package q;

import V4.C0763h0;
import V4.InterfaceC0765i0;
import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicReference;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
public final class U extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public e5.a f23236a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object f23237b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public V f23238c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f23239d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public /* synthetic */ Object f23240e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ V f23241f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ C4.j f23242j;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public U(V v3, J4.c cVar, A4.d dVar) {
        super(2, dVar);
        Q q6 = Q.f23224a;
        this.f23241f = v3;
        this.f23242j = (C4.j) cVar;
    }

    /* JADX WARN: Type inference failed for: r1v0, types: [C4.j, J4.c] */
    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        ?? r12 = this.f23242j;
        Q q6 = Q.f23224a;
        U u6 = new U(this.f23241f, r12, dVar);
        u6.f23240e = obj;
        return u6;
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((U) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v0, types: [int] */
    /* JADX WARN: Type inference failed for: r3v10 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v3, types: [J4.c] */
    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        V v3;
        ?? r32;
        T t6;
        e5.a aVar;
        e5.a aVar2;
        V v6;
        Throwable th;
        T t7;
        AtomicReference atomicReference;
        e5.a aVar3;
        AtomicReference atomicReference2;
        B4.a aVar4 = B4.a.f492a;
        ?? r12 = this.f23239d;
        try {
            try {
                if (r12 == 0) {
                    AbstractC2467b.l(obj);
                    A4.h hVar = ((V4.C) this.f23240e).getCoroutineContext().get(C0763h0.f8306a);
                    kotlin.jvm.internal.o.e(hVar);
                    Q q6 = Q.f23224a;
                    T t8 = new T((InterfaceC0765i0) hVar);
                    while (true) {
                        v3 = this.f23241f;
                        AtomicReference atomicReference3 = v3.f23244a;
                        T t9 = (T) atomicReference3.get();
                        if (t9 != null) {
                            Q q7 = Q.f23224a;
                            if (q7.compareTo(q7) < 0) {
                                throw new CancellationException("Current mutation had a higher priority");
                            }
                        }
                        while (!atomicReference3.compareAndSet(t9, t8)) {
                            if (atomicReference3.get() != t9) {
                                break;
                            }
                        }
                        if (t9 != null) {
                            t9.f23232a.cancel(new S("Mutation interrupted"));
                        }
                        this.f23240e = t8;
                        e5.c cVar = v3.f23245b;
                        this.f23236a = cVar;
                        C4.j jVar = this.f23242j;
                        this.f23237b = jVar;
                        this.f23238c = v3;
                        this.f23239d = 1;
                        if (cVar.e(this) != aVar4) {
                            r32 = jVar;
                            t6 = t8;
                            aVar = cVar;
                        }
                    }
                    return aVar4;
                }
                if (r12 != 1) {
                    if (r12 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    v6 = (V) this.f23237b;
                    e5.a aVar5 = this.f23236a;
                    t7 = (T) this.f23240e;
                    try {
                        AbstractC2467b.l(obj);
                        aVar3 = aVar5;
                        atomicReference2 = v6.f23244a;
                        while (!atomicReference2.compareAndSet(t7, null) && atomicReference2.get() == t7) {
                        }
                        ((e5.c) aVar3).g(null);
                        return obj;
                    } catch (Throwable th2) {
                        th = th2;
                        atomicReference = v6.f23244a;
                        while (!atomicReference.compareAndSet(t7, null)) {
                        }
                        throw th;
                    }
                }
                V v7 = this.f23238c;
                J4.c cVar2 = (J4.c) this.f23237b;
                e5.a aVar6 = this.f23236a;
                t6 = (T) this.f23240e;
                AbstractC2467b.l(obj);
                v3 = v7;
                r32 = cVar2;
                aVar = aVar6;
                this.f23240e = t6;
                this.f23236a = aVar2;
                this.f23237b = v3;
                this.f23238c = null;
                this.f23239d = 2;
                Object objInvoke = r32.invoke(this);
                if (objInvoke != aVar4) {
                    v6 = v3;
                    obj = objInvoke;
                    t7 = t6;
                    aVar3 = aVar2;
                    atomicReference2 = v6.f23244a;
                    while (!atomicReference2.compareAndSet(t7, null)) {
                    }
                    ((e5.c) aVar3).g(null);
                    return obj;
                }
                return aVar4;
            } catch (Throwable th3) {
                v6 = v3;
                th = th3;
                t7 = t6;
                atomicReference = v6.f23244a;
                while (!atomicReference.compareAndSet(t7, null) && atomicReference.get() == t7) {
                }
                throw th;
            }
            aVar2 = aVar;
        } catch (Throwable th4) {
            ((e5.c) r12).g(null);
            throw th4;
        }
    }
}
