package kotlin.reflect.jvm.internal.impl.protobuf;

/* loaded from: classes3.dex */
final class Utf8 {
    private static int incompleteStateFor(int i) {
        if (i > -12) {
            return -1;
        }
        return i;
    }

    public static boolean isValidUtf8(byte[] bArr) {
        return isValidUtf8(bArr, 0, bArr.length);
    }

    /* JADX WARN: Code restructure failed: missing block: B:10:0x0015, code lost:
    
        if (r7[r8] > (-65)) goto L13;
     */
    /* JADX WARN: Code restructure failed: missing block: B:30:0x0046, code lost:
    
        if (r7[r8] > (-65)) goto L32;
     */
    /* JADX WARN: Code restructure failed: missing block: B:50:0x0083, code lost:
    
        if (r7[r6] > (-65)) goto L53;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static int partialIsValidUtf8(int r6, byte[] r7, int r8, int r9) {
        /*
            if (r6 == 0) goto L86
            if (r8 < r9) goto L5
            return r6
        L5:
            byte r0 = (byte) r6
            r1 = -32
            r2 = -1
            r3 = -65
            if (r0 >= r1) goto L1c
            r6 = -62
            if (r0 < r6) goto L1b
            int r6 = r8 + 1
            r8 = r7[r8]
            if (r8 <= r3) goto L18
            goto L1b
        L18:
            r8 = r6
            goto L86
        L1b:
            return r2
        L1c:
            r4 = -16
            if (r0 >= r4) goto L49
            int r6 = r6 >> 8
            int r6 = ~r6
            byte r6 = (byte) r6
            if (r6 != 0) goto L34
            int r6 = r8 + 1
            r8 = r7[r8]
            if (r6 < r9) goto L31
            int r6 = incompleteStateFor(r0, r8)
            return r6
        L31:
            r5 = r8
            r8 = r6
            r6 = r5
        L34:
            if (r6 > r3) goto L48
            r4 = -96
            if (r0 != r1) goto L3c
            if (r6 < r4) goto L48
        L3c:
            r1 = -19
            if (r0 != r1) goto L42
            if (r6 >= r4) goto L48
        L42:
            int r6 = r8 + 1
            r8 = r7[r8]
            if (r8 <= r3) goto L18
        L48:
            return r2
        L49:
            int r1 = r6 >> 8
            int r1 = ~r1
            byte r1 = (byte) r1
            if (r1 != 0) goto L5c
            int r6 = r8 + 1
            r1 = r7[r8]
            if (r6 < r9) goto L5a
            int r6 = incompleteStateFor(r0, r1)
            return r6
        L5a:
            r8 = 0
            goto L62
        L5c:
            int r6 = r6 >> 16
            byte r6 = (byte) r6
            r5 = r8
            r8 = r6
            r6 = r5
        L62:
            if (r8 != 0) goto L72
            int r8 = r6 + 1
            r6 = r7[r6]
            if (r8 < r9) goto L6f
            int r6 = incompleteStateFor(r0, r1, r6)
            return r6
        L6f:
            r5 = r8
            r8 = r6
            r6 = r5
        L72:
            if (r1 > r3) goto L85
            int r0 = r0 << 28
            int r1 = r1 + 112
            int r1 = r1 + r0
            int r0 = r1 >> 30
            if (r0 != 0) goto L85
            if (r8 > r3) goto L85
            int r8 = r6 + 1
            r6 = r7[r6]
            if (r6 <= r3) goto L86
        L85:
            return r2
        L86:
            int r6 = partialIsValidUtf8(r7, r8, r9)
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: kotlin.reflect.jvm.internal.impl.protobuf.Utf8.partialIsValidUtf8(int, byte[], int, int):int");
    }

    private static int partialIsValidUtf8NonAscii(byte[] bArr, int i, int i4) {
        while (i < i4) {
            int i5 = i + 1;
            byte b4 = bArr[i];
            if (b4 < 0) {
                if (b4 < -32) {
                    if (i5 >= i4) {
                        return b4;
                    }
                    if (b4 >= -62) {
                        i += 2;
                        if (bArr[i5] > -65) {
                        }
                    }
                    return -1;
                }
                if (b4 < -16) {
                    if (i5 >= i4 - 1) {
                        return incompleteStateFor(bArr, i5, i4);
                    }
                    int i6 = i + 2;
                    byte b5 = bArr[i5];
                    if (b5 <= -65 && ((b4 != -32 || b5 >= -96) && (b4 != -19 || b5 < -96))) {
                        i += 3;
                        if (bArr[i6] > -65) {
                        }
                    }
                    return -1;
                }
                if (i5 >= i4 - 2) {
                    return incompleteStateFor(bArr, i5, i4);
                }
                int i7 = i + 2;
                byte b6 = bArr[i5];
                if (b6 <= -65) {
                    if ((((b6 + 112) + (b4 << 28)) >> 30) == 0) {
                        int i8 = i + 3;
                        if (bArr[i7] <= -65) {
                            i += 4;
                            if (bArr[i8] > -65) {
                            }
                        }
                    }
                }
                return -1;
            }
            i = i5;
        }
        return 0;
    }

    private static int incompleteStateFor(int i, int i4) {
        if (i > -12 || i4 > -65) {
            return -1;
        }
        return i ^ (i4 << 8);
    }

    public static boolean isValidUtf8(byte[] bArr, int i, int i4) {
        return partialIsValidUtf8(bArr, i, i4) == 0;
    }

    private static int incompleteStateFor(int i, int i4, int i5) {
        if (i > -12 || i4 > -65 || i5 > -65) {
            return -1;
        }
        return (i ^ (i4 << 8)) ^ (i5 << 16);
    }

    private static int incompleteStateFor(byte[] bArr, int i, int i4) {
        byte b4 = bArr[i - 1];
        int i5 = i4 - i;
        if (i5 == 0) {
            return incompleteStateFor(b4);
        }
        if (i5 == 1) {
            return incompleteStateFor(b4, bArr[i]);
        }
        if (i5 == 2) {
            return incompleteStateFor(b4, bArr[i], bArr[i + 1]);
        }
        throw new AssertionError();
    }

    public static int partialIsValidUtf8(byte[] bArr, int i, int i4) {
        while (i < i4 && bArr[i] >= 0) {
            i++;
        }
        if (i >= i4) {
            return 0;
        }
        return partialIsValidUtf8NonAscii(bArr, i, i4);
    }
}
