package p025.p026.p029;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.TypeCastException;
import kotlinx.coroutines.channels.ClosedSendChannelException;
import p025.p026.p027.C1281;
import p025.p026.p027.C1282;
import p025.p026.p027.C1284;
import p025.p026.p027.C1295;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.p411.p413.C6635;

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

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final AtomicReferenceFieldUpdater f4569 = AtomicReferenceFieldUpdater.newUpdater(AbstractC1404.class, Object.class, "onCloseHandler");

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C1282 f4570 = new C1282();
    public volatile Object onCloseHandler = null;

    @Override // p025.p026.p029.InterfaceC1419
    public final boolean offer(E e) throws Throwable {
        Object objMo2742 = mo2742(e);
        if (objMo2742 == C1403.f4565) {
            return true;
        }
        if (objMo2742 == C1403.f4566) {
            C1411<?> c1411M2745 = m2745();
            if (c1411M2745 == null) {
                return false;
            }
            m2744(c1411M2745);
            Throwable closedSendChannelException = c1411M2745.f4575;
            if (closedSendChannelException == null) {
                closedSendChannelException = new ClosedSendChannelException("Channel was closed");
            }
            C1295.m2593(closedSendChannelException);
            throw closedSendChannelException;
        }
        if (!(objMo2742 instanceof C1411)) {
            throw new IllegalStateException(("offerInternal returned " + objMo2742).toString());
        }
        C1411<?> c1411 = (C1411) objMo2742;
        m2744(c1411);
        Throwable closedSendChannelException2 = c1411.f4575;
        if (closedSendChannelException2 == null) {
            closedSendChannelException2 = new ClosedSendChannelException("Channel was closed");
        }
        C1295.m2593(closedSendChannelException2);
        throw closedSendChannelException2;
    }

    public String toString() {
        String string;
        String string2;
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append('@');
        sb.append(C4303.m7180(this));
        sb.append('{');
        C1284 c1284M2576 = this.f4570.m2576();
        if (c1284M2576 == this.f4570) {
            string2 = "EmptyQueue";
        } else {
            if (c1284M2576 instanceof C1411) {
                string = c1284M2576.toString();
            } else if (c1284M2576 instanceof AbstractC1415) {
                string = "ReceiveQueued";
            } else if (c1284M2576 instanceof AbstractC1418) {
                string = "SendQueued";
            } else {
                string = "UNEXPECTED:" + c1284M2576;
            }
            C1284 c1284M2577 = this.f4570.m2577();
            if (c1284M2577 != c1284M2576) {
                StringBuilder sbM4897 = C2803.m4897(string, ",queueSize=");
                Object objM2575 = this.f4570.m2575();
                if (objM2575 == null) {
                    throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.internal.Node /* = kotlinx.coroutines.internal.LockFreeLinkedListNode */");
                }
                int i = 0;
                for (C1284 c1284M25762 = (C1284) objM2575; !C6635.m9825(c1284M25762, r2); c1284M25762 = c1284M25762.m2576()) {
                    if (c1284M25762 instanceof C1284) {
                        i++;
                    }
                }
                sbM4897.append(i);
                string2 = sbM4897.toString();
                if (c1284M2577 instanceof C1411) {
                    string2 = string2 + ",closedForSend=" + c1284M2577;
                }
            } else {
                string2 = string;
            }
        }
        sb.append(string2);
        sb.append('}');
        sb.append(mo2743());
        return sb.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public Object mo2742(E e) {
        InterfaceC1417<E> interfaceC1417Mo2733;
        do {
            interfaceC1417Mo2733 = mo2733();
            if (interfaceC1417Mo2733 == null) {
                return C1403.f4566;
            }
        } while (interfaceC1417Mo2733.mo2739(e, null) == null);
        interfaceC1417Mo2733.mo2740(e);
        return interfaceC1417Mo2733.mo2748();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public String mo2743() {
        return "";
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m2744(C1411<?> c1411) {
        Object objM2567 = null;
        while (true) {
            C1284 c1284M2577 = c1411.m2577();
            if (!(c1284M2577 instanceof AbstractC1415)) {
                c1284M2577 = null;
            }
            AbstractC1415 abstractC1415 = (AbstractC1415) c1284M2577;
            if (abstractC1415 == null) {
                break;
            } else if (abstractC1415.mo2569()) {
                objM2567 = C1281.m2567(objM2567, abstractC1415);
            } else {
                abstractC1415.m2578();
            }
        }
        if (objM2567 == null) {
            return;
        }
        if (!(objM2567 instanceof ArrayList)) {
            ((AbstractC1415) objM2567).mo2741(c1411);
            return;
        }
        ArrayList arrayList = (ArrayList) objM2567;
        int size = arrayList.size();
        while (true) {
            size--;
            if (size < 0) {
                return;
            } else {
                ((AbstractC1415) arrayList.get(size)).mo2741(c1411);
            }
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C1411<?> m2745() {
        C1284 c1284M2577 = this.f4570.m2577();
        if (!(c1284M2577 instanceof C1411)) {
            c1284M2577 = null;
        }
        C1411<?> c1411 = (C1411) c1284M2577;
        if (c1411 == null) {
            return null;
        }
        m2744(c1411);
        return c1411;
    }

    /* JADX WARN: Code restructure failed: missing block: B:7:0x000d, code lost:
    
        r1 = 0;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v2, types: [އ.֏.֏.ކ] */
    /* JADX WARN: Type inference failed for: r1v3 */
    /* JADX WARN: Type inference failed for: r1v4 */
    /* JADX INFO: renamed from: ހ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public InterfaceC1417<E> mo2733() {
        ?? r1;
        C1284 c1284M2580;
        C1282 c1282 = this.f4570;
        while (true) {
            Object objM2575 = c1282.m2575();
            if (objM2575 == null) {
                throw new TypeCastException("null cannot be cast to non-null type kotlinx.coroutines.internal.Node /* = kotlinx.coroutines.internal.LockFreeLinkedListNode */");
            }
            r1 = (C1284) objM2575;
            if (r1 == c1282 || !(r1 instanceof InterfaceC1417)) {
                break;
            }
            if (((((InterfaceC1417) r1) instanceof C1411) && !r1.mo2568()) || (c1284M2580 = r1.m2580()) == null) {
                break;
            }
            c1284M2580.m2579();
        }
        return (InterfaceC1417) r1;
    }
}
