package defpackage;

import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import defpackage.kp3;
import java.io.EOFException;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import okhttp3.internal.ws.WebSocketProtocol;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@DebugMetadata(c = "io.ktor.websocket.RawWebSocketCommonKt", f = "RawWebSocketCommon.kt", i = {0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5}, l = {218, 219, 238, 239, 247, 255}, m = "readFrame", n = {"$this$readFrame", "maxFrameSize", "lastOpcode", "$this$readFrame", "maxFrameSize", "lastOpcode", "flagsAndOpcode", "$this$readFrame", "frameType", "maxFrameSize", "flagsAndOpcode", "maskAndLength", "fin", "$this$readFrame", "frameType", "maxFrameSize", "flagsAndOpcode", "maskAndLength", "fin", "$this$readFrame", "frameType", "maxFrameSize", "flagsAndOpcode", "fin", SessionDescription.ATTR_LENGTH, "frameType", "flagsAndOpcode", "fin", "maskKey"}, s = {"L$0", "J$0", "I$0", "L$0", "J$0", "I$0", "B$0", "L$0", "L$1", "J$0", "B$0", "B$1", "I$0", "L$0", "L$1", "J$0", "B$0", "B$1", "I$0", "L$0", "L$1", "J$0", "B$0", "I$0", "J$1", "L$0", "B$0", "I$0", "I$1"})
final class ct7 extends ContinuationImpl {
    public Object a;
    public pp3 b;
    public long c;
    public long d;
    public int e;
    public int f;
    public byte i;
    public byte j;
    public /* synthetic */ Object k;
    public int l;

    /* JADX WARN: Code restructure failed: missing block: B:84:0x01c7, code lost:
    
        if (r2 == r3) goto L96;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:101:0x0201  */
    /* JADX WARN: Removed duplicated region for block: B:106:0x0239  */
    /* JADX WARN: Removed duplicated region for block: B:107:0x023c  */
    /* JADX WARN: Removed duplicated region for block: B:110:0x0246  */
    /* JADX WARN: Removed duplicated region for block: B:111:0x0249  */
    /* JADX WARN: Removed duplicated region for block: B:114:0x024f  */
    /* JADX WARN: Removed duplicated region for block: B:115:0x0252  */
    /* JADX WARN: Removed duplicated region for block: B:118:0x0258  */
    /* JADX WARN: Removed duplicated region for block: B:119:0x025b  */
    /* JADX WARN: Removed duplicated region for block: B:126:0x026e  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x00cf  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x00ee  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00f0  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0106  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x019b  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x01ae  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x01b0  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x01b4  */
    /* JADX WARN: Removed duplicated region for block: B:88:0x01d2  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws op3, EOFException, dl7 {
        ct7 ct7Var;
        long j;
        int i;
        bn0 bn0Var;
        Object objG;
        byte b;
        long j2;
        int i2;
        bn0 bn0Var2;
        byte bByteValue;
        int i3;
        int i4;
        pp3 pp3Var;
        int i5;
        byte b2;
        pp3 pp3Var2;
        byte b3;
        pp3 pp3Var3;
        byte b4;
        long j3;
        long j4;
        bn0 bn0Var3;
        pp3 pp3Var4;
        int i6;
        int iIntValue;
        byte b5;
        int i7;
        pp3 pp3Var5;
        this.k = obj;
        int i8 = this.l | Integer.MIN_VALUE;
        this.l = i8;
        if ((i8 & Integer.MIN_VALUE) != 0) {
            this.l = i8 - Integer.MIN_VALUE;
            ct7Var = this;
        } else {
            ct7Var = new ct7(this);
        }
        Object objG2 = ct7Var.k;
        ck1 ck1Var = ck1.a;
        switch (ct7Var.l) {
            case 0:
                s38.b(objG2);
                ct7Var.a = null;
                j = 0;
                ct7Var.c = 0L;
                ct7Var.e = 0;
                ct7Var.l = 1;
                objG2 = go0.g(null, ct7Var);
                if (objG2 != ck1Var) {
                    i = 0;
                    bn0Var = null;
                    byte bByteValue2 = ((Number) objG2).byteValue();
                    ct7Var.a = bn0Var;
                    ct7Var.c = j;
                    ct7Var.e = i;
                    ct7Var.i = bByteValue2;
                    ct7Var.l = 2;
                    objG = go0.g(bn0Var, ct7Var);
                    if (objG != ck1Var) {
                        b = bByteValue2;
                        objG2 = objG;
                        j2 = j;
                        i2 = i;
                        bn0Var2 = bn0Var;
                        bByteValue = ((Number) objG2).byteValue();
                        i3 = b & 15;
                        if (i3 != 0 && i2 == 0) {
                            throw new dl7("Can't continue finished frames");
                        }
                        int i9 = i3 != 0 ? i2 : i3;
                        pp3.c.getClass();
                        i4 = 0;
                        pp3Var = (i9 >= 0 || i9 > pp3.d) ? null : pp3.e[i9];
                        if (pp3Var != null) {
                            throw new IllegalStateException(n41.k("Unsupported opcode: ", i9));
                        }
                        boolean z = pp3Var.a;
                        if (i3 != 0 && i2 != 0 && !z) {
                            throw new dl7("Can't start new data frame before finishing previous one");
                        }
                        i5 = (b & 128) != 0 ? 1 : 0;
                        if (z && i5 == 0) {
                            throw new dl7("control frames can't be fragmented");
                        }
                        int i10 = bByteValue & 127;
                        if (i10 == 126) {
                            ct7Var.a = bn0Var2;
                            ct7Var.b = pp3Var;
                            ct7Var.c = j2;
                            ct7Var.i = b;
                            ct7Var.j = bByteValue;
                            ct7Var.e = i5;
                            ct7Var.l = 3;
                            Object objN = go0.n(bn0Var2, ct7Var);
                            if (objN != ck1Var) {
                                b2 = bByteValue;
                                objG2 = objN;
                                pp3Var2 = pp3Var;
                                long jShortValue = ((long) ((Number) objG2).shortValue()) & WebSocketProtocol.PAYLOAD_SHORT_MAX;
                                bByteValue = b2;
                                bn0 bn0Var4 = bn0Var2;
                                b4 = b;
                                j3 = j2;
                                j4 = jShortValue;
                                pp3Var4 = pp3Var2;
                                bn0Var3 = bn0Var4;
                                if (!pp3Var4.a) {
                                }
                                if ((bByteValue & 128) != 0) {
                                }
                                if (i6 == 1) {
                                }
                            }
                        } else if (i10 != 127) {
                            long j5 = i10;
                            bn0 bn0Var5 = bn0Var2;
                            b4 = b;
                            j3 = j2;
                            j4 = j5;
                            bn0Var3 = bn0Var5;
                            pp3Var4 = pp3Var;
                            if (!pp3Var4.a && j4 > 125) {
                                throw new dl7("control frames can't be larger than 125 bytes");
                            }
                            i6 = (bByteValue & 128) != 0 ? 1 : i4;
                            if (i6 == 1) {
                                ct7Var.a = bn0Var3;
                                ct7Var.b = pp3Var4;
                                ct7Var.c = j3;
                                ct7Var.i = b4;
                                ct7Var.e = i5;
                                ct7Var.d = j4;
                                ct7Var.l = 5;
                                objG2 = go0.i(bn0Var3, ct7Var);
                            } else {
                                if (i6 != 0) {
                                    throw new io6();
                                }
                                iIntValue = -1;
                                b5 = b4;
                                if (j4 <= 2147483647L || j4 > j3) {
                                    throw new op3(j4);
                                }
                                ct7Var.a = pp3Var4;
                                ct7Var.b = null;
                                ct7Var.i = b5;
                                ct7Var.e = i5;
                                ct7Var.f = iIntValue;
                                ct7Var.l = 6;
                                Object objK = go0.k(bn0Var3, (int) j4, ct7Var);
                                if (objK != ck1Var) {
                                    i7 = iIntValue;
                                    pp3Var5 = pp3Var4;
                                    objG2 = objK;
                                    qx8 qx8Var = (qx8) objG2;
                                    if (i7 != -1) {
                                        byte[] bArr = new byte[4];
                                        bArr[i4] = (byte) (i7 >> 24);
                                        bArr[1] = (byte) (i7 >> 16);
                                        bArr[2] = (byte) (i7 >> 8);
                                        bArr[3] = (byte) i7;
                                        mg0 mg0Var = new mg0();
                                        int iB = (int) oo0.b(qx8Var);
                                        for (int i11 = i4; i11 < iB; i11++) {
                                            mg0Var.bk((byte) (qx8Var.readByte() ^ bArr[i11 % 4]));
                                        }
                                        qx8Var = mg0Var;
                                    }
                                    return kp3.c.a(i5 == 0 ? 1 : i4, pp3Var5, qy8.a(qx8Var), (b5 & 64) == 0 ? 1 : i4, (b5 & 32) == 0 ? 1 : i4, (b5 & 16) == 0 ? 1 : i4);
                                }
                            }
                            break;
                        } else {
                            ct7Var.a = bn0Var2;
                            ct7Var.b = pp3Var;
                            ct7Var.c = j2;
                            ct7Var.i = b;
                            ct7Var.j = bByteValue;
                            ct7Var.e = i5;
                            ct7Var.l = 4;
                            Object objJ = go0.j(bn0Var2, ct7Var);
                            if (objJ != ck1Var) {
                                b3 = bByteValue;
                                objG2 = objJ;
                                pp3Var3 = pp3Var;
                                long jLongValue = ((Number) objG2).longValue();
                                bByteValue = b3;
                                pp3Var4 = pp3Var3;
                                bn0Var3 = bn0Var2;
                                b4 = b;
                                j3 = j2;
                                j4 = jLongValue;
                                if (!pp3Var4.a) {
                                }
                                if ((bByteValue & 128) != 0) {
                                }
                                if (i6 == 1) {
                                }
                            }
                        }
                    }
                }
                return ck1Var;
            case 1:
                i = ct7Var.e;
                j = ct7Var.c;
                bn0Var = (bn0) ct7Var.a;
                s38.b(objG2);
                byte bByteValue22 = ((Number) objG2).byteValue();
                ct7Var.a = bn0Var;
                ct7Var.c = j;
                ct7Var.e = i;
                ct7Var.i = bByteValue22;
                ct7Var.l = 2;
                objG = go0.g(bn0Var, ct7Var);
                if (objG != ck1Var) {
                }
                return ck1Var;
            case 2:
                byte b6 = ct7Var.i;
                i2 = ct7Var.e;
                j2 = ct7Var.c;
                bn0 bn0Var6 = (bn0) ct7Var.a;
                s38.b(objG2);
                bn0Var2 = bn0Var6;
                b = b6;
                bByteValue = ((Number) objG2).byteValue();
                i3 = b & 15;
                if (i3 != 0) {
                }
                if (i3 != 0) {
                }
                pp3.c.getClass();
                i4 = 0;
                if (i9 >= 0) {
                }
                if (pp3Var != null) {
                }
                break;
            case 3:
                i5 = ct7Var.e;
                b2 = ct7Var.j;
                b = ct7Var.i;
                j2 = ct7Var.c;
                pp3Var2 = ct7Var.b;
                bn0Var2 = (bn0) ct7Var.a;
                s38.b(objG2);
                i4 = 0;
                long jShortValue2 = ((long) ((Number) objG2).shortValue()) & WebSocketProtocol.PAYLOAD_SHORT_MAX;
                bByteValue = b2;
                bn0 bn0Var42 = bn0Var2;
                b4 = b;
                j3 = j2;
                j4 = jShortValue2;
                pp3Var4 = pp3Var2;
                bn0Var3 = bn0Var42;
                if (!pp3Var4.a) {
                }
                if ((bByteValue & 128) != 0) {
                }
                if (i6 == 1) {
                }
                break;
            case 4:
                i5 = ct7Var.e;
                b3 = ct7Var.j;
                b = ct7Var.i;
                j2 = ct7Var.c;
                pp3Var3 = ct7Var.b;
                bn0Var2 = (bn0) ct7Var.a;
                s38.b(objG2);
                i4 = 0;
                long jLongValue2 = ((Number) objG2).longValue();
                bByteValue = b3;
                pp3Var4 = pp3Var3;
                bn0Var3 = bn0Var2;
                b4 = b;
                j3 = j2;
                j4 = jLongValue2;
                if (!pp3Var4.a) {
                }
                if ((bByteValue & 128) != 0) {
                }
                if (i6 == 1) {
                }
                break;
            case 5:
                j4 = ct7Var.d;
                i5 = ct7Var.e;
                b4 = ct7Var.i;
                j3 = ct7Var.c;
                pp3 pp3Var6 = ct7Var.b;
                bn0Var3 = (bn0) ct7Var.a;
                s38.b(objG2);
                i4 = 0;
                pp3Var4 = pp3Var6;
                iIntValue = ((Number) objG2).intValue();
                b5 = b4;
                if (j4 <= 2147483647L) {
                    break;
                }
                throw new op3(j4);
            case 6:
                i7 = ct7Var.f;
                i5 = ct7Var.e;
                b5 = ct7Var.i;
                pp3 pp3Var7 = (pp3) ct7Var.a;
                s38.b(objG2);
                pp3Var5 = pp3Var7;
                i4 = 0;
                qx8 qx8Var2 = (qx8) objG2;
                if (i7 != -1) {
                }
                return kp3.c.a(i5 == 0 ? 1 : i4, pp3Var5, qy8.a(qx8Var2), (b5 & 64) == 0 ? 1 : i4, (b5 & 32) == 0 ? 1 : i4, (b5 & 16) == 0 ? 1 : i4);
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }
}
