package defpackage;

import androidx.media3.container.NalUnitUtil;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@DebugMetadata(c = "io.ktor.utils.io.ByteReadChannelOperationsKt", f = "ByteReadChannelOperations.kt", i = {0, 0, 0, 1, 1, 1, 2}, l = {114, 115, 124, 124}, m = "copyAndClose", n = {"$this$copyAndClose", "channel", "result", "$this$copyAndClose", "channel", "result", "result"}, s = {"L$0", "L$1", "J$0", "L$0", "L$1", "J$0", "J$0"})
final class en0 extends ContinuationImpl {
    public Object a;
    public gp0 b;
    public long c;
    public /* synthetic */ Object d;
    public int e;

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0060 A[Catch: all -> 0x008b, TryCatch #2 {all -> 0x008b, blocks: (B:21:0x005a, B:23:0x0060, B:26:0x007c, B:31:0x0091, B:39:0x00ac), top: B:51:0x005a }] */
    /* JADX WARN: Removed duplicated region for block: B:28:0x008a  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x0091 A[Catch: all -> 0x008b, TRY_LEAVE, TryCatch #2 {all -> 0x008b, blocks: (B:21:0x005a, B:23:0x0060, B:26:0x007c, B:31:0x0091, B:39:0x00ac), top: B:51:0x005a }] */
    /* JADX WARN: Type inference failed for: r0v2, types: [int] */
    /* JADX WARN: Type inference failed for: r4v1 */
    /* JADX WARN: Type inference failed for: r4v2, types: [gp0] */
    /* JADX WARN: Type inference failed for: r4v4 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:27:0x0088 -> B:51:0x005a). Please report as a decompilation issue!!! */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        ?? r4;
        en0 en0Var;
        long jY;
        gp0 gp0Var;
        bn0 bn0Var;
        en0 en0Var2;
        long j;
        this.d = obj;
        ?? r0 = (this.e | Integer.MIN_VALUE) - Integer.MIN_VALUE;
        this.e = r0;
        ck1 ck1Var = ck1.a;
        try {
            if (r0 != 0) {
                try {
                    if (r0 == 1) {
                        jY = this.c;
                        gp0Var = this.b;
                        bn0Var = (bn0) this.a;
                        s38.b(obj);
                        en0Var2 = this;
                        en0Var2.a = bn0Var;
                        en0Var2.b = gp0Var;
                        en0Var2.c = jY;
                        en0Var2.e = 2;
                        if (bn0Var.h(1, en0Var2) != ck1Var) {
                        }
                        return ck1Var;
                    }
                    if (r0 != 2) {
                        if (r0 == 3) {
                            j = this.c;
                            s38.b(obj);
                            return Boxing.boxLong(j);
                        }
                        if (r0 != 4) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        Throwable th = (Throwable) this.a;
                        s38.b(obj);
                        throw th;
                    }
                    jY = this.c;
                    gp0Var = this.b;
                    bn0Var = (bn0) this.a;
                    s38.b(obj);
                    en0Var2 = this;
                } catch (Throwable th2) {
                    th = th2;
                    r4 = r0;
                    en0Var = this;
                    try {
                        bn0Var.c(th);
                        kp0.a(r4, th);
                        throw th;
                    } catch (Throwable th3) {
                        en0Var.a = th3;
                        en0Var.b = null;
                        en0Var.e = 4;
                        if (r4.d(en0Var) != ck1Var) {
                            throw th3;
                        }
                    }
                }
            } else {
                s38.b(obj);
                jY = 0;
                en0Var2 = this;
                gp0Var = null;
                bn0Var = null;
            }
            if (bn0Var.i()) {
                jY += bn0Var.g().y(gp0Var.f());
                en0Var2.a = bn0Var;
                en0Var2.b = gp0Var;
                en0Var2.c = jY;
                en0Var2.e = 1;
                if (gp0Var.b(en0Var2) != ck1Var) {
                    en0Var2.a = bn0Var;
                    en0Var2.b = gp0Var;
                    en0Var2.c = jY;
                    en0Var2.e = 2;
                    if (bn0Var.h(1, en0Var2) != ck1Var) {
                        if (bn0Var.i()) {
                            Throwable thA = bn0Var.a();
                            if (thA != null) {
                                throw thA;
                            }
                            en0Var2.a = null;
                            en0Var2.b = null;
                            en0Var2.c = jY;
                            en0Var2.e = 3;
                            if (gp0Var.d(en0Var2) != ck1Var) {
                                j = jY;
                                return Boxing.boxLong(j);
                            }
                        }
                    }
                }
            }
            return ck1Var;
        } catch (Throwable th4) {
            gp0 gp0Var2 = gp0Var;
            en0Var = en0Var2;
            th = th4;
            r4 = gp0Var2;
            bn0Var.c(th);
            kp0.a(r4, th);
            throw th;
        }
    }
}
