package defpackage;

import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlinx.coroutines.CompletionHandlerException;
import kotlinx.coroutines.DispatchException;
import sun.misc.Unsafe;

/* renamed from: ᵱʽ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public class C4385 extends AbstractC4927 implements InterfaceC0719, InterfaceC0571, InterfaceC5233 {

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public static final /* synthetic */ long f16429;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public static final /* synthetic */ long f16430;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f16431;
    private volatile /* synthetic */ int _decisionAndIndex$volatile;
    private volatile /* synthetic */ Object _parentHandle$volatile;
    private volatile /* synthetic */ Object _state$volatile;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final InterfaceC2262 f16433;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final InterfaceC4943 f16434;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final /* synthetic */ AtomicIntegerFieldUpdater f16432 = AtomicIntegerFieldUpdater.newUpdater(C4385.class, "_decisionAndIndex$volatile");

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f16428 = AtomicReferenceFieldUpdater.newUpdater(C4385.class, Object.class, "_state$volatile");

    static {
        Unsafe unsafe = AbstractC3747.f13986;
        f16429 = unsafe.objectFieldOffset(C4385.class.getDeclaredField("_state$volatile"));
        f16431 = AtomicReferenceFieldUpdater.newUpdater(C4385.class, Object.class, "_parentHandle$volatile");
        f16430 = unsafe.objectFieldOffset(C4385.class.getDeclaredField("_parentHandle$volatile"));
    }

    public C4385(int i, InterfaceC4943 interfaceC4943) {
        super(i);
        this.f16434 = interfaceC4943;
        this.f16433 = interfaceC4943.mo2135();
        this._decisionAndIndex$volatile = 536870911;
        this._state$volatile = C4102.f15331;
    }

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public static Object m9392(InterfaceC5554 interfaceC5554, Object obj, int i, InterfaceC2634 interfaceC2634) {
        if (obj instanceof C1411) {
            return obj;
        }
        if (i != 1 && i != 2) {
            return obj;
        }
        if (interfaceC2634 != null || (interfaceC5554 instanceof InterfaceC1868)) {
            return new C0703(obj, interfaceC5554 instanceof InterfaceC1868 ? (InterfaceC1868) interfaceC5554 : null, interfaceC2634, (Throwable) null, 16);
        }
        return obj;
    }

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public static void m9393(Object obj, Object obj2) {
        throw new IllegalStateException(("It's prohibited to register multiple handlers, tried to register " + obj + ", already has " + obj2).toString());
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(mo4887());
        sb.append('(');
        sb.append(ˁـᵛ.ᐧﾞ(this.f16434));
        sb.append("){");
        Object objM9402 = m9402();
        sb.append(objM9402 instanceof InterfaceC5554 ? "Active" : objM9402 instanceof C3412 ? "Cancelled" : "Completed");
        sb.append("}@");
        sb.append(ˁـᵛ.ᵳٴᵶ(this));
        return sb.toString();
    }

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final boolean m9394() {
        return this.f18326 == 2 && ((C2869) this.f16434).m7012();
    }

    @Override // defpackage.InterfaceC4943
    /* renamed from: ˇʼʤˎ */
    public final void mo2134(Object obj) throws DispatchException {
        Throwable thM8872 = AbstractC4019.m8872(obj);
        if (thM8872 != null) {
            obj = new C1411(thM8872, false);
        }
        m9404(obj, this.f18326, null);
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m9395(AbstractC2858 abstractC2858, Throwable th) {
        InterfaceC2262 interfaceC2262 = this.f16433;
        int i = f16432.get(this) & 536870911;
        if (i == 536870911) {
            ᵹˉᵞ.ᵳٴᵶ("The index for Segment.onCancellation(..) is broken");
            return;
        }
        try {
            abstractC2858.mo2529(i, interfaceC2262);
        } catch (Throwable th2) {
            ᵭʝʜ.ᵸʓᵠ(interfaceC2262, new CompletionHandlerException("Exception in invokeOnCancellation handler for " + this, th2));
        }
    }

    @Override // defpackage.InterfaceC4943
    /* renamed from: ˌᵜᵹᵩ */
    public final InterfaceC2262 mo2135() {
        return this.f16433;
    }

    @Override // defpackage.InterfaceC0719
    /* renamed from: ˎˏʜʾ */
    public final C0434 mo2136(Object obj, InterfaceC2634 interfaceC2634) {
        return m9409(obj, interfaceC2634);
    }

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final void m9396() throws DispatchException {
        Throwable thM7011;
        InterfaceC4943 interfaceC4943 = this.f16434;
        C2869 c2869 = interfaceC4943 instanceof C2869 ? (C2869) interfaceC4943 : null;
        if (c2869 == null || (thM7011 = c2869.m7011(this)) == null) {
            return;
        }
        m9410();
        m9400(thM7011);
    }

    @Override // defpackage.AbstractC4927
    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final Throwable mo9397(Object obj) {
        Throwable thMo9397 = super.mo9397(obj);
        if (thMo9397 != null) {
            return thMo9397;
        }
        return null;
    }

    @Override // defpackage.AbstractC4927
    /* renamed from: ˏᵙ */
    public final InterfaceC4943 mo7010() {
        return this.f16434;
    }

    /* renamed from: ˑᵥˁ */
    public String mo4887() {
        return "CancellableContinuation";
    }

    /* renamed from: ˑᵱ, reason: contains not printable characters */
    public final InterfaceC3451 m9398() {
        f16431.getClass();
        return (InterfaceC3451) AbstractC3747.f13986.getObjectVolatile(this, f16430);
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final void m9399(int i) throws DispatchException {
        AtomicIntegerFieldUpdater atomicIntegerFieldUpdater;
        int i2;
        do {
            atomicIntegerFieldUpdater = f16432;
            i2 = atomicIntegerFieldUpdater.get(this);
            int i3 = i2 >> 29;
            if (i3 != 0) {
                if (i3 != 1) {
                    ᵹˉᵞ.ᵳٴᵶ("Already resumed");
                    return;
                }
                boolean z = i == 4;
                InterfaceC4943 interfaceC4943 = this.f16434;
                if (!z && (interfaceC4943 instanceof C2869)) {
                    boolean z2 = i == 1 || i == 2;
                    int i4 = this.f18326;
                    if (z2 == (i4 == 1 || i4 == 2)) {
                        C2869 c2869 = (C2869) interfaceC4943;
                        AbstractC2687 abstractC2687 = c2869.f11121;
                        InterfaceC2262 interfaceC2262Mo2135 = c2869.f11120.mo2135();
                        if (AbstractC1243.m3783(abstractC2687, interfaceC2262Mo2135)) {
                            AbstractC1243.m3785(abstractC2687, interfaceC2262Mo2135, this);
                            return;
                        }
                        AbstractC0685 abstractC0685M4289 = AbstractC1407.m4289();
                        if (abstractC0685M4289.f3352 >= 4294967296L) {
                            abstractC0685M4289.m2662(this);
                            return;
                        }
                        abstractC0685M4289.m2663(true);
                        try {
                            ᵺᵣᵬ.ᵡˎ(this, interfaceC4943, true);
                            do {
                            } while (abstractC0685M4289.m2664());
                        } finally {
                            try {
                                return;
                            } finally {
                            }
                        }
                        return;
                    }
                }
                ᵺᵣᵬ.ᵡˎ(this, interfaceC4943, z);
                return;
            }
        } while (!atomicIntegerFieldUpdater.compareAndSet(this, i2, 1073741824 + (536870911 & i2)));
    }

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final boolean m9400(Throwable th) throws DispatchException {
        Throwable cancellationException;
        C4385 c4385;
        while (true) {
            f16428.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            long j = f16429;
            Object objectVolatile = unsafe.getObjectVolatile(this, j);
            if (!(objectVolatile instanceof InterfaceC5554)) {
                return false;
            }
            boolean z = (objectVolatile instanceof InterfaceC1868) || (objectVolatile instanceof AbstractC2858);
            if (th == null) {
                cancellationException = new CancellationException("Continuation " + this + " was cancelled normally");
            } else {
                cancellationException = th;
            }
            C3412 c3412 = new C3412(cancellationException, z);
            while (true) {
                Unsafe unsafe2 = AbstractC3747.f13986;
                c4385 = this;
                if (unsafe2.compareAndSwapObject(c4385, f16429, objectVolatile, c3412)) {
                    InterfaceC5554 interfaceC5554 = (InterfaceC5554) objectVolatile;
                    if (interfaceC5554 instanceof InterfaceC1868) {
                        c4385.m9411((InterfaceC1868) objectVolatile, th);
                    } else if (interfaceC5554 instanceof AbstractC2858) {
                        c4385.m9395((AbstractC2858) objectVolatile, th);
                    }
                    if (!c4385.m9394()) {
                        c4385.m9410();
                    }
                    c4385.m9399(c4385.f18326);
                    return true;
                }
                if (unsafe2.getObjectVolatile(c4385, j) != objectVolatile) {
                    break;
                }
                this = c4385;
            }
            this = c4385;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:60:0x00c5, code lost:
    
        m9393(r11, r7);
     */
    /* JADX WARN: Code restructure failed: missing block: B:61:0x00c8, code lost:
    
        throw null;
     */
    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void m9401(defpackage.InterfaceC5554 r11) {
        /*
            Method dump skipped, instructions count: 201
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C4385.m9401(ﹳˈ):void");
    }

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final Object m9402() {
        f16428.getClass();
        return AbstractC3747.f13986.getObjectVolatile(this, f16429);
    }

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final void m9403(InterfaceC0362 interfaceC0362) {
        m9401(new C3033(1, interfaceC0362));
    }

    @Override // defpackage.InterfaceC5233
    /* renamed from: ᵥᵯˎ */
    public final void mo2137(AbstractC2858 abstractC2858, int i) {
        AtomicIntegerFieldUpdater atomicIntegerFieldUpdater;
        int i2;
        do {
            atomicIntegerFieldUpdater = f16432;
            i2 = atomicIntegerFieldUpdater.get(this);
            if ((i2 & 536870911) != 536870911) {
                ᵹˉᵞ.ᵳٴᵶ("invokeOnCancellation should be called at most once");
                return;
            }
        } while (!atomicIntegerFieldUpdater.compareAndSet(this, i2, ((i2 >> 29) << 29) + i));
        m9401(abstractC2858);
    }

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public final void m9404(Object obj, int i, InterfaceC2634 interfaceC2634) throws DispatchException {
        C4385 c4385;
        while (true) {
            f16428.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            long j = f16429;
            Object objectVolatile = unsafe.getObjectVolatile(this, j);
            if (!(objectVolatile instanceof InterfaceC5554)) {
                C4385 c43852 = this;
                if (objectVolatile instanceof C3412) {
                    C3412 c3412 = (C3412) objectVolatile;
                    if (C3412.f12705.compareAndSet(c3412, 0, 1)) {
                        if (interfaceC2634 != null) {
                            c43852.m9407(interfaceC2634, c3412.f5777, obj);
                            return;
                        }
                        return;
                    }
                }
                C4069.m8939(obj, "Already resumed, but proposed with update ");
                return;
            }
            Object objM9392 = m9392((InterfaceC5554) objectVolatile, obj, i, interfaceC2634);
            while (true) {
                Unsafe unsafe2 = AbstractC3747.f13986;
                c4385 = this;
                if (unsafe2.compareAndSwapObject(c4385, f16429, objectVolatile, objM9392)) {
                    if (!c4385.m9394()) {
                        c4385.m9410();
                    }
                    c4385.m9399(i);
                    return;
                } else if (unsafe2.getObjectVolatile(c4385, j) != objectVolatile) {
                    break;
                } else {
                    this = c4385;
                }
            }
            this = c4385;
        }
    }

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final Object m9405() {
        AtomicIntegerFieldUpdater atomicIntegerFieldUpdater;
        int i;
        InterfaceC3506 interfaceC3506;
        boolean zM9394 = m9394();
        do {
            atomicIntegerFieldUpdater = f16432;
            i = atomicIntegerFieldUpdater.get(this);
            int i2 = i >> 29;
            if (i2 != 0) {
                if (i2 != 2) {
                    ᵹˉᵞ.ᵳٴᵶ("Already suspended");
                    return null;
                }
                if (zM9394) {
                    m9396();
                }
                Object objM9402 = m9402();
                if (objM9402 instanceof C1411) {
                    throw ((C1411) objM9402).f5777;
                }
                int i3 = this.f18326;
                if ((i3 != 1 && i3 != 2) || (interfaceC3506 = (InterfaceC3506) this.f16433.mo1764(ʾᵠᵦ.ᵾᵬ)) == null || interfaceC3506.mo2236()) {
                    return mo9412(objM9402);
                }
                CancellationException cancellationExceptionMo2238 = interfaceC3506.mo2238();
                mo9408(cancellationExceptionMo2238);
                throw cancellationExceptionMo2238;
            }
        } while (!atomicIntegerFieldUpdater.compareAndSet(this, i, 536870912 + (536870911 & i)));
        if (m9398() == null) {
            m9414();
        }
        if (zM9394) {
            m9396();
        }
        return EnumC3346.f12524;
    }

    /* renamed from: ᵨᵳʝ */
    public Throwable mo4888(C0577 c0577) {
        return c0577.mo2238();
    }

    @Override // defpackage.InterfaceC0719
    /* renamed from: ᵪʩ */
    public final void mo2138(Object obj, InterfaceC2634 interfaceC2634) throws DispatchException {
        m9404(obj, this.f18326, interfaceC2634);
    }

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public final boolean m9406() {
        f16428.getClass();
        Unsafe unsafe = AbstractC3747.f13986;
        long j = f16429;
        Object objectVolatile = unsafe.getObjectVolatile(this, j);
        if ((objectVolatile instanceof C0703) && ((C0703) objectVolatile).f3419 != null) {
            m9410();
            return false;
        }
        f16432.set(this, 536870911);
        unsafe.putObjectVolatile(this, j, C4102.f15331);
        return true;
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final void m9407(InterfaceC2634 interfaceC2634, Throwable th, Object obj) {
        InterfaceC2262 interfaceC2262 = this.f16433;
        try {
            interfaceC2634.mo1884(th, obj, interfaceC2262);
        } catch (Throwable th2) {
            ᵭʝʜ.ᵸʓᵠ(interfaceC2262, new CompletionHandlerException("Exception in resume onCancellation handler for " + this, th2));
        }
    }

    @Override // defpackage.InterfaceC0719
    /* renamed from: ᵳٴᵶ */
    public final void mo2139(Object obj) throws DispatchException {
        m9399(this.f18326);
    }

    @Override // defpackage.AbstractC4927
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void mo9408(CancellationException cancellationException) {
        CancellationException cancellationException2;
        C4385 c4385;
        while (true) {
            f16428.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            long j = f16429;
            Object objectVolatile = unsafe.getObjectVolatile(this, j);
            if (objectVolatile instanceof InterfaceC5554) {
                ᵹˉᵞ.ᵳٴᵶ("Not completed");
                return;
            }
            if (objectVolatile instanceof C1411) {
                return;
            }
            if (objectVolatile instanceof C0703) {
                C0703 c0703 = (C0703) objectVolatile;
                if (c0703.f3415 != null) {
                    ᵹˉᵞ.ᵳٴᵶ("Must be called at most once");
                    return;
                }
                C0703 c0703M2701 = C0703.m2701(c0703, null, cancellationException, 15);
                while (true) {
                    Unsafe unsafe2 = AbstractC3747.f13986;
                    C4385 c43852 = this;
                    if (unsafe2.compareAndSwapObject(c43852, f16429, objectVolatile, c0703M2701)) {
                        InterfaceC1868 interfaceC1868 = c0703.f3418;
                        if (interfaceC1868 != null) {
                            c43852.m9411(interfaceC1868, cancellationException);
                        }
                        InterfaceC2634 interfaceC2634 = c0703.f3416;
                        if (interfaceC2634 != null) {
                            c43852.m9407(interfaceC2634, cancellationException, c0703.f3417);
                            return;
                        }
                        return;
                    }
                    if (unsafe2.getObjectVolatile(c43852, j) != objectVolatile) {
                        cancellationException2 = cancellationException;
                        c4385 = c43852;
                        break;
                    }
                    this = c43852;
                }
            } else {
                C4385 c43853 = this;
                CancellationException cancellationException3 = cancellationException;
                C0703 c07032 = new C0703(objectVolatile, (InterfaceC1868) null, (InterfaceC2634) null, cancellationException3, 14);
                cancellationException2 = cancellationException3;
                while (true) {
                    C0703 c07033 = c07032;
                    Unsafe unsafe3 = AbstractC3747.f13986;
                    c4385 = c43853;
                    boolean zCompareAndSwapObject = unsafe3.compareAndSwapObject(c4385, f16429, objectVolatile, c07033);
                    c07032 = c07033;
                    if (zCompareAndSwapObject) {
                        return;
                    }
                    if (unsafe3.getObjectVolatile(c4385, j) != objectVolatile) {
                        break;
                    } else {
                        c43853 = c4385;
                    }
                }
            }
            cancellationException = cancellationException2;
            this = c4385;
        }
    }

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public final C0434 m9409(Object obj, InterfaceC2634 interfaceC2634) {
        C4385 c4385;
        while (true) {
            f16428.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            long j = f16429;
            Object objectVolatile = unsafe.getObjectVolatile(this, j);
            if (!(objectVolatile instanceof InterfaceC5554)) {
                return null;
            }
            Object objM9392 = m9392((InterfaceC5554) objectVolatile, obj, this.f18326, interfaceC2634);
            while (true) {
                Unsafe unsafe2 = AbstractC3747.f13986;
                c4385 = this;
                if (unsafe2.compareAndSwapObject(c4385, f16429, objectVolatile, objM9392)) {
                    boolean zM9394 = c4385.m9394();
                    C0434 c0434 = AbstractC1038.f4512;
                    if (!zM9394) {
                        c4385.m9410();
                    }
                    return c0434;
                }
                if (unsafe2.getObjectVolatile(c4385, j) != objectVolatile) {
                    break;
                }
                this = c4385;
            }
            this = c4385;
        }
    }

    @Override // defpackage.AbstractC4927
    /* renamed from: ᵶᵷᵕ */
    public final Object mo7014() {
        return m9402();
    }

    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final void m9410() {
        InterfaceC3451 interfaceC3451M9398 = m9398();
        if (interfaceC3451M9398 == null) {
            return;
        }
        interfaceC3451M9398.mo1618();
        f16431.getClass();
        AbstractC3747.f13986.putObjectVolatile(this, f16430, C0281.f1879);
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void m9411(InterfaceC1868 interfaceC1868, Throwable th) {
        try {
            interfaceC1868.mo5274(th);
        } catch (Throwable th2) {
            ᵭʝʜ.ᵸʓᵠ(this.f16433, new CompletionHandlerException("Exception in invokeOnCancellation handler for " + this, th2));
        }
    }

    @Override // defpackage.AbstractC4927
    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final Object mo9412(Object obj) {
        return obj instanceof C0703 ? ((C0703) obj).f3417 : obj;
    }

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public final void m9413(AbstractC2687 abstractC2687) {
        InterfaceC4943 interfaceC4943 = this.f16434;
        C2869 c2869 = interfaceC4943 instanceof C2869 ? (C2869) interfaceC4943 : null;
        m9404(C3637.f13536, (c2869 != null ? c2869.f11121 : null) == abstractC2687 ? 4 : this.f18326, null);
    }

    @Override // defpackage.InterfaceC0571
    /* renamed from: ᵻᵢﹳᵰ */
    public final InterfaceC0571 mo2414() {
        InterfaceC4943 interfaceC4943 = this.f16434;
        if (interfaceC4943 instanceof InterfaceC0571) {
            return (InterfaceC0571) interfaceC4943;
        }
        return null;
    }

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final InterfaceC3451 m9414() {
        InterfaceC3506 interfaceC3506 = (InterfaceC3506) this.f16433.mo1764(ʾᵠᵦ.ᵾᵬ);
        if (interfaceC3506 == null) {
            return null;
        }
        InterfaceC3451 interfaceC3451 = ᵭʝʜ.ˑᵱ(interfaceC3506, true, new C5042(this));
        while (true) {
            f16431.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            long j = f16430;
            C4385 c4385 = this;
            if (unsafe.compareAndSwapObject(c4385, j, (Object) null, interfaceC3451) || unsafe.getObjectVolatile(c4385, j) != null) {
                break;
            }
            this = c4385;
        }
        return interfaceC3451;
    }

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final void m9415() {
        InterfaceC3451 interfaceC3451M9414 = m9414();
        if (interfaceC3451M9414 == null || (m9402() instanceof InterfaceC5554)) {
            return;
        }
        interfaceC3451M9414.mo1618();
        f16431.getClass();
        AbstractC3747.f13986.putObjectVolatile(this, f16430, C0281.f1879);
    }
}
