package p025.p026.p029;

import java.util.ArrayList;
import java.util.concurrent.CancellationException;
import kotlin.TypeCastException;
import p025.p026.AbstractC1304;
import p025.p026.C1302;
import p025.p026.C1307;
import p025.p026.C1308;
import p025.p026.C1319;
import p025.p026.C1336;
import p025.p026.C1337;
import p025.p026.InterfaceC1306;
import p025.p026.p027.C1281;
import p025.p026.p027.C1282;
import p025.p026.p027.C1283;
import p025.p026.p027.C1284;
import p025.p026.p027.C1295;
import p025.p026.p027.C1296;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.C6542;
import p402.C6549;
import p402.InterfaceC6540;
import p402.p405.InterfaceC6575;
import p402.p405.p406.EnumC6586;
import p402.p411.p412.InterfaceC6614;
import p402.p411.p413.C6649;

/* JADX INFO: renamed from: އ.֏.ၷ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public abstract class AbstractC1398<E> extends AbstractC1404<E> implements InterfaceC1407<E> {

    /* JADX INFO: renamed from: އ.֏.ၷ.֏$֏, reason: contains not printable characters */
    public static final class C1399<E> implements InterfaceC1410<E> {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public Object f4558 = C1403.f4567;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final AbstractC1398<E> f4559;

        public C1399(AbstractC1398<E> abstractC1398) {
            this.f4559 = abstractC1398;
        }

        /* JADX WARN: Multi-variable type inference failed */
        @Override // p025.p026.p029.InterfaceC1410
        public E next() throws Throwable {
            E e = (E) this.f4558;
            if (e instanceof C1411) {
                Throwable thM2750 = ((C1411) e).m2750();
                C1295.m2593(thM2750);
                throw thM2750;
            }
            Object obj = C1403.f4567;
            if (e == obj) {
                throw new IllegalStateException("'hasNext' should be called prior to 'next' invocation");
            }
            this.f4558 = obj;
            return e;
        }

        /* JADX WARN: Removed duplicated region for block: B:33:0x006f  */
        @Override // p025.p026.p029.InterfaceC1410
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public Object mo2737(InterfaceC6575<? super Boolean> interfaceC6575) {
            C1307 c1307;
            C1307 c13072;
            boolean z;
            Object obj = this.f4558;
            if (obj != C1403.f4567) {
                return Boolean.valueOf(m2738(obj));
            }
            Object objMo2736 = this.f4559.mo2736();
            this.f4558 = objMo2736;
            if (objMo2736 != C1403.f4567) {
                return Boolean.valueOf(m2738(objMo2736));
            }
            InterfaceC6575 interfaceC6575M7066 = C4303.m7066((InterfaceC6575) interfaceC6575);
            if (interfaceC6575M7066 instanceof C1336) {
                C1336 c1336 = (C1336) interfaceC6575M7066;
                while (true) {
                    Object obj2 = c1336._reusableCancellableContinuation;
                    if (obj2 == null) {
                        c1336._reusableCancellableContinuation = C1337.f4484;
                        c1307 = null;
                        break;
                    }
                    if (!(obj2 instanceof C1307)) {
                        throw new IllegalStateException(("Inconsistent state " + obj2).toString());
                    }
                    if (C1336.f4477.compareAndSet(c1336, obj2, C1337.f4484)) {
                        c1307 = (C1307) obj2;
                        break;
                    }
                }
                if (c1307 == null) {
                    c13072 = new C1307(interfaceC6575M7066, 0);
                } else {
                    if (c1307._state instanceof C1319) {
                        c1307.m2634();
                        z = false;
                    } else {
                        c1307._decision = 0;
                        c1307._state = C1302.f4441;
                        z = true;
                    }
                    c13072 = z ? c1307 : null;
                    if (c13072 == null) {
                    }
                }
            } else {
                c13072 = new C1307(interfaceC6575M7066, 0);
            }
            C1307 c13073 = c13072;
            C1400 c1400 = new C1400(this, c13073);
            while (true) {
                if (this.f4559.mo2732((AbstractC1415) c1400)) {
                    AbstractC1398<E> abstractC1398 = this.f4559;
                    if (abstractC1398 == null) {
                        throw null;
                    }
                    c13073.mo2624((InterfaceC6614<? super Throwable, C6549>) abstractC1398.new C1401(c1400));
                } else {
                    Object objMo27362 = this.f4559.mo2736();
                    this.f4558 = objMo27362;
                    if (objMo27362 instanceof C1411) {
                        C1411 c1411 = (C1411) objMo27362;
                        if (c1411.f4575 == null) {
                            C6542.C6543 c6543 = C6542.f19318;
                            c13073.mo2608((Object) false);
                        } else {
                            Throwable thM2750 = c1411.m2750();
                            C6542.C6543 c65432 = C6542.f19318;
                            c13073.mo2608(C4303.m7010(thM2750));
                        }
                    } else if (objMo27362 != C1403.f4567) {
                        C6542.C6543 c65433 = C6542.f19318;
                        c13073.mo2608((Object) true);
                        break;
                    }
                }
            }
            Object objM2636 = c13073.m2636();
            EnumC6586 enumC6586 = EnumC6586.COROUTINE_SUSPENDED;
            return objM2636;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final boolean m2738(Object obj) throws Throwable {
            if (!(obj instanceof C1411)) {
                return true;
            }
            C1411 c1411 = (C1411) obj;
            if (c1411.f4575 == null) {
                return false;
            }
            Throwable thM2750 = c1411.m2750();
            C1295.m2593(thM2750);
            throw thM2750;
        }
    }

    /* JADX INFO: renamed from: އ.֏.ၷ.֏$ؠ, reason: contains not printable characters */
    public static final class C1400<E> extends AbstractC1415<E> {

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public final C1399<E> f4560;

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public final InterfaceC1306<Boolean> f4561;

        /* JADX WARN: Multi-variable type inference failed */
        public C1400(C1399<E> c1399, InterfaceC1306<? super Boolean> interfaceC1306) {
            this.f4560 = c1399;
            this.f4561 = interfaceC1306;
        }

        @Override // p025.p026.p027.C1284
        public String toString() {
            StringBuilder sbM4889 = C2803.m4889("ReceiveHasNext@");
            sbM4889.append(C4303.m7180(this));
            return sbM4889.toString();
        }

        @Override // p025.p026.p029.InterfaceC1417
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public C1296 mo2739(E e, C1284.C1286 c1286) {
            InterfaceC1306<Boolean> interfaceC1306 = this.f4561;
            if (c1286 != null) {
                throw null;
            }
            if (interfaceC1306.mo2620(true, (Object) null) == null) {
                return null;
            }
            if (c1286 == null) {
                return C1308.f4447;
            }
            throw null;
        }

        @Override // p025.p026.p029.InterfaceC1417
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo2740(E e) {
            this.f4560.f4558 = e;
            this.f4561.mo2625(C1308.f4447);
        }

        @Override // p025.p026.p029.AbstractC1415
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo2741(C1411<?> c1411) {
            Object objMo2620 = c1411.f4575 == null ? this.f4561.mo2620(false, (Object) null) : this.f4561.mo2623(c1411.m2750());
            if (objMo2620 != null) {
                this.f4560.f4558 = c1411;
                this.f4561.mo2625(objMo2620);
            }
        }
    }

    /* JADX INFO: renamed from: އ.֏.ၷ.֏$ހ, reason: contains not printable characters */
    public final class C1401 extends AbstractC1304 {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final AbstractC1415<?> f4562;

        public C1401(AbstractC1415<?> abstractC1415) {
            this.f4562 = abstractC1415;
        }

        public String toString() {
            StringBuilder sbM4889 = C2803.m4889("RemoveReceiveOnCancel[");
            sbM4889.append(this.f4562);
            sbM4889.append(']');
            return sbM4889.toString();
        }

        @Override // p025.p026.AbstractC1305
        /* JADX INFO: renamed from: ֏ */
        public void mo2619(Throwable th) {
            if (this.f4562.mo2569() && AbstractC1398.this == null) {
                throw null;
            }
        }

        @Override // p402.p411.p412.InterfaceC6614
        /* JADX INFO: renamed from: ؠ */
        public C6549 mo1606(Throwable th) {
            if (this.f4562.mo2569() && AbstractC1398.this == null) {
                throw null;
            }
            return C6549.f19328;
        }
    }

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C1402(C1284 c1284, C1284 c12842, AbstractC1398 abstractC1398) {
            super(c12842);
            this.f4564 = abstractC1398;
        }

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

    @Override // p025.p026.p029.InterfaceC1416
    public final InterfaceC1410<E> iterator() {
        return new C1399(this);
    }

    @Override // p025.p026.p029.InterfaceC1416
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void mo2730(CancellationException cancellationException) {
        boolean z;
        Object obj;
        Object obj2;
        if (cancellationException == null) {
            cancellationException = new CancellationException(getClass().getSimpleName() + " was cancelled");
        }
        C1411<?> c1411 = new C1411<>(cancellationException);
        C1284 c1284 = this.f4570;
        while (true) {
            C1284 c1284M2577 = c1284.m2577();
            if (!(!(c1284M2577 instanceof C1411))) {
                z = false;
                break;
            } else if (c1284M2577.m2574(c1411, c1284)) {
                z = true;
                break;
            }
        }
        if (!z) {
            C1284 c1284M25772 = this.f4570.m2577();
            if (c1284M25772 == null) {
                throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.channels.Closed<*>");
            }
            c1411 = (C1411) c1284M25772;
        }
        m2744(c1411);
        if (z && (obj = this.onCloseHandler) != null && obj != (obj2 = C1403.f4568) && AbstractC1404.f4569.compareAndSet(this, obj, obj2)) {
            C6649.m9833(obj, 1);
            ((InterfaceC6614) obj).mo1606(cancellationException);
        }
        mo2731(z);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo2731(boolean z) {
        C1411<?> c1411M2745 = m2745();
        if (c1411M2745 == null) {
            throw new IllegalStateException("Cannot happen".toString());
        }
        Object objM2567 = null;
        while (true) {
            C1284 c1284M2577 = c1411M2745.m2577();
            if (c1284M2577 instanceof C1282) {
                break;
            } else if (c1284M2577.mo2569()) {
                objM2567 = C1281.m2567(objM2567, (AbstractC1418) c1284M2577);
            } else {
                c1284M2577.m2578();
            }
        }
        if (objM2567 == null) {
            return;
        }
        if (!(objM2567 instanceof ArrayList)) {
            ((AbstractC1418) objM2567).mo2749(c1411M2745);
            return;
        }
        ArrayList arrayList = (ArrayList) objM2567;
        int size = arrayList.size();
        while (true) {
            size--;
            if (size < 0) {
                return;
            } else {
                ((AbstractC1418) arrayList.get(size)).mo2749(c1411M2745);
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public boolean mo2732(AbstractC1415<? super E> abstractC1415) {
        int iM2571;
        C1284 c1284M2577;
        if (!mo2734()) {
            C1284 c1284 = this.f4570;
            C1402 c1402 = new C1402(abstractC1415, abstractC1415, this);
            do {
                C1284 c1284M25772 = c1284.m2577();
                if (!(!(c1284M25772 instanceof AbstractC1418))) {
                    break;
                }
                iM2571 = c1284M25772.m2571(abstractC1415, c1284, c1402);
                if (iM2571 == 1) {
                    return true;
                }
            } while (iM2571 != 2);
        } else {
            C1284 c12842 = this.f4570;
            do {
                c1284M2577 = c12842.m2577();
                if (!(!(c1284M2577 instanceof AbstractC1418))) {
                }
            } while (!c1284M2577.m2574(abstractC1415, c12842));
            return true;
        }
        return false;
    }

    @Override // p025.p026.p029.AbstractC1404
    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public InterfaceC1417<E> mo2733() {
        InterfaceC1417<E> interfaceC1417Mo2733 = super.mo2733();
        if (interfaceC1417Mo2733 != null) {
            boolean z = interfaceC1417Mo2733 instanceof C1411;
        }
        return interfaceC1417Mo2733;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public abstract boolean mo2734();

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public abstract boolean mo2735();

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public abstract Object mo2736();
}
