package vm;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import rm.x;

@Metadata(d1 = {"\u00002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\f\b\u0001\u0018\u0000 \u001c*\u0006\b\u0000\u0010\u0001 \u00002\b\u0012\u0004\u0012\u00028\u00000\u00022\u00020\u0003:\u0001\nB!\b\u0000\u0012\f\u0010\u000f\u001a\b\u0012\u0004\u0012\u00028\u00000\u0002\u0012\b\u0010\u0018\u001a\u0004\u0018\u00010\t¢\u0006\u0004\b\u0019\u0010\u001aB\u0017\b\u0011\u0012\f\u0010\u000f\u001a\b\u0012\u0004\u0012\u00028\u00000\u0002¢\u0006\u0004\b\u0019\u0010\u001bJ\u001d\u0010\u0007\u001a\u00020\u00062\f\u0010\u0005\u001a\b\u0012\u0004\u0012\u00028\u00000\u0004H\u0016¢\u0006\u0004\b\u0007\u0010\bJ\n\u0010\n\u001a\u0004\u0018\u00010\tH\u0001J\b\u0010\f\u001a\u00020\u000bH\u0016R\u001a\u0010\u000f\u001a\b\u0012\u0004\u0012\u00028\u00000\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\r\u0010\u000eR\u0018\u0010\u0005\u001a\u0004\u0018\u00010\t8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0005\u0010\u0010R\u0014\u0010\u0014\u001a\u00020\u00118VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0012\u0010\u0013R\u0016\u0010\u0017\u001a\u0004\u0018\u00010\u00038VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0015\u0010\u0016¨\u0006\u001d"}, d2 = {"Lvm/i;", "T", "Lvm/d;", "Lkotlin/coroutines/jvm/internal/e;", "Lrm/x;", "result", "Lrm/n0;", "resumeWith", "(Ljava/lang/Object;)V", "", "a", "", "toString", "p", "Lvm/d;", "delegate", "Ljava/lang/Object;", "Lvm/g;", "getContext", "()Lvm/g;", "context", "getCallerFrame", "()Lkotlin/coroutines/jvm/internal/e;", "callerFrame", "initialResult", "<init>", "(Lvm/d;Ljava/lang/Object;)V", "(Lvm/d;)V", "q", "kotlin-stdlib"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes3.dex */
public final class i<T> implements d<T>, kotlin.coroutines.jvm.internal.e {

    /* renamed from: q, reason: collision with root package name */
    private static final a f40194q = new a(null);

    /* renamed from: r, reason: collision with root package name */
    private static final AtomicReferenceFieldUpdater<i<?>, Object> f40195r = AtomicReferenceFieldUpdater.newUpdater(i.class, Object.class, "result");

    /* renamed from: p, reason: collision with root package name and from kotlin metadata */
    private final d<T> delegate;
    private volatile Object result;

    @Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\b\u0082\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\t\u0010\bRj\u0010\u0005\u001aR\u0012\u0014\u0012\u0012\u0012\u0002\b\u0003 \u0004*\b\u0012\u0002\b\u0003\u0018\u00010\u00030\u0003\u0012\f\u0012\n \u0004*\u0004\u0018\u00010\u00010\u0001 \u0004*(\u0012\u0014\u0012\u0012\u0012\u0002\b\u0003 \u0004*\b\u0012\u0002\b\u0003\u0018\u00010\u00030\u0003\u0012\f\u0012\n \u0004*\u0004\u0018\u00010\u00010\u0001\u0018\u00010\u00020\u00028\u0002X\u0082\u0004¢\u0006\f\n\u0004\b\u0005\u0010\u0006\u0012\u0004\b\u0007\u0010\b¨\u0006\n"}, d2 = {"Lvm/i$a;", "", "Ljava/util/concurrent/atomic/AtomicReferenceFieldUpdater;", "Lvm/i;", "kotlin.jvm.PlatformType", "RESULT", "Ljava/util/concurrent/atomic/AtomicReferenceFieldUpdater;", "getRESULT$annotations", "()V", "<init>", "kotlin-stdlib"}, k = 1, mv = {1, 9, 0})
    /* loaded from: classes3.dex */
    private static final class a {
        private a() {
        }

        public /* synthetic */ a(k kVar) {
            this();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public i(d<? super T> delegate, Object obj) {
        t.g(delegate, "delegate");
        this.delegate = delegate;
        this.result = obj;
    }

    public final Object a() {
        Object f10;
        Object f11;
        Object f12;
        Object obj = this.result;
        wm.a aVar = wm.a.UNDECIDED;
        if (obj == aVar) {
            AtomicReferenceFieldUpdater<i<?>, Object> atomicReferenceFieldUpdater = f40195r;
            f11 = wm.d.f();
            if (androidx.concurrent.futures.b.a(atomicReferenceFieldUpdater, this, aVar, f11)) {
                f12 = wm.d.f();
                return f12;
            }
            obj = this.result;
        }
        if (obj == wm.a.RESUMED) {
            f10 = wm.d.f();
            return f10;
        }
        if (obj instanceof x.b) {
            throw ((x.b) obj).f34911p;
        }
        return obj;
    }

    @Override // kotlin.coroutines.jvm.internal.e
    public kotlin.coroutines.jvm.internal.e getCallerFrame() {
        d<T> dVar = this.delegate;
        if (dVar instanceof kotlin.coroutines.jvm.internal.e) {
            return (kotlin.coroutines.jvm.internal.e) dVar;
        }
        return null;
    }

    @Override // vm.d
    public g getContext() {
        return this.delegate.getContext();
    }

    @Override // vm.d
    public void resumeWith(Object result) {
        Object f10;
        Object f11;
        while (true) {
            Object obj = this.result;
            wm.a aVar = wm.a.UNDECIDED;
            if (obj != aVar) {
                f10 = wm.d.f();
                if (obj != f10) {
                    throw new IllegalStateException("Already resumed");
                }
                AtomicReferenceFieldUpdater<i<?>, Object> atomicReferenceFieldUpdater = f40195r;
                f11 = wm.d.f();
                if (androidx.concurrent.futures.b.a(atomicReferenceFieldUpdater, this, f11, wm.a.RESUMED)) {
                    this.delegate.resumeWith(result);
                    return;
                }
            } else if (androidx.concurrent.futures.b.a(f40195r, this, aVar, result)) {
                return;
            }
        }
    }

    public String toString() {
        return "SafeContinuation for " + this.delegate;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public i(d<? super T> delegate) {
        this(delegate, wm.a.UNDECIDED);
        t.g(delegate, "delegate");
    }
}
