package defpackage;

import androidx.media3.container.NalUnitUtil;
import defpackage.uv0;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0010\u0018\u0000*\u0004\b\u0000\u0010\u00012\b\u0012\u0004\u0012\u00028\u00000\u0002¨\u0006\u0003"}, d2 = {"Lac1;", "E", "Lzg0;", "kotlinx-coroutines-core"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public class ac1<E> extends zg0<E> {
    public final ug0 m;

    public ac1(int i, ug0 ug0Var) {
        super(i);
        this.m = ug0Var;
        if (ug0Var != ug0.a) {
            if (i < 1) {
                throw new IllegalArgumentException(n41.i(i, "Buffered channel capacity must be at least 1, but ", " was specified").toString());
            }
        } else {
            throw new IllegalArgumentException(("This implementation does not support suspension for senders, use " + iw7.a.getOrCreateKotlinClass(zg0.class).getSimpleName() + " instead").toString());
        }
    }

    @Override // defpackage.zg0
    public final boolean ad() {
        return this.m == ug0.b;
    }

    @Override // defpackage.zg0
    public final void ak(lf8 lf8Var, Object obj) {
        Object objAs = as(obj, false);
        if (!(objAs instanceof uv0.c)) {
            lf8Var.c(e6a.a);
        } else {
            if (!(objAs instanceof uv0.a)) {
                throw new IllegalStateException("unreachable");
            }
            lf8Var.c(ph0.l);
        }
    }

    @Override // defpackage.zg0
    public final Object am(Continuation continuation) {
        Object objAs = as(null, true);
        if (objAs instanceof uv0.c) {
            return Boxing.boxBoolean(false);
        }
        return Boxing.boxBoolean(true);
    }

    /* JADX WARN: Code restructure failed: missing block: B:51:0x00b6, code lost:
    
        return r8;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object as(Object obj, boolean z) {
        ug0 ug0Var = this.m;
        ug0 ug0Var2 = ug0.c;
        e6a e6aVar = e6a.a;
        if (ug0Var == ug0Var2) {
            Object objI = super.i(obj);
            return (!(objI instanceof uv0.c) || (objI instanceof uv0.a)) ? objI : e6aVar;
        }
        Object obj2 = ph0.d;
        vv0 vv0Var = (vv0) zg0.f.get(this);
        while (true) {
            long andIncrement = zg0.b.getAndIncrement(this);
            long j = 1152921504606846975L & andIncrement;
            boolean zAb = ab(andIncrement, false);
            int i = ph0.b;
            long j2 = i;
            long j3 = j / j2;
            int i2 = (int) (j % j2);
            if (vv0Var.c != j3) {
                vv0 vv0VarB = zg0.b(this, j3, vv0Var);
                if (vv0VarB != null) {
                    vv0Var = vv0VarB;
                } else if (zAb) {
                    return new uv0.a(y());
                }
            }
            int iF = zg0.f(this, vv0Var, i2, obj, j, obj2, zAb);
            if (iF == 0) {
                vv0Var.a();
                return e6aVar;
            }
            if (iF == 1) {
                break;
            }
            if (iF != 2) {
                if (iF == 3) {
                    throw new IllegalStateException("unexpected");
                }
                if (iF == 4) {
                    if (j < zg0.c.get(this)) {
                        vv0Var.a();
                    }
                    return new uv0.a(y());
                }
                if (iF == 5) {
                    vv0Var.a();
                }
            } else {
                if (zAb) {
                    vv0Var.i();
                    return new uv0.a(y());
                }
                bna bnaVar = obj2 instanceof bna ? (bna) obj2 : null;
                if (bnaVar != null) {
                    bnaVar.a(vv0Var, i2 + i);
                }
                p((vv0Var.c * j2) + ((long) i2));
            }
        }
    }

    @Override // defpackage.zg0, defpackage.hg8
    public final Object i(Object obj) {
        return as(obj, false);
    }

    @Override // defpackage.zg0, defpackage.hg8
    public final Object s(Object obj, Continuation continuation) throws Throwable {
        if (as(obj, true) instanceof uv0.a) {
            throw y();
        }
        return e6a.a;
    }
}
