package defpackage;

import defpackage.il0;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lhwa;", "Le6a;", "<anonymous>", "(Lhwa;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "io.ktor.client.utils.ByteChannelUtilsKt$observable$1", f = "ByteChannelUtils.kt", i = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3}, l = {22, 24, 26, 31}, m = "invokeSuspend", n = {"$this$writer", "$this$useInstance$iv", "instance$iv", "byteArray", "bytesSend", "$this$writer", "$this$useInstance$iv", "instance$iv", "byteArray", "bytesSend", "read", "$this$writer", "$this$useInstance$iv", "instance$iv", "byteArray", "bytesSend", "$this$useInstance$iv", "instance$iv"}, s = {"L$0", "L$1", "L$5", "L$6", "J$0", "L$0", "L$1", "L$5", "L$6", "J$0", "I$0", "L$0", "L$1", "L$5", "L$6", "J$0", "L$0", "L$1"})
@vx8
final class gm0 extends SuspendLambda implements gr3<hwa, Continuation<? super e6a>, Object> {
    public Object a;
    public bn0 b;
    public rj7 c;
    public Long d;
    public Object e;
    public byte[] f;
    public long i;
    public int j;
    public int k;
    public /* synthetic */ Object l;
    public final /* synthetic */ bn0 m;
    public final /* synthetic */ rj7 n;
    public final /* synthetic */ Long o;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public gm0(bn0 bn0Var, rj7 rj7Var, Long l, Continuation continuation) {
        super(2, continuation);
        this.m = bn0Var;
        this.n = rj7Var;
        this.o = l;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        gm0 gm0Var = new gm0(this.m, this.n, this.o, continuation);
        gm0Var.l = obj;
        return gm0Var;
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((gm0) create((hwa) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:63:0x0165, code lost:
    
        if (r11.a() == r0) goto L64;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00c8 A[Catch: all -> 0x0020, TryCatch #0 {all -> 0x0020, blocks: (B:9:0x001b, B:34:0x00c2, B:36:0x00c8, B:39:0x00e3, B:41:0x00eb, B:58:0x0140, B:62:0x014f), top: B:71:0x000a }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00eb A[Catch: all -> 0x0020, TRY_LEAVE, TryCatch #0 {all -> 0x0020, blocks: (B:9:0x001b, B:34:0x00c2, B:36:0x00c8, B:39:0x00e3, B:41:0x00eb, B:58:0x0140, B:62:0x014f), top: B:71:0x000a }] */
    /* JADX WARN: Removed duplicated region for block: B:51:0x012e  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x013e  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x0140 A[Catch: all -> 0x0020, TRY_ENTER, TryCatch #0 {all -> 0x0020, blocks: (B:9:0x001b, B:34:0x00c2, B:36:0x00c8, B:39:0x00e3, B:41:0x00eb, B:58:0x0140, B:62:0x014f), top: B:71:0x000a }] */
    /* JADX WARN: Type inference failed for: r2v0, types: [int] */
    /* JADX WARN: Type inference failed for: r2v1, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v10, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v12, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v13 */
    /* JADX WARN: Type inference failed for: r2v14, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v16 */
    /* JADX WARN: Type inference failed for: r2v17 */
    /* JADX WARN: Type inference failed for: r2v19 */
    /* JADX WARN: Type inference failed for: r2v21 */
    /* JADX WARN: Type inference failed for: r2v22 */
    /* JADX WARN: Type inference failed for: r2v25 */
    /* JADX WARN: Type inference failed for: r2v26 */
    /* JADX WARN: Type inference failed for: r2v27 */
    /* JADX WARN: Type inference failed for: r2v28 */
    /* JADX WARN: Type inference failed for: r2v29 */
    /* JADX WARN: Type inference failed for: r2v30 */
    /* JADX WARN: Type inference failed for: r2v31 */
    /* JADX WARN: Type inference failed for: r2v32 */
    /* JADX WARN: Type inference failed for: r2v4 */
    /* JADX WARN: Type inference failed for: r2v5 */
    /* JADX WARN: Type inference failed for: r2v6 */
    /* JADX WARN: Type inference failed for: r2v8 */
    /* JADX WARN: Type inference failed for: r2v9, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r3v0, types: [qs6] */
    /* JADX WARN: Type inference failed for: r3v10 */
    /* JADX WARN: Type inference failed for: r3v16 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v20 */
    /* JADX WARN: Type inference failed for: r3v21 */
    /* JADX WARN: Type inference failed for: r3v22 */
    /* JADX WARN: Type inference failed for: r3v23 */
    /* JADX WARN: Type inference failed for: r3v28 */
    /* JADX WARN: Type inference failed for: r3v9, types: [qs6] */
    /* JADX WARN: Type inference failed for: r8v1 */
    /* JADX WARN: Type inference failed for: r8v4 */
    /* JADX WARN: Type inference failed for: r8v7 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:51:0x012e -> B:52:0x0134). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:57:0x013e -> B:34:0x00c2). 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 {
        ?? r3;
        long j;
        rj7 rj7Var;
        bn0 bn0Var;
        Long l;
        hwa hwaVar;
        ?? r2;
        byte[] bArr;
        long j2;
        qs6 qs6Var;
        Long l2;
        ?? r8;
        bn0 bn0Var2;
        hwa hwaVar2;
        int i;
        long j3;
        Object objE;
        qs6 qs6Var2;
        ?? r22;
        int iIntValue;
        qs6 qs6Var3;
        ?? r32;
        ?? r23;
        ck1 ck1Var = ck1.a;
        ?? r24 = this.k;
        int i2 = 2;
        int i3 = 1;
        try {
            if (r24 == 0) {
                j = 0;
                s38.b(obj);
                hwa hwaVar3 = (hwa) this.l;
                il0.a aVar = il0.a;
                Object objA = aVar.a();
                try {
                    byte[] bArr2 = (byte[]) objA;
                    bn0 bn0Var3 = this.m;
                    rj7Var = this.n;
                    bn0Var = bn0Var3;
                    l = this.o;
                    hwaVar = hwaVar3;
                    r2 = objA;
                    bArr = bArr2;
                    j2 = 0;
                    qs6Var3 = aVar;
                    if (bn0Var.i()) {
                    }
                    return ck1Var;
                } catch (Throwable th) {
                    th = th;
                    r24 = objA;
                    r3 = aVar;
                }
            } else if (r24 == 1) {
                j = 0;
                long j4 = this.i;
                bArr = this.f;
                Object obj2 = this.e;
                l = this.d;
                rj7Var = this.c;
                bn0Var = this.b;
                qs6 qs6Var4 = (qs6) this.a;
                hwaVar = (hwa) this.l;
                try {
                    s38.b(obj);
                    objE = obj;
                    j2 = j4;
                    r22 = obj2;
                    qs6Var2 = qs6Var4;
                    iIntValue = ((Number) objE).intValue();
                    if (iIntValue <= 0) {
                    }
                } catch (Throwable th2) {
                    th = th2;
                    r24 = obj2;
                    r3 = qs6Var4;
                }
            } else {
                if (r24 == 2) {
                    j = 0;
                    i = this.j;
                    long j5 = this.i;
                    byte[] bArr3 = this.f;
                    Object obj3 = this.e;
                    Long l3 = this.d;
                    rj7 rj7Var2 = this.c;
                    bn0 bn0Var4 = this.b;
                    qs6Var = (qs6) this.a;
                    hwa hwaVar4 = (hwa) this.l;
                    try {
                        s38.b(obj);
                        l2 = l3;
                        rj7Var = rj7Var2;
                        j2 = j5;
                        bArr = bArr3;
                        r8 = obj3;
                        bn0Var2 = bn0Var4;
                        hwaVar2 = hwaVar4;
                        qs6Var = qs6Var;
                        j3 = ((long) i) + j2;
                        this.l = hwaVar2;
                        this.a = qs6Var;
                        this.b = bn0Var2;
                        this.c = rj7Var;
                        this.d = l2;
                        r24 = r8;
                        this.e = r24;
                        this.f = bArr;
                        this.i = j3;
                        this.k = 3;
                        if (rj7Var.a() != ck1Var) {
                        }
                        return ck1Var;
                    } catch (Throwable th3) {
                        th = th3;
                        r24 = obj3;
                        r3 = qs6Var;
                        r3.cd(r24);
                        throw th;
                    }
                }
                if (r24 != 3) {
                    if (r24 != 4) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    Object obj4 = this.a;
                    qs6 qs6Var5 = (qs6) this.l;
                    s38.b(obj);
                    r23 = obj4;
                    r32 = qs6Var5;
                    r32.cd(r23);
                    return e6a.a;
                }
                long j6 = this.i;
                byte[] bArr4 = this.f;
                Object obj5 = this.e;
                Long l4 = this.d;
                rj7 rj7Var3 = this.c;
                bn0 bn0Var5 = this.b;
                qs6 qs6Var6 = (qs6) this.a;
                j = 0;
                hwa hwaVar5 = (hwa) this.l;
                try {
                    s38.b(obj);
                    bArr = bArr4;
                    ?? r25 = obj5;
                    rj7Var = rj7Var3;
                    j2 = j6;
                    l = l4;
                    bn0Var = bn0Var5;
                    hwaVar = hwaVar5;
                    qs6 qs6Var7 = qs6Var6;
                    i2 = 2;
                    i3 = 1;
                    r2 = r25;
                    qs6Var3 = qs6Var7;
                    if (bn0Var.i()) {
                        this.l = hwaVar;
                        this.a = qs6Var3;
                        this.b = bn0Var;
                        this.c = rj7Var;
                        this.d = l;
                        this.e = r2;
                        this.f = bArr;
                        this.i = j2;
                        this.k = i3;
                        objE = go0.e(bn0Var, bArr, bArr.length, this);
                        r22 = r2;
                        qs6Var2 = qs6Var3;
                        if (objE != ck1Var) {
                            iIntValue = ((Number) objE).intValue();
                            if (iIntValue <= 0) {
                                gp0 gp0Var = hwaVar.a;
                                this.l = hwaVar;
                                this.a = qs6Var2;
                                this.b = bn0Var;
                                this.c = rj7Var;
                                this.d = l;
                                this.e = r22;
                                this.f = bArr;
                                this.i = j2;
                                this.j = iIntValue;
                                this.k = i2;
                                if (kp0.c(gp0Var, bArr, 0, iIntValue, this) != ck1Var) {
                                    try {
                                        try {
                                            hwa hwaVar6 = hwaVar;
                                            qs6Var = qs6Var2;
                                            hwaVar2 = hwaVar6;
                                            r8 = r22;
                                            bn0Var2 = bn0Var;
                                            i = iIntValue;
                                            l2 = l;
                                            this.l = hwaVar2;
                                            this.a = qs6Var;
                                            this.b = bn0Var2;
                                            this.c = rj7Var;
                                            this.d = l2;
                                            this.e = r24;
                                            this.f = bArr;
                                            this.i = j3;
                                            this.k = 3;
                                            if (rj7Var.a() != ck1Var) {
                                                qs6 qs6Var8 = qs6Var;
                                                hwaVar = hwaVar2;
                                                qs6Var7 = qs6Var8;
                                                j2 = j3;
                                                l = l2;
                                                bn0Var = bn0Var2;
                                                r25 = r24;
                                                i2 = 2;
                                                i3 = 1;
                                                r2 = r25;
                                                qs6Var3 = qs6Var7;
                                                if (bn0Var.i()) {
                                                    Throwable thA = bn0Var.a();
                                                    kp0.a(hwaVar.a, thA);
                                                    r23 = r2;
                                                    r32 = qs6Var3;
                                                    if (thA == null) {
                                                        r23 = r2;
                                                        r32 = qs6Var3;
                                                        if (j2 == j) {
                                                            this.l = qs6Var3;
                                                            this.a = r2;
                                                            this.b = null;
                                                            this.c = null;
                                                            this.d = null;
                                                            this.e = null;
                                                            this.f = null;
                                                            this.k = 4;
                                                            r23 = r2;
                                                            r32 = qs6Var3;
                                                        }
                                                    }
                                                    r32.cd(r23);
                                                    return e6a.a;
                                                }
                                            }
                                        } catch (Throwable th4) {
                                            th = th4;
                                            r3 = qs6Var;
                                            r3.cd(r24);
                                            throw th;
                                        }
                                        r24 = r8;
                                    } catch (Throwable th5) {
                                        th = th5;
                                        r24 = r8;
                                    }
                                    j3 = ((long) i) + j2;
                                }
                            } else {
                                r2 = r22;
                                qs6Var3 = qs6Var2;
                                if (bn0Var.i()) {
                                }
                            }
                        }
                    }
                    return ck1Var;
                } catch (Throwable th6) {
                    th = th6;
                    r24 = obj5;
                    r3 = qs6Var6;
                }
            }
        } catch (Throwable th7) {
            th = th7;
        }
        r3.cd(r24);
        throw th;
    }
}
