package p025.p026;

import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.TypeCastException;
import kotlinx.coroutines.CompletionHandlerException;
import kotlinx.coroutines.JobCancellationException;
import kotlinx.coroutines.TimeoutCancellationException;
import p025.p026.p027.AbstractC1292;
import p025.p026.p027.C1283;
import p025.p026.p027.C1284;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.C6549;
import p402.InterfaceC6540;
import p402.p405.InterfaceC6575;
import p402.p405.InterfaceC6578;
import p402.p411.p412.InterfaceC6614;
import p402.p411.p412.InterfaceC6618;
import p402.p411.p413.C6635;

/* JADX INFO: renamed from: އ.֏.ൎ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public class C1368 implements InterfaceC1363, InterfaceC1313, InterfaceC1380 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final AtomicReferenceFieldUpdater f4518 = AtomicReferenceFieldUpdater.newUpdater(C1368.class, Object.class, "_state");
    public volatile Object _parentHandle;
    public volatile Object _state;

    /* JADX INFO: renamed from: އ.֏.ൎ$֏, reason: contains not printable characters */
    public static final class C1369<T> extends C1307<T> {

        /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
        public final C1368 f4519;

        public C1369(InterfaceC6575<? super T> interfaceC6575, C1368 c1368) {
            super(interfaceC6575, 1);
            this.f4519 = c1368;
        }

        @Override // p025.p026.C1307
        /* JADX INFO: renamed from: ֏ */
        public Throwable mo2626(InterfaceC1363 interfaceC1363) {
            Throwable th;
            Object objM2717 = this.f4519.m2717();
            return (!(objM2717 instanceof C1371) || (th = (Throwable) ((C1371) objM2717)._rootCause) == null) ? objM2717 instanceof C1318 ? ((C1318) objM2717).f4456 : interfaceC1363.mo2686() : th;
        }

        @Override // p025.p026.C1307
        /* JADX INFO: renamed from: ޅ */
        public String mo2638() {
            return "AwaitContinuation";
        }
    }

    /* JADX INFO: renamed from: އ.֏.ൎ$ؠ, reason: contains not printable characters */
    public static final class C1370 extends AbstractC1367<InterfaceC1363> {

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public final C1368 f4520;

        /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
        public final C1371 f4521;

        /* JADX INFO: renamed from: މ, reason: contains not printable characters */
        public final C1312 f4522;

        /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
        public final Object f4523;

        public C1370(C1368 c1368, C1371 c1371, C1312 c1312, Object obj) {
            super(c1312.f4450);
            this.f4520 = c1368;
            this.f4521 = c1371;
            this.f4522 = c1312;
            this.f4523 = obj;
        }

        @Override // p025.p026.p027.C1284
        public String toString() {
            StringBuilder sbM4889 = C2803.m4889("ChildCompletion[");
            sbM4889.append(this.f4522);
            sbM4889.append(", ");
            sbM4889.append(this.f4523);
            sbM4889.append(']');
            return sbM4889.toString();
        }

        @Override // p402.p411.p412.InterfaceC6614
        /* JADX INFO: renamed from: ؠ */
        public /* bridge */ /* synthetic */ C6549 mo1606(Throwable th) {
            mo2640(th);
            return C6549.f19328;
        }

        @Override // p025.p026.AbstractC1321
        /* JADX INFO: renamed from: ؠ, reason: avoid collision after fix types in other method */
        public void mo2640(Throwable th) {
            C1368 c1368 = this.f4520;
            C1371 c1371 = this.f4521;
            C1312 c1312 = this.f4522;
            Object obj = this.f4523;
            C1312 c1312M2694 = c1368.m2694((C1284) c1312);
            if (c1312M2694 == null || !c1368.m2702(c1371, c1312M2694, obj)) {
                c1368.mo2590(c1368.m2691(c1371, obj));
            }
        }
    }

    /* JADX INFO: renamed from: އ.֏.ൎ$ހ, reason: contains not printable characters */
    public static final class C1371 implements InterfaceC1358 {
        public volatile Object _exceptionsHolder = null;
        public volatile int _isCompleting;
        public volatile Object _rootCause;

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final C1377 f4524;

        public C1371(C1377 c1377, boolean z, Throwable th) {
            this.f4524 = c1377;
            this._isCompleting = z ? 1 : 0;
            this._rootCause = th;
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference failed for: r1v2, types: [boolean, int] */
        public String toString() {
            StringBuilder sbM4889 = C2803.m4889("Finishing[cancelling=");
            sbM4889.append(m2721());
            sbM4889.append(", completing=");
            sbM4889.append((boolean) this._isCompleting);
            sbM4889.append(", rootCause=");
            sbM4889.append((Throwable) this._rootCause);
            sbM4889.append(", exceptions=");
            sbM4889.append(this._exceptionsHolder);
            sbM4889.append(", list=");
            sbM4889.append(this.f4524);
            sbM4889.append(']');
            return sbM4889.toString();
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final ArrayList<Throwable> m2718() {
            return new ArrayList<>(4);
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m2719(Throwable th) {
            Throwable th2 = (Throwable) this._rootCause;
            if (th2 == null) {
                this._rootCause = th;
                return;
            }
            if (th == th2) {
                return;
            }
            Object obj = this._exceptionsHolder;
            if (obj == null) {
                this._exceptionsHolder = th;
                return;
            }
            if (obj instanceof Throwable) {
                if (th == obj) {
                    return;
                }
                ArrayList<Throwable> arrayListM2718 = m2718();
                arrayListM2718.add(obj);
                arrayListM2718.add(th);
                this._exceptionsHolder = arrayListM2718;
                return;
            }
            if (obj instanceof ArrayList) {
                ((ArrayList) obj).add(th);
                return;
            }
            throw new IllegalStateException(("State is " + obj).toString());
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final List<Throwable> m2720(Throwable th) {
            ArrayList arrayListM2718;
            Object obj = this._exceptionsHolder;
            if (obj == null) {
                arrayListM2718 = m2718();
            } else if (obj instanceof Throwable) {
                ArrayList arrayListM27182 = m2718();
                arrayListM27182.add(obj);
                arrayListM2718 = arrayListM27182;
            } else {
                if (!(obj instanceof ArrayList)) {
                    throw new IllegalStateException(("State is " + obj).toString());
                }
                arrayListM2718 = (ArrayList) obj;
            }
            Throwable th2 = (Throwable) this._rootCause;
            if (th2 != null) {
                arrayListM2718.add(0, th2);
            }
            if (th != null && (!C6635.m9825(th, th2))) {
                arrayListM2718.add(th);
            }
            this._exceptionsHolder = C1373.f4531;
            return arrayListM2718;
        }

        @Override // p025.p026.InterfaceC1358
        /* JADX INFO: renamed from: ؠ */
        public C1377 mo2667() {
            return this.f4524;
        }

        @Override // p025.p026.InterfaceC1358
        /* JADX INFO: renamed from: ހ */
        public boolean mo2668() {
            return ((Throwable) this._rootCause) == null;
        }

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final boolean m2721() {
            return ((Throwable) this._rootCause) != null;
        }

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public final boolean m2722() {
            return this._exceptionsHolder == C1373.f4531;
        }
    }

    /* JADX INFO: renamed from: އ.֏.ൎ$ށ, reason: contains not printable characters */
    public static final class C1372 extends C1284.AbstractC1285 {

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final /* synthetic */ C1368 f4525;

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public final /* synthetic */ Object f4526;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C1372(C1284 c1284, C1284 c12842, C1368 c1368, Object obj) {
            super(c12842);
            this.f4525 = c1368;
            this.f4526 = obj;
        }

        @Override // p025.p026.p027.AbstractC1279
        /* JADX INFO: renamed from: ؠ */
        public Object mo2566(C1284 c1284) {
            if (this.f4525.m2717() == this.f4526) {
                return null;
            }
            return C1283.f4412;
        }
    }

    public C1368(boolean z) {
        this._state = z ? C1373.f4533 : C1373.f4532;
        this._parentHandle = null;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static /* synthetic */ CancellationException m2690(C1368 c1368, Throwable th, String str, int i, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: toCancellationException");
        }
        if ((i & 1) != 0) {
            str = null;
        }
        return c1368.m2693(th, str);
    }

    @Override // p402.p405.InterfaceC6578
    public <R> R fold(R r, InterfaceC6618<? super R, ? super InterfaceC6578.InterfaceC6579, ? extends R> interfaceC6618) {
        return (R) InterfaceC6578.InterfaceC6579.C6580.m9801(this, r, interfaceC6618);
    }

    @Override // p402.p405.InterfaceC6578.InterfaceC6579, p402.p405.InterfaceC6578
    public <E extends InterfaceC6578.InterfaceC6579> E get(InterfaceC6578.InterfaceC6581<E> interfaceC6581) {
        return (E) InterfaceC6578.InterfaceC6579.C6580.m9802(this, interfaceC6581);
    }

    @Override // p402.p405.InterfaceC6578.InterfaceC6579
    public final InterfaceC6578.InterfaceC6581<?> getKey() {
        return InterfaceC1363.f4514;
    }

    @Override // p402.p405.InterfaceC6578
    public InterfaceC6578 minusKey(InterfaceC6578.InterfaceC6581<?> interfaceC6581) {
        return InterfaceC6578.InterfaceC6579.C6580.m9804(this, interfaceC6581);
    }

    @Override // p402.p405.InterfaceC6578
    public InterfaceC6578 plus(InterfaceC6578 interfaceC6578) {
        return InterfaceC6578.InterfaceC6579.C6580.m9803(this, interfaceC6578);
    }

    @Override // p025.p026.InterfaceC1363
    public final boolean start() {
        int iM2715;
        do {
            iM2715 = m2715(m2717());
            if (iM2715 == 0) {
                return false;
            }
        } while (iM2715 != 1);
        return true;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(mo2614() + '{' + m2716(m2717()) + '}');
        sb.append('@');
        sb.append(C4303.m7180(this));
        return sb.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Object m2691(C1371 c1371, Object obj) throws Throwable {
        boolean zM2721;
        Throwable thM2692;
        C1318 c1318 = (C1318) (!(obj instanceof C1318) ? null : obj);
        Throwable th = c1318 != null ? c1318.f4456 : null;
        synchronized (c1371) {
            zM2721 = c1371.m2721();
            List<Throwable> listM2720 = c1371.m2720(th);
            thM2692 = m2692(c1371, (List<? extends Throwable>) listM2720);
            if (thM2692 != null && listM2720.size() > 1) {
                Set setNewSetFromMap = Collections.newSetFromMap(new IdentityHashMap(listM2720.size()));
                for (Throwable th2 : listM2720) {
                    if (th2 != thM2692 && th2 != thM2692 && !(th2 instanceof CancellationException) && setNewSetFromMap.add(th2)) {
                        C4303.m7093(thM2692, th2);
                    }
                }
            }
        }
        if (thM2692 != null && thM2692 != th) {
            obj = new C1318(thM2692, false, 2, null);
        }
        if (thM2692 != null) {
            if (m2707(thM2692) || mo2712(thM2692)) {
                if (obj == null) {
                    throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.CompletedExceptionally");
                }
                C1318.f4455.compareAndSet((C1318) obj, 0, 1);
            }
        }
        if (!zM2721) {
            mo2714(thM2692);
        }
        mo2613(obj);
        f4518.compareAndSet(this, c1371, obj instanceof InterfaceC1358 ? new C1359((InterfaceC1358) obj) : obj);
        m2697((InterfaceC1358) c1371, obj);
        return obj;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Throwable m2692(C1371 c1371, List<? extends Throwable> list) {
        Object next;
        Object obj = null;
        if (list.isEmpty()) {
            if (c1371.m2721()) {
                return new JobCancellationException(mo2611(), null, this);
            }
            return null;
        }
        Iterator<T> it = list.iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            }
            next = it.next();
            if (!(((Throwable) next) instanceof CancellationException)) {
                break;
            }
        }
        Throwable th = (Throwable) next;
        if (th != null) {
            return th;
        }
        Throwable th2 = list.get(0);
        if (th2 instanceof TimeoutCancellationException) {
            Iterator<T> it2 = list.iterator();
            while (true) {
                if (!it2.hasNext()) {
                    break;
                }
                Object next2 = it2.next();
                Throwable th3 = (Throwable) next2;
                if (th3 != th2 && (th3 instanceof TimeoutCancellationException)) {
                    obj = next2;
                    break;
                }
            }
            Throwable th4 = (Throwable) obj;
            if (th4 != null) {
                return th4;
            }
        }
        return th2;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final CancellationException m2693(Throwable th, String str) {
        CancellationException jobCancellationException = (CancellationException) (!(th instanceof CancellationException) ? null : th);
        if (jobCancellationException == null) {
            if (str == null) {
                str = mo2611();
            }
            jobCancellationException = new JobCancellationException(str, th, this);
        }
        return jobCancellationException;
    }

    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ֏ */
    public final InterfaceC1311 mo2682(InterfaceC1313 interfaceC1313) {
        InterfaceC1341 interfaceC1341M7051 = C4303.m7051((InterfaceC1363) this, true, false, (InterfaceC6614) new C1312(this, interfaceC1313), 2, (Object) null);
        if (interfaceC1341M7051 != null) {
            return (InterfaceC1311) interfaceC1341M7051;
        }
        throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.ChildHandle");
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C1312 m2694(C1284 c1284) {
        while (c1284.mo2568()) {
            c1284 = c1284.m2577();
        }
        while (true) {
            c1284 = c1284.m2576();
            if (!c1284.mo2568()) {
                if (c1284 instanceof C1312) {
                    return (C1312) c1284;
                }
                if (c1284 instanceof C1377) {
                    return null;
                }
            }
        }
    }

    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ֏ */
    public final InterfaceC1341 mo2683(InterfaceC6614<? super Throwable, C6549> interfaceC6614) {
        return mo2684(false, true, interfaceC6614);
    }

    /* JADX WARN: Removed duplicated region for block: B:58:0x0093  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x008d A[SYNTHETIC] */
    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final InterfaceC1341 mo2684(boolean z, boolean z2, InterfaceC6614<? super Throwable, C6549> interfaceC6614) {
        Throwable th;
        AbstractC1367<?> abstractC1367M2695 = null;
        while (true) {
            Object objM2717 = m2717();
            if (objM2717 instanceof C1344) {
                C1344 c1344 = (C1344) objM2717;
                if (c1344.f4491) {
                    if (abstractC1367M2695 == null) {
                        abstractC1367M2695 = m2695(interfaceC6614, z);
                    }
                    if (f4518.compareAndSet(this, objM2717, abstractC1367M2695)) {
                        return abstractC1367M2695;
                    }
                } else {
                    C1377 c1377 = new C1377();
                    Object c1357 = c1377;
                    if (!c1344.f4491) {
                        c1357 = new C1357(c1377);
                    }
                    f4518.compareAndSet(this, c1344, c1357);
                }
            } else {
                if (!(objM2717 instanceof InterfaceC1358)) {
                    if (z2) {
                        if (!(objM2717 instanceof C1318)) {
                            objM2717 = null;
                        }
                        C1318 c1318 = (C1318) objM2717;
                        interfaceC6614.mo1606(c1318 != null ? c1318.f4456 : null);
                    }
                    return C1378.f4536;
                }
                C1377 c1377Mo2667 = ((InterfaceC1358) objM2717).mo2667();
                if (c1377Mo2667 != null) {
                    InterfaceC1341 interfaceC1341 = C1378.f4536;
                    if (z && (objM2717 instanceof C1371)) {
                        synchronized (objM2717) {
                            th = (Throwable) ((C1371) objM2717)._rootCause;
                            if (th == null || ((interfaceC6614 instanceof C1312) && ((C1371) objM2717)._isCompleting == 0)) {
                                if (abstractC1367M2695 == null) {
                                    abstractC1367M2695 = m2695(interfaceC6614, z);
                                }
                                if (m2701(objM2717, c1377Mo2667, abstractC1367M2695)) {
                                    if (th == null) {
                                        return abstractC1367M2695;
                                    }
                                    interfaceC1341 = abstractC1367M2695;
                                }
                            }
                        }
                        if (th == null) {
                        }
                    } else {
                        th = null;
                        if (th == null) {
                            if (z2) {
                                interfaceC6614.mo1606(th);
                            }
                            return interfaceC1341;
                        }
                        if (abstractC1367M2695 == null) {
                            abstractC1367M2695 = m2695(interfaceC6614, z);
                        }
                        if (m2701(objM2717, c1377Mo2667, abstractC1367M2695)) {
                            return abstractC1367M2695;
                        }
                    }
                } else {
                    if (objM2717 == null) {
                        throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.JobNode<*>");
                    }
                    m2699((AbstractC1367<?>) objM2717);
                }
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final AbstractC1367<?> m2695(InterfaceC6614<? super Throwable, C6549> interfaceC6614, boolean z) {
        if (z) {
            AbstractC1365 abstractC1365 = (AbstractC1365) (interfaceC6614 instanceof AbstractC1365 ? interfaceC6614 : null);
            return abstractC1365 != null ? abstractC1365 : new C1361(this, interfaceC6614);
        }
        AbstractC1367<?> abstractC1367 = (AbstractC1367) (interfaceC6614 instanceof AbstractC1367 ? interfaceC6614 : null);
        return abstractC1367 != null ? abstractC1367 : new C1362(this, interfaceC6614);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C1377 m2696(InterfaceC1358 interfaceC1358) {
        C1377 c1377Mo2667 = interfaceC1358.mo2667();
        if (c1377Mo2667 != null) {
            return c1377Mo2667;
        }
        if (interfaceC1358 instanceof C1344) {
            return new C1377();
        }
        if (interfaceC1358 instanceof AbstractC1367) {
            m2699((AbstractC1367<?>) interfaceC1358);
            return null;
        }
        throw new IllegalStateException(("State should have list: " + interfaceC1358).toString());
    }

    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ֏ */
    public void mo2685(CancellationException cancellationException) throws Throwable {
        if (cancellationException == null) {
            cancellationException = new JobCancellationException(mo2611(), null, this);
        }
        mo2705(cancellationException);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m2697(InterfaceC1358 interfaceC1358, Object obj) throws Throwable {
        InterfaceC1311 interfaceC1311 = (InterfaceC1311) this._parentHandle;
        if (interfaceC1311 != null) {
            interfaceC1311.mo2666();
            this._parentHandle = C1378.f4536;
        }
        CompletionHandlerException completionHandlerException = null;
        if (!(obj instanceof C1318)) {
            obj = null;
        }
        C1318 c1318 = (C1318) obj;
        Throwable th = c1318 != null ? c1318.f4456 : null;
        if (interfaceC1358 instanceof AbstractC1367) {
            try {
                ((AbstractC1367) interfaceC1358).mo2640(th);
                return;
            } catch (Throwable th2) {
                mo2612((Throwable) new CompletionHandlerException("Exception in completion handler " + interfaceC1358 + " for " + this, th2));
                return;
            }
        }
        C1377 c1377Mo2667 = interfaceC1358.mo2667();
        if (c1377Mo2667 != null) {
            Object objM2575 = c1377Mo2667.m2575();
            if (objM2575 == null) {
                throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.internal.Node /* = kotlinx.coroutines.internal.LockFreeLinkedListNode */");
            }
            for (C1284 c1284M2576 = (C1284) objM2575; !C6635.m9825(c1284M2576, c1377Mo2667); c1284M2576 = c1284M2576.m2576()) {
                if (c1284M2576 instanceof AbstractC1367) {
                    AbstractC1367 abstractC1367 = (AbstractC1367) c1284M2576;
                    try {
                        abstractC1367.mo2640(th);
                    } catch (Throwable th3) {
                        if (completionHandlerException != null) {
                            C4303.m7093((Throwable) completionHandlerException, th3);
                        } else {
                            completionHandlerException = new CompletionHandlerException("Exception in completion handler " + abstractC1367 + " for " + this, th3);
                        }
                    }
                }
            }
            if (completionHandlerException != null) {
                mo2612((Throwable) completionHandlerException);
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m2698(InterfaceC1363 interfaceC1363) {
        if (interfaceC1363 == null) {
            this._parentHandle = C1378.f4536;
            return;
        }
        interfaceC1363.start();
        InterfaceC1311 interfaceC1311Mo2682 = interfaceC1363.mo2682(this);
        this._parentHandle = interfaceC1311Mo2682;
        if (mo2687()) {
            interfaceC1311Mo2682.mo2666();
            this._parentHandle = C1378.f4536;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m2699(AbstractC1367<?> abstractC1367) {
        C1377 c1377 = new C1377();
        if (abstractC1367 == null) {
            throw null;
        }
        C1284.f4414.lazySet(c1377, abstractC1367);
        C1284.f4413.lazySet(c1377, abstractC1367);
        while (true) {
            if (abstractC1367.m2575() != abstractC1367) {
                break;
            } else if (C1284.f4413.compareAndSet(abstractC1367, abstractC1367, c1377)) {
                c1377.m2573(abstractC1367);
                break;
            }
        }
        f4518.compareAndSet(this, abstractC1367, abstractC1367.m2576());
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m2700(C1377 c1377, Throwable th) throws Throwable {
        mo2714(th);
        Object objM2575 = c1377.m2575();
        if (objM2575 == null) {
            throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.internal.Node /* = kotlinx.coroutines.internal.LockFreeLinkedListNode */");
        }
        CompletionHandlerException completionHandlerException = null;
        for (C1284 c1284M2576 = (C1284) objM2575; !C6635.m9825(c1284M2576, c1377); c1284M2576 = c1284M2576.m2576()) {
            if (c1284M2576 instanceof AbstractC1365) {
                AbstractC1367 abstractC1367 = (AbstractC1367) c1284M2576;
                try {
                    abstractC1367.mo2640(th);
                } catch (Throwable th2) {
                    if (completionHandlerException != null) {
                        C4303.m7093((Throwable) completionHandlerException, th2);
                    } else {
                        completionHandlerException = new CompletionHandlerException("Exception in completion handler " + abstractC1367 + " for " + this, th2);
                    }
                }
            }
        }
        if (completionHandlerException != null) {
            mo2612((Throwable) completionHandlerException);
        }
        m2707(th);
    }

    @Override // p025.p026.InterfaceC1313
    /* JADX INFO: renamed from: ֏ */
    public final void mo2642(InterfaceC1380 interfaceC1380) throws Throwable {
        m2706(interfaceC1380);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m2701(Object obj, C1377 c1377, AbstractC1367<?> abstractC1367) {
        int iM2571;
        C1372 c1372 = new C1372(abstractC1367, abstractC1367, this, obj);
        do {
            iM2571 = c1377.m2577().m2571(abstractC1367, c1377, c1372);
            if (iM2571 == 1) {
                return true;
            }
        } while (iM2571 != 2);
        return false;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m2702(C1371 c1371, C1312 c1312, Object obj) {
        while (C4303.m7051((InterfaceC1363) c1312.f4450, false, false, (InterfaceC6614) new C1370(this, c1371, c1312, obj), 1, (Object) null) == C1378.f4536) {
            c1312 = m2694((C1284) c1312);
            if (c1312 == null) {
                return false;
            }
        }
        return true;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Object m2703(Object obj, Object obj2) throws Throwable {
        boolean z;
        if (!(obj instanceof InterfaceC1358)) {
            return C1373.f4527;
        }
        if ((!(obj instanceof C1344) && !(obj instanceof AbstractC1367)) || (obj instanceof C1312) || (obj2 instanceof C1318)) {
            return m2704((InterfaceC1358) obj, obj2);
        }
        InterfaceC1358 interfaceC1358 = (InterfaceC1358) obj;
        if (f4518.compareAndSet(this, interfaceC1358, C1373.m2723(obj2))) {
            mo2714((Throwable) null);
            mo2613(obj2);
            m2697(interfaceC1358, obj2);
            z = true;
        } else {
            z = false;
        }
        return z ? obj2 : C1373.f4529;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Object m2704(InterfaceC1358 interfaceC1358, Object obj) throws Throwable {
        C1377 c1377M2696 = m2696(interfaceC1358);
        if (c1377M2696 == null) {
            return C1373.f4529;
        }
        C1312 c1312M2694 = null;
        C1371 c1371 = (C1371) (!(interfaceC1358 instanceof C1371) ? null : interfaceC1358);
        if (c1371 == null) {
            c1371 = new C1371(c1377M2696, false, null);
        }
        synchronized (c1371) {
            if (c1371._isCompleting != 0) {
                return C1373.f4527;
            }
            c1371._isCompleting = 1;
            if (c1371 != interfaceC1358 && !f4518.compareAndSet(this, interfaceC1358, c1371)) {
                return C1373.f4529;
            }
            boolean zM2721 = c1371.m2721();
            C1318 c1318 = (C1318) (!(obj instanceof C1318) ? null : obj);
            if (c1318 != null) {
                c1371.m2719(c1318.f4456);
            }
            Throwable th = (Throwable) c1371._rootCause;
            if (!(true ^ zM2721)) {
                th = null;
            }
            if (th != null) {
                m2700(c1377M2696, th);
            }
            C1312 c1312 = (C1312) (!(interfaceC1358 instanceof C1312) ? null : interfaceC1358);
            if (c1312 != null) {
                c1312M2694 = c1312;
            } else {
                C1377 c1377Mo2667 = interfaceC1358.mo2667();
                if (c1377Mo2667 != null) {
                    c1312M2694 = m2694((C1284) c1377Mo2667);
                }
            }
            return (c1312M2694 == null || !m2702(c1371, c1312M2694, obj)) ? m2691(c1371, obj) : C1373.f4528;
        }
    }

    /* JADX INFO: renamed from: ؠ */
    public void mo2590(Object obj) {
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public void mo2705(Throwable th) throws Throwable {
        m2706((Object) th);
    }

    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ހ */
    public boolean mo2610() {
        Object objM2717 = m2717();
        return (objM2717 instanceof InterfaceC1358) && ((InterfaceC1358) objM2717).mo2668();
    }

    /* JADX INFO: renamed from: ށ */
    public String mo2611() {
        return "Job was cancelled";
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final boolean m2706(Object obj) throws Throwable {
        Object objM2710 = C1373.f4527;
        if (mo2689()) {
            do {
                Object objM2717 = m2717();
                if (!(objM2717 instanceof InterfaceC1358) || ((objM2717 instanceof C1371) && ((C1371) objM2717)._isCompleting != 0)) {
                    objM2710 = C1373.f4527;
                    break;
                }
                objM2710 = m2703(objM2717, new C1318(m2708(obj), false, 2, null));
            } while (objM2710 == C1373.f4529);
            if (objM2710 == C1373.f4528) {
                return true;
            }
        }
        if (objM2710 == C1373.f4527) {
            objM2710 = m2710(obj);
        }
        if (objM2710 != C1373.f4527 && objM2710 != C1373.f4528) {
            if (objM2710 == C1373.f4530) {
                return false;
            }
            mo2590(objM2710);
        }
        return true;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final boolean m2707(Throwable th) {
        if (mo2592()) {
            return true;
        }
        boolean z = th instanceof CancellationException;
        InterfaceC1311 interfaceC1311 = (InterfaceC1311) this._parentHandle;
        return (interfaceC1311 == null || interfaceC1311 == C1378.f4536) ? z : interfaceC1311.mo2641(th) || z;
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final Throwable m2708(Object obj) {
        if (obj != null ? obj instanceof Throwable : true) {
            return obj != null ? (Throwable) obj : new JobCancellationException(mo2611(), null, this);
        }
        if (obj != null) {
            return ((InterfaceC1380) obj).mo2711();
        }
        throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.ParentJob");
    }

    /* JADX INFO: renamed from: ނ */
    public boolean mo2688() {
        return true;
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public boolean mo2709(Throwable th) {
        if (th instanceof CancellationException) {
            return true;
        }
        return m2706((Object) th) && mo2688();
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x007a  */
    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m2710(Object obj) throws Throwable {
        Throwable thM2708 = null;
        while (true) {
            Object objM2717 = m2717();
            boolean z = true;
            if (objM2717 instanceof C1371) {
                synchronized (objM2717) {
                    if (((C1371) objM2717).m2722()) {
                        return C1373.f4530;
                    }
                    boolean zM2721 = ((C1371) objM2717).m2721();
                    if (obj != null || !zM2721) {
                        if (thM2708 == null) {
                            thM2708 = m2708(obj);
                        }
                        ((C1371) objM2717).m2719(thM2708);
                    }
                    Throwable th = zM2721 ^ true ? (Throwable) ((C1371) objM2717)._rootCause : null;
                    if (th != null) {
                        m2700(((C1371) objM2717).f4524, th);
                    }
                    return C1373.f4527;
                }
            }
            if (!(objM2717 instanceof InterfaceC1358)) {
                return C1373.f4530;
            }
            if (thM2708 == null) {
                thM2708 = m2708(obj);
            }
            InterfaceC1358 interfaceC1358 = (InterfaceC1358) objM2717;
            if (interfaceC1358.mo2668()) {
                C1377 c1377M2696 = m2696(interfaceC1358);
                if (c1377M2696 != null) {
                    if (f4518.compareAndSet(this, interfaceC1358, new C1371(c1377M2696, false, thM2708))) {
                        m2700(c1377M2696, thM2708);
                    } else {
                        z = false;
                    }
                    if (z) {
                        return C1373.f4527;
                    }
                }
            } else {
                Object objM2703 = m2703(objM2717, new C1318(thM2708, false, 2, null));
                if (objM2703 == C1373.f4527) {
                    throw new IllegalStateException(("Cannot happen in " + objM2717).toString());
                }
                if (objM2703 != C1373.f4529) {
                    return objM2703;
                }
            }
        }
    }

    @Override // p025.p026.InterfaceC1380
    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public CancellationException mo2711() {
        Throwable th;
        Object objM2717 = m2717();
        if (objM2717 instanceof C1371) {
            th = (Throwable) ((C1371) objM2717)._rootCause;
        } else if (objM2717 instanceof C1318) {
            th = ((C1318) objM2717).f4456;
        } else {
            if (objM2717 instanceof InterfaceC1358) {
                throw new IllegalStateException(("Cannot be cancelling child in this state: " + objM2717).toString());
            }
            th = null;
        }
        CancellationException cancellationException = (CancellationException) (th instanceof CancellationException ? th : null);
        if (cancellationException != null) {
            return cancellationException;
        }
        StringBuilder sbM4889 = C2803.m4889("Parent job is ");
        sbM4889.append(m2716(objM2717));
        return new JobCancellationException(sbM4889.toString(), th, this);
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public boolean mo2712(Throwable th) {
        return false;
    }

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Object m2713(Object obj) {
        Object objM2703;
        do {
            objM2703 = m2703(m2717(), obj);
            if (objM2703 == C1373.f4527) {
                String str = "Job " + this + " is already complete or completing, but is being completed with " + obj;
                if (!(obj instanceof C1318)) {
                    obj = null;
                }
                C1318 c1318 = (C1318) obj;
                throw new IllegalStateException(str, c1318 != null ? c1318.f4456 : null);
            }
        } while (objM2703 == C1373.f4529);
        return objM2703;
    }

    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ބ */
    public final CancellationException mo2686() {
        Object objM2717 = m2717();
        if (!(objM2717 instanceof C1371)) {
            if (objM2717 instanceof InterfaceC1358) {
                throw new IllegalStateException(("Job is still new or active: " + this).toString());
            }
            if (objM2717 instanceof C1318) {
                return m2690(this, ((C1318) objM2717).f4456, null, 1, null);
            }
            return new JobCancellationException(getClass().getSimpleName() + " has completed normally", null, this);
        }
        Throwable th = (Throwable) ((C1371) objM2717)._rootCause;
        if (th != null) {
            CancellationException cancellationExceptionM2693 = m2693(th, getClass().getSimpleName() + " is cancelling");
            if (cancellationExceptionM2693 != null) {
                return cancellationExceptionM2693;
            }
        }
        throw new IllegalStateException(("Job is still new or active: " + this).toString());
    }

    /* JADX INFO: renamed from: ބ */
    public void mo2612(Throwable th) throws Throwable {
        throw th;
    }

    /* JADX INFO: renamed from: ޅ */
    public void mo2613(Object obj) {
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public void mo2714(Throwable th) {
    }

    @Override // p025.p026.InterfaceC1363
    /* JADX INFO: renamed from: ޅ */
    public final boolean mo2687() {
        return !(m2717() instanceof InterfaceC1358);
    }

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final int m2715(Object obj) {
        if (obj instanceof C1344) {
            if (((C1344) obj).f4491) {
                return 0;
            }
            if (!f4518.compareAndSet(this, obj, C1373.f4533)) {
                return -1;
            }
            mo2615();
            return 1;
        }
        if (!(obj instanceof C1357)) {
            return 0;
        }
        if (!f4518.compareAndSet(this, obj, ((C1357) obj).f4508)) {
            return -1;
        }
        mo2615();
        return 1;
    }

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final String m2716(Object obj) {
        if (!(obj instanceof C1371)) {
            return obj instanceof InterfaceC1358 ? ((InterfaceC1358) obj).mo2668() ? "Active" : "New" : obj instanceof C1318 ? "Cancelled" : "Completed";
        }
        C1371 c1371 = (C1371) obj;
        return c1371.m2721() ? "Cancelling" : c1371._isCompleting != 0 ? "Completing" : "Active";
    }

    /* JADX INFO: renamed from: އ */
    public boolean mo2689() {
        return false;
    }

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final Object m2717() {
        while (true) {
            Object obj = this._state;
            if (!(obj instanceof AbstractC1292)) {
                return obj;
            }
            ((AbstractC1292) obj).mo2564(this);
        }
    }

    /* JADX INFO: renamed from: މ */
    public boolean mo2592() {
        return false;
    }

    /* JADX INFO: renamed from: ފ */
    public String mo2614() {
        return getClass().getSimpleName();
    }

    /* JADX INFO: renamed from: ދ */
    public void mo2615() {
    }
}
