package Z6;

import com.google.android.gms.internal.measurement.C1;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: loaded from: classes.dex */
public class k0 implements d0, q0 {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f7529q = AtomicReferenceFieldUpdater.newUpdater(k0.class, Object.class, "_state$volatile");

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f7530r = AtomicReferenceFieldUpdater.newUpdater(k0.class, Object.class, "_parentHandle$volatile");
    private volatile /* synthetic */ Object _parentHandle$volatile;
    private volatile /* synthetic */ Object _state$volatile;

    public k0(boolean z8) {
        this._state$volatile = z8 ? AbstractC0385z.f7572j : AbstractC0385z.i;
    }

    public static C0373m U(e7.j jVar) {
        while (jVar.i()) {
            e7.j jVarF = jVar.f();
            if (jVarF == null) {
                AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = e7.j.f12559r;
                Object obj = atomicReferenceFieldUpdater.get(jVar);
                while (true) {
                    jVar = (e7.j) obj;
                    if (!jVar.i()) {
                        break;
                    }
                    obj = atomicReferenceFieldUpdater.get(jVar);
                }
            } else {
                jVar = jVarF;
            }
        }
        while (true) {
            jVar = jVar.h();
            if (!jVar.i()) {
                if (jVar instanceof C0373m) {
                    return (C0373m) jVar;
                }
                if (jVar instanceof m0) {
                    return null;
                }
            }
        }
    }

    public static String c0(Object obj) {
        if (!(obj instanceof j0)) {
            return obj instanceof Z ? ((Z) obj).a() ? "Active" : "New" : obj instanceof C0377q ? "Cancelled" : "Completed";
        }
        j0 j0Var = (j0) obj;
        return j0Var.e() ? "Cancelling" : j0.f7523r.get(j0Var) == 1 ? "Completing" : "Active";
    }

    @Override // E6.i
    public final E6.i A(E6.i iVar) {
        return s7.l.x(this, iVar);
    }

    public final Throwable B(Object obj) {
        Throwable thC;
        if (obj instanceof Throwable) {
            return (Throwable) obj;
        }
        k0 k0Var = (k0) ((q0) obj);
        Object obj2 = f7529q.get(k0Var);
        if (obj2 instanceof j0) {
            thC = ((j0) obj2).c();
        } else if (obj2 instanceof C0377q) {
            thC = ((C0377q) obj2).f7541a;
        } else {
            if (obj2 instanceof Z) {
                throw new IllegalStateException(("Cannot be cancelling child in this state: " + obj2).toString());
            }
            thC = null;
        }
        CancellationException cancellationException = thC instanceof CancellationException ? (CancellationException) thC : null;
        return cancellationException == null ? new e0("Parent job is ".concat(c0(obj2)), thC, k0Var) : cancellationException;
    }

    public final Object C(j0 j0Var, Object obj) throws IllegalAccessException, InvocationTargetException {
        Throwable thE;
        C0377q c0377q = obj instanceof C0377q ? (C0377q) obj : null;
        Throwable th = c0377q != null ? c0377q.f7541a : null;
        synchronized (j0Var) {
            j0Var.e();
            ArrayList arrayListF = j0Var.f(th);
            thE = E(j0Var, arrayListF);
            if (thE != null && arrayListF.size() > 1) {
                Set setNewSetFromMap = Collections.newSetFromMap(new IdentityHashMap(arrayListF.size()));
                int size = arrayListF.size();
                int i = 0;
                while (i < size) {
                    Object obj2 = arrayListF.get(i);
                    i++;
                    Throwable th2 = (Throwable) obj2;
                    if (th2 != thE && th2 != thE && !(th2 instanceof CancellationException) && setNewSetFromMap.add(th2)) {
                        android.support.v4.media.session.a.a(thE, th2);
                    }
                }
            }
        }
        if (thE != null && thE != th) {
            obj = new C0377q(thE, false);
        }
        if (thE != null && (w(thE) || I(thE))) {
            P6.g.c(obj, "null cannot be cast to non-null type kotlinx.coroutines.CompletedExceptionally");
            C0377q.f7540b.compareAndSet((C0377q) obj, 0, 1);
        }
        X(obj);
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f7529q;
        Object c0360a0 = obj instanceof Z ? new C0360a0((Z) obj) : obj;
        while (!atomicReferenceFieldUpdater.compareAndSet(this, j0Var, c0360a0) && atomicReferenceFieldUpdater.get(this) == j0Var) {
        }
        z(j0Var, obj);
        return obj;
    }

    public final Object D() throws Throwable {
        Object obj = f7529q.get(this);
        if (obj instanceof Z) {
            throw new IllegalStateException("This job has not completed yet");
        }
        if (obj instanceof C0377q) {
            throw ((C0377q) obj).f7541a;
        }
        return AbstractC0385z.A(obj);
    }

    public final Throwable E(j0 j0Var, ArrayList arrayList) {
        Object obj;
        Object obj2 = null;
        if (arrayList.isEmpty()) {
            if (j0Var.e()) {
                return new e0(x(), null, this);
            }
            return null;
        }
        int size = arrayList.size();
        int i = 0;
        int i5 = 0;
        while (true) {
            if (i5 >= size) {
                obj = null;
                break;
            }
            obj = arrayList.get(i5);
            i5++;
            if (!(((Throwable) obj) instanceof CancellationException)) {
                break;
            }
        }
        Throwable th = (Throwable) obj;
        if (th != null) {
            return th;
        }
        Throwable th2 = (Throwable) arrayList.get(0);
        if (th2 instanceof v0) {
            int size2 = arrayList.size();
            while (true) {
                if (i >= size2) {
                    break;
                }
                Object obj3 = arrayList.get(i);
                i++;
                Throwable th3 = (Throwable) obj3;
                if (th3 != th2 && (th3 instanceof v0)) {
                    obj2 = obj3;
                    break;
                }
            }
            Throwable th4 = (Throwable) obj2;
            if (th4 != null) {
                return th4;
            }
        }
        return th2;
    }

    public boolean F() {
        return true;
    }

    public boolean G() {
        return this instanceof C0375o;
    }

    public final m0 H(Z z8) {
        m0 m0VarD = z8.d();
        if (m0VarD != null) {
            return m0VarD;
        }
        if (z8 instanceof N) {
            return new m0();
        }
        if (z8 instanceof g0) {
            a0((g0) z8);
            return null;
        }
        throw new IllegalStateException(("State should have list: " + z8).toString());
    }

    public boolean I(Throwable th) {
        return false;
    }

    @Override // E6.i
    public final E6.g K(E6.h hVar) {
        return s7.l.m(this, hVar);
    }

    public final void L(d0 d0Var) {
        o0 o0Var = o0.f7534q;
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f7530r;
        if (d0Var == null) {
            atomicReferenceFieldUpdater.set(this, o0Var);
            return;
        }
        d0Var.start();
        InterfaceC0372l interfaceC0372lG = d0Var.g(this);
        atomicReferenceFieldUpdater.set(this, interfaceC0372lG);
        if (N()) {
            interfaceC0372lG.b();
            atomicReferenceFieldUpdater.set(this, o0Var);
        }
    }

    public final L M(boolean z8, g0 g0Var) {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
        o0 o0Var;
        boolean z9;
        boolean zE;
        g0Var.f7509t = this;
        loop0: while (true) {
            atomicReferenceFieldUpdater = f7529q;
            Object obj = atomicReferenceFieldUpdater.get(this);
            boolean z10 = obj instanceof N;
            o0Var = o0.f7534q;
            z9 = true;
            if (!z10) {
                if (!(obj instanceof Z)) {
                    z9 = false;
                    break;
                }
                Z z11 = (Z) obj;
                m0 m0VarD = z11.d();
                if (m0VarD == null) {
                    P6.g.c(obj, "null cannot be cast to non-null type kotlinx.coroutines.JobNode");
                    a0((g0) obj);
                } else {
                    if (g0Var.k()) {
                        j0 j0Var = z11 instanceof j0 ? (j0) z11 : null;
                        Throwable thC = j0Var != null ? j0Var.c() : null;
                        if (thC == null) {
                            zE = m0VarD.e(g0Var, 5);
                        } else if (z8) {
                            g0Var.l(thC);
                            return o0Var;
                        }
                    } else {
                        zE = m0VarD.e(g0Var, 1);
                    }
                    if (zE) {
                        break;
                    }
                }
            } else {
                N n8 = (N) obj;
                if (n8.f7478q) {
                    while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, g0Var)) {
                        if (atomicReferenceFieldUpdater.get(this) != obj) {
                            break;
                        }
                    }
                    break loop0;
                }
                Z(n8);
            }
        }
        if (z9) {
            return g0Var;
        }
        if (z8) {
            Object obj2 = atomicReferenceFieldUpdater.get(this);
            C0377q c0377q = obj2 instanceof C0377q ? (C0377q) obj2 : null;
            g0Var.l(c0377q != null ? c0377q.f7541a : null);
        }
        return o0Var;
    }

    public final boolean N() {
        return !(f7529q.get(this) instanceof Z);
    }

    @Override // E6.i
    public final Object O(Object obj, O6.p pVar) {
        return pVar.k(obj, this);
    }

    public boolean P() {
        return this instanceof C0363c;
    }

    @Override // Z6.d0
    public final L Q(O6.l lVar) {
        return M(true, new M(1, lVar));
    }

    public final boolean R(Object obj) throws IllegalAccessException, InvocationTargetException {
        Object objD0;
        do {
            objD0 = d0(f7529q.get(this), obj);
            if (objD0 == AbstractC0385z.f7567d) {
                return false;
            }
            if (objD0 == AbstractC0385z.f7568e) {
                return true;
            }
        } while (objD0 == AbstractC0385z.f7569f);
        p(objD0);
        return true;
    }

    public final Object S(Object obj) throws IllegalAccessException, InvocationTargetException {
        Object objD0;
        do {
            objD0 = d0(f7529q.get(this), obj);
            if (objD0 == AbstractC0385z.f7567d) {
                String str = "Job " + this + " is already complete or completing, but is being completed with " + obj;
                C0377q c0377q = obj instanceof C0377q ? (C0377q) obj : null;
                throw new IllegalStateException(str, c0377q != null ? c0377q.f7541a : null);
            }
        } while (objD0 == AbstractC0385z.f7569f);
        return objD0;
    }

    public String T() {
        return getClass().getSimpleName();
    }

    @Override // Z6.d0
    public final L V(boolean z8, boolean z9, F5.n nVar) {
        return M(z9, z8 ? new c0(nVar) : new M(1, nVar));
    }

    public final void W(m0 m0Var, Throwable th) throws IllegalAccessException, InvocationTargetException {
        m0Var.e(new e7.h(4), 4);
        Object obj = e7.j.f12558q.get(m0Var);
        P6.g.c(obj, "null cannot be cast to non-null type kotlinx.coroutines.internal.LockFreeLinkedListNode");
        A6.b bVar = null;
        for (e7.j jVarH = (e7.j) obj; !jVarH.equals(m0Var); jVarH = jVarH.h()) {
            if ((jVarH instanceof g0) && ((g0) jVarH).k()) {
                try {
                    ((g0) jVarH).l(th);
                } catch (Throwable th2) {
                    if (bVar != null) {
                        android.support.v4.media.session.a.a(bVar, th2);
                    } else {
                        bVar = new A6.b("Exception in completion handler " + jVarH + " for " + this, th2);
                    }
                }
            }
        }
        if (bVar != null) {
            J(bVar);
        }
        w(th);
    }

    public final void Z(N n8) {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
        m0 m0Var = new m0();
        Object y8 = m0Var;
        if (!n8.f7478q) {
            y8 = new Y(m0Var);
        }
        do {
            atomicReferenceFieldUpdater = f7529q;
            if (atomicReferenceFieldUpdater.compareAndSet(this, n8, y8)) {
                return;
            }
        } while (atomicReferenceFieldUpdater.get(this) == n8);
    }

    @Override // Z6.d0
    public boolean a() {
        Object obj = f7529q.get(this);
        return (obj instanceof Z) && ((Z) obj).a();
    }

    public final void a0(g0 g0Var) {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
        m0 m0Var = new m0();
        g0Var.getClass();
        e7.j.f12559r.set(m0Var, g0Var);
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater2 = e7.j.f12558q;
        atomicReferenceFieldUpdater2.set(m0Var, g0Var);
        loop0: while (true) {
            if (atomicReferenceFieldUpdater2.get(g0Var) == g0Var) {
                while (!atomicReferenceFieldUpdater2.compareAndSet(g0Var, g0Var, m0Var)) {
                    if (atomicReferenceFieldUpdater2.get(g0Var) != g0Var) {
                        break;
                    }
                }
                m0Var.g(g0Var);
                break loop0;
            }
            break;
        }
        e7.j jVarH = g0Var.h();
        do {
            atomicReferenceFieldUpdater = f7529q;
            if (atomicReferenceFieldUpdater.compareAndSet(this, g0Var, jVarH)) {
                return;
            }
        } while (atomicReferenceFieldUpdater.get(this) == g0Var);
    }

    @Override // Z6.d0
    public void b(CancellationException cancellationException) throws IllegalAccessException, InvocationTargetException {
        if (cancellationException == null) {
            cancellationException = new e0(x(), null, this);
        }
        v(cancellationException);
    }

    public final int b0(Object obj) {
        boolean z8 = obj instanceof N;
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f7529q;
        if (z8) {
            if (((N) obj).f7478q) {
                return 0;
            }
            N n8 = AbstractC0385z.f7572j;
            while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, n8)) {
                if (atomicReferenceFieldUpdater.get(this) != obj) {
                    return -1;
                }
            }
            Y();
            return 1;
        }
        if (!(obj instanceof Y)) {
            return 0;
        }
        m0 m0Var = ((Y) obj).f7494q;
        while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, m0Var)) {
            if (atomicReferenceFieldUpdater.get(this) != obj) {
                return -1;
            }
        }
        Y();
        return 1;
    }

    public final Object d0(Object obj, Object obj2) throws IllegalAccessException, InvocationTargetException {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
        if (!(obj instanceof Z)) {
            return AbstractC0385z.f7567d;
        }
        if (((obj instanceof N) || (obj instanceof g0)) && !(obj instanceof C0373m) && !(obj2 instanceof C0377q)) {
            Z z8 = (Z) obj;
            Object c0360a0 = obj2 instanceof Z ? new C0360a0((Z) obj2) : obj2;
            do {
                atomicReferenceFieldUpdater = f7529q;
                if (atomicReferenceFieldUpdater.compareAndSet(this, z8, c0360a0)) {
                    X(obj2);
                    z(z8, obj2);
                    return obj2;
                }
            } while (atomicReferenceFieldUpdater.get(this) == z8);
            return AbstractC0385z.f7569f;
        }
        Z z9 = (Z) obj;
        m0 m0VarH = H(z9);
        if (m0VarH == null) {
            return AbstractC0385z.f7569f;
        }
        j0 j0Var = z9 instanceof j0 ? (j0) z9 : null;
        if (j0Var == null) {
            j0Var = new j0(m0VarH, null);
        }
        synchronized (j0Var) {
            try {
                AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = j0.f7523r;
                if (atomicIntegerFieldUpdater.get(j0Var) == 1) {
                    return AbstractC0385z.f7567d;
                }
                atomicIntegerFieldUpdater.set(j0Var, 1);
                if (j0Var != z9) {
                    AtomicReferenceFieldUpdater atomicReferenceFieldUpdater2 = f7529q;
                    while (!atomicReferenceFieldUpdater2.compareAndSet(this, z9, j0Var)) {
                        if (atomicReferenceFieldUpdater2.get(this) != z9) {
                            return AbstractC0385z.f7569f;
                        }
                    }
                }
                boolean zE = j0Var.e();
                C0377q c0377q = obj2 instanceof C0377q ? (C0377q) obj2 : null;
                if (c0377q != null) {
                    j0Var.b(c0377q.f7541a);
                }
                Throwable thC = zE ? null : j0Var.c();
                if (thC != null) {
                    W(m0VarH, thC);
                }
                C0373m c0373mU = U(m0VarH);
                if (c0373mU != null && e0(j0Var, c0373mU, obj2)) {
                    return AbstractC0385z.f7568e;
                }
                m0VarH.e(new e7.h(2), 2);
                C0373m c0373mU2 = U(m0VarH);
                return (c0373mU2 == null || !e0(j0Var, c0373mU2, obj2)) ? C(j0Var, obj2) : AbstractC0385z.f7568e;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final boolean e0(j0 j0Var, C0373m c0373m, Object obj) {
        while (AbstractC0385z.q(c0373m.f7532u, false, new i0(this, j0Var, c0373m, obj)) == o0.f7534q) {
            c0373m = U(c0373m);
            if (c0373m == null) {
                return false;
            }
        }
        return true;
    }

    @Override // Z6.d0
    public final InterfaceC0372l g(k0 k0Var) {
        C0373m c0373m = new C0373m(k0Var);
        c0373m.f7509t = this;
        loop0: while (true) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f7529q;
            Object obj = atomicReferenceFieldUpdater.get(this);
            if (obj instanceof N) {
                N n8 = (N) obj;
                if (n8.f7478q) {
                    while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, c0373m)) {
                        if (atomicReferenceFieldUpdater.get(this) != obj) {
                            break;
                        }
                    }
                    break loop0;
                }
                Z(n8);
            } else {
                boolean z8 = obj instanceof Z;
                o0 o0Var = o0.f7534q;
                if (!z8) {
                    Object obj2 = atomicReferenceFieldUpdater.get(this);
                    C0377q c0377q = obj2 instanceof C0377q ? (C0377q) obj2 : null;
                    c0373m.l(c0377q != null ? c0377q.f7541a : null);
                    return o0Var;
                }
                m0 m0VarD = ((Z) obj).d();
                if (m0VarD == null) {
                    P6.g.c(obj, "null cannot be cast to non-null type kotlinx.coroutines.JobNode");
                    a0((g0) obj);
                } else if (!m0VarD.e(c0373m, 7)) {
                    boolean zE = m0VarD.e(c0373m, 3);
                    Object obj3 = atomicReferenceFieldUpdater.get(this);
                    if (obj3 instanceof j0) {
                        thC = ((j0) obj3).c();
                    } else {
                        C0377q c0377q2 = obj3 instanceof C0377q ? (C0377q) obj3 : null;
                        if (c0377q2 != null) {
                            thC = c0377q2.f7541a;
                        }
                    }
                    c0373m.l(thC);
                    if (zE) {
                        break loop0;
                    }
                    return o0Var;
                }
            }
        }
        return c0373m;
    }

    @Override // E6.g
    public final E6.h getKey() {
        return C0379t.f7546r;
    }

    @Override // Z6.d0
    public final boolean isCancelled() {
        Object obj = f7529q.get(this);
        if (obj instanceof C0377q) {
            return true;
        }
        return (obj instanceof j0) && ((j0) obj).e();
    }

    public Object j(G6.i iVar) {
        return s(iVar);
    }

    @Override // Z6.d0
    public final Object m(d7.l lVar) {
        Object obj;
        A6.n nVar;
        do {
            obj = f7529q.get(this);
            boolean z8 = obj instanceof Z;
            nVar = A6.n.f457a;
            if (!z8) {
                E6.i iVar = lVar.f3016r;
                P6.g.b(iVar);
                AbstractC0385z.i(iVar);
                return nVar;
            }
        } while (b0(obj) < 0);
        C0369i c0369i = new C0369i(1, C1.A(lVar));
        c0369i.v();
        c0369i.y(new C0365e(2, AbstractC0385z.q(this, true, new C0371k(c0369i, 1))));
        Object objU = c0369i.u();
        F6.a aVar = F6.a.f2580q;
        if (objU != aVar) {
            objU = nVar;
        }
        return objU == aVar ? objU : nVar;
    }

    @Override // E6.i
    public final E6.i n(E6.h hVar) {
        return s7.l.s(this, hVar);
    }

    public void q(Object obj) {
        p(obj);
    }

    @Override // Z6.d0
    public final CancellationException r() {
        CancellationException e0Var;
        Object obj = f7529q.get(this);
        if (!(obj instanceof j0)) {
            if (obj instanceof Z) {
                throw new IllegalStateException(("Job is still new or active: " + this).toString());
            }
            if (!(obj instanceof C0377q)) {
                return new e0(getClass().getSimpleName().concat(" has completed normally"), null, this);
            }
            Throwable th = ((C0377q) obj).f7541a;
            e0Var = th instanceof CancellationException ? (CancellationException) th : null;
            return e0Var == null ? new e0(x(), th, this) : e0Var;
        }
        Throwable thC = ((j0) obj).c();
        if (thC == null) {
            throw new IllegalStateException(("Job is still new or active: " + this).toString());
        }
        String strConcat = getClass().getSimpleName().concat(" is cancelling");
        e0Var = thC instanceof CancellationException ? (CancellationException) thC : null;
        if (e0Var == null) {
            if (strConcat == null) {
                strConcat = x();
            }
            e0Var = new e0(strConcat, thC, this);
        }
        return e0Var;
    }

    public final Object s(G6.i iVar) throws Throwable {
        Object obj;
        do {
            obj = f7529q.get(this);
            if (!(obj instanceof Z)) {
                if (obj instanceof C0377q) {
                    throw ((C0377q) obj).f7541a;
                }
                return AbstractC0385z.A(obj);
            }
        } while (b0(obj) < 0);
        h0 h0Var = new h0(C1.A(iVar), this);
        h0Var.v();
        h0Var.y(new C0365e(2, AbstractC0385z.q(this, true, new M(2, h0Var))));
        return h0Var.u();
    }

    @Override // Z6.d0
    public final boolean start() {
        int iB0;
        do {
            iB0 = b0(f7529q.get(this));
            if (iB0 == 0) {
                return false;
            }
        } while (iB0 != 1);
        return true;
    }

    /* JADX WARN: Code restructure failed: missing block: B:31:0x006a, code lost:
    
        r0 = r10;
     */
    /* JADX WARN: Removed duplicated region for block: B:18:0x0041 A[PHI: r0
      0x0041: PHI (r0v1 java.lang.Object) = (r0v0 java.lang.Object), (r0v13 java.lang.Object) binds: [B:3:0x0008, B:16:0x003d] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean t(Object obj) throws IllegalAccessException, InvocationTargetException {
        B3.f fVar;
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
        Object objD0 = AbstractC0385z.f7567d;
        if (G()) {
            do {
                Object obj2 = f7529q.get(this);
                if (obj2 instanceof Z) {
                    if (obj2 instanceof j0) {
                        j0 j0Var = (j0) obj2;
                        j0Var.getClass();
                        if (j0.f7523r.get(j0Var) == 1) {
                        }
                    }
                    objD0 = d0(obj2, new C0377q(B(obj), false));
                }
                objD0 = AbstractC0385z.f7567d;
                break;
            } while (objD0 == AbstractC0385z.f7569f);
            if (objD0 != AbstractC0385z.f7568e) {
                if (objD0 == AbstractC0385z.f7567d) {
                    Throwable thB = null;
                    loop1: while (true) {
                        Object obj3 = f7529q.get(this);
                        if (!(obj3 instanceof j0)) {
                            if (!(obj3 instanceof Z)) {
                                fVar = AbstractC0385z.f7570g;
                                break;
                            }
                            if (thB == null) {
                                thB = B(obj);
                            }
                            Z z8 = (Z) obj3;
                            if (z8.a()) {
                                m0 m0VarH = H(z8);
                                if (m0VarH == null) {
                                    continue;
                                } else {
                                    j0 j0Var2 = new j0(m0VarH, thB);
                                    do {
                                        atomicReferenceFieldUpdater = f7529q;
                                        if (atomicReferenceFieldUpdater.compareAndSet(this, z8, j0Var2)) {
                                            W(m0VarH, thB);
                                            fVar = AbstractC0385z.f7567d;
                                            break loop1;
                                        }
                                    } while (atomicReferenceFieldUpdater.get(this) == z8);
                                }
                            } else {
                                Object objD02 = d0(obj3, new C0377q(thB, false));
                                if (objD02 == AbstractC0385z.f7567d) {
                                    throw new IllegalStateException(("Cannot happen in " + obj3).toString());
                                }
                                if (objD02 != AbstractC0385z.f7569f) {
                                    objD0 = objD02;
                                    break;
                                }
                            }
                        } else {
                            synchronized (obj3) {
                                try {
                                    j0 j0Var3 = (j0) obj3;
                                    j0Var3.getClass();
                                    if (j0.f7525t.get(j0Var3) == AbstractC0385z.f7571h) {
                                        fVar = AbstractC0385z.f7570g;
                                    } else {
                                        boolean zE = ((j0) obj3).e();
                                        if (thB == null) {
                                            thB = B(obj);
                                        }
                                        ((j0) obj3).b(thB);
                                        Throwable thC = zE ? null : ((j0) obj3).c();
                                        if (thC != null) {
                                            W(((j0) obj3).f7526q, thC);
                                        }
                                        fVar = AbstractC0385z.f7567d;
                                    }
                                } catch (Throwable th) {
                                    throw th;
                                }
                            }
                        }
                    }
                }
                if (objD0 != AbstractC0385z.f7567d && objD0 != AbstractC0385z.f7568e) {
                    if (objD0 == AbstractC0385z.f7570g) {
                        return false;
                    }
                    p(objD0);
                    return true;
                }
            }
        }
        return true;
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(T() + '{' + c0(f7529q.get(this)) + '}');
        sb.append('@');
        sb.append(AbstractC0385z.m(this));
        return sb.toString();
    }

    public void v(CancellationException cancellationException) throws IllegalAccessException, InvocationTargetException {
        t(cancellationException);
    }

    public final boolean w(Throwable th) {
        if (P()) {
            return true;
        }
        boolean z8 = th instanceof CancellationException;
        InterfaceC0372l interfaceC0372l = (InterfaceC0372l) f7530r.get(this);
        return (interfaceC0372l == null || interfaceC0372l == o0.f7534q) ? z8 : interfaceC0372l.c(th) || z8;
    }

    public String x() {
        return "Job was cancelled";
    }

    public boolean y(Throwable th) {
        if (th instanceof CancellationException) {
            return true;
        }
        return t(th) && F();
    }

    public final void z(Z z8, Object obj) throws IllegalAccessException, InvocationTargetException {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f7530r;
        InterfaceC0372l interfaceC0372l = (InterfaceC0372l) atomicReferenceFieldUpdater.get(this);
        if (interfaceC0372l != null) {
            interfaceC0372l.b();
            atomicReferenceFieldUpdater.set(this, o0.f7534q);
        }
        A6.b bVar = null;
        C0377q c0377q = obj instanceof C0377q ? (C0377q) obj : null;
        Throwable th = c0377q != null ? c0377q.f7541a : null;
        if (z8 instanceof g0) {
            try {
                ((g0) z8).l(th);
                return;
            } catch (Throwable th2) {
                J(new A6.b("Exception in completion handler " + z8 + " for " + this, th2));
                return;
            }
        }
        m0 m0VarD = z8.d();
        if (m0VarD != null) {
            m0VarD.e(new e7.h(1), 1);
            Object obj2 = e7.j.f12558q.get(m0VarD);
            P6.g.c(obj2, "null cannot be cast to non-null type kotlinx.coroutines.internal.LockFreeLinkedListNode");
            for (e7.j jVarH = (e7.j) obj2; !jVarH.equals(m0VarD); jVarH = jVarH.h()) {
                if (jVarH instanceof g0) {
                    try {
                        ((g0) jVarH).l(th);
                    } catch (Throwable th3) {
                        if (bVar != null) {
                            android.support.v4.media.session.a.a(bVar, th3);
                        } else {
                            bVar = new A6.b("Exception in completion handler " + jVarH + " for " + this, th3);
                        }
                    }
                }
            }
            if (bVar != null) {
                J(bVar);
            }
        }
    }

    public void Y() {
    }

    public void J(A6.b bVar) {
        throw bVar;
    }

    public void X(Object obj) {
    }

    public void p(Object obj) {
    }
}
