package androidx.datastore.preferences.protobuf;

import java.util.Arrays;

/* JADX INFO: renamed from: androidx.datastore.preferences.protobuf.h, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1019h extends F1.L {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final byte[] f11387c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f11388d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f11389e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f11390f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int f11391j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f11392k;
    public int l = Integer.MAX_VALUE;

    public C1019h(byte[] bArr, int i6, int i7, boolean z6) {
        this.f11387c = bArr;
        this.f11388d = i7 + i6;
        this.f11390f = i6;
        this.f11391j = i6;
    }

    @Override // F1.L
    public final long A() {
        return O();
    }

    @Override // F1.L
    public final int B() {
        return L();
    }

    @Override // F1.L
    public final long C() {
        return M();
    }

    @Override // F1.L
    public final int D() {
        int iN = N();
        return (-(iN & 1)) ^ (iN >>> 1);
    }

    @Override // F1.L
    public final long E() {
        long jO = O();
        return (-(jO & 1)) ^ (jO >>> 1);
    }

    @Override // F1.L
    public final String F() throws C1034x {
        int iN = N();
        if (iN > 0) {
            int i6 = this.f11388d;
            int i7 = this.f11390f;
            if (iN <= i6 - i7) {
                String str = new String(this.f11387c, i7, iN, AbstractC1032v.f11445a);
                this.f11390f += iN;
                return str;
            }
        }
        if (iN == 0) {
            return "";
        }
        if (iN < 0) {
            throw C1034x.d();
        }
        throw C1034x.e();
    }

    @Override // F1.L
    public final String G() throws C1034x {
        int iN = N();
        if (iN > 0) {
            int i6 = this.f11388d;
            int i7 = this.f11390f;
            if (iN <= i6 - i7) {
                String strA = t0.f11444a.a(this.f11387c, i7, iN);
                this.f11390f += iN;
                return strA;
            }
        }
        if (iN == 0) {
            return "";
        }
        if (iN <= 0) {
            throw C1034x.d();
        }
        throw C1034x.e();
    }

    @Override // F1.L
    public final int H() throws C1034x {
        if (h()) {
            this.f11392k = 0;
            return 0;
        }
        int iN = N();
        this.f11392k = iN;
        if ((iN >>> 3) != 0) {
            return iN;
        }
        throw new C1034x("Protocol message contained an invalid tag (zero).");
    }

    @Override // F1.L
    public final int I() {
        return N();
    }

    @Override // F1.L
    public final long J() {
        return O();
    }

    @Override // F1.L
    public final boolean K(int i6) throws C1034x {
        int iH;
        int i7 = i6 & 7;
        int i8 = 0;
        if (i7 == 0) {
            int i9 = this.f11388d - this.f11390f;
            byte[] bArr = this.f11387c;
            if (i9 >= 10) {
                while (i8 < 10) {
                    int i10 = this.f11390f;
                    this.f11390f = i10 + 1;
                    if (bArr[i10] < 0) {
                        i8++;
                    }
                }
                throw C1034x.c();
            }
            while (i8 < 10) {
                int i11 = this.f11390f;
                if (i11 == this.f11388d) {
                    throw C1034x.e();
                }
                this.f11390f = i11 + 1;
                if (bArr[i11] < 0) {
                    i8++;
                }
            }
            throw C1034x.c();
            return true;
        }
        if (i7 == 1) {
            R(8);
            return true;
        }
        if (i7 == 2) {
            R(N());
            return true;
        }
        if (i7 != 3) {
            if (i7 == 4) {
                return false;
            }
            if (i7 != 5) {
                throw C1034x.b();
            }
            R(4);
            return true;
        }
        do {
            iH = H();
            if (iH == 0) {
                break;
            }
        } while (K(iH));
        c(((i6 >>> 3) << 3) | 4);
        return true;
    }

    public final int L() throws C1034x {
        int i6 = this.f11390f;
        if (this.f11388d - i6 < 4) {
            throw C1034x.e();
        }
        this.f11390f = i6 + 4;
        byte[] bArr = this.f11387c;
        return ((bArr[i6 + 3] & 255) << 24) | (bArr[i6] & 255) | ((bArr[i6 + 1] & 255) << 8) | ((bArr[i6 + 2] & 255) << 16);
    }

    public final long M() throws C1034x {
        int i6 = this.f11390f;
        if (this.f11388d - i6 < 8) {
            throw C1034x.e();
        }
        this.f11390f = i6 + 8;
        byte[] bArr = this.f11387c;
        return ((((long) bArr[i6 + 7]) & 255) << 56) | (((long) bArr[i6]) & 255) | ((((long) bArr[i6 + 1]) & 255) << 8) | ((((long) bArr[i6 + 2]) & 255) << 16) | ((((long) bArr[i6 + 3]) & 255) << 24) | ((((long) bArr[i6 + 4]) & 255) << 32) | ((((long) bArr[i6 + 5]) & 255) << 40) | ((((long) bArr[i6 + 6]) & 255) << 48);
    }

    public final int N() {
        int i6;
        int i7 = this.f11390f;
        int i8 = this.f11388d;
        if (i8 != i7) {
            int i9 = i7 + 1;
            byte[] bArr = this.f11387c;
            byte b5 = bArr[i7];
            if (b5 >= 0) {
                this.f11390f = i9;
                return b5;
            }
            if (i8 - i9 >= 9) {
                int i10 = i7 + 2;
                int i11 = (bArr[i9] << 7) ^ b5;
                if (i11 < 0) {
                    i6 = i11 ^ (-128);
                } else {
                    int i12 = i7 + 3;
                    int i13 = (bArr[i10] << 14) ^ i11;
                    if (i13 >= 0) {
                        i6 = i13 ^ 16256;
                    } else {
                        int i14 = i7 + 4;
                        int i15 = i13 ^ (bArr[i12] << 21);
                        if (i15 < 0) {
                            i6 = (-2080896) ^ i15;
                        } else {
                            i12 = i7 + 5;
                            byte b6 = bArr[i14];
                            int i16 = (i15 ^ (b6 << 28)) ^ 266354560;
                            if (b6 < 0) {
                                i14 = i7 + 6;
                                if (bArr[i12] < 0) {
                                    i12 = i7 + 7;
                                    if (bArr[i14] < 0) {
                                        i14 = i7 + 8;
                                        if (bArr[i12] < 0) {
                                            i12 = i7 + 9;
                                            if (bArr[i14] < 0) {
                                                int i17 = i7 + 10;
                                                if (bArr[i12] >= 0) {
                                                    i10 = i17;
                                                    i6 = i16;
                                                }
                                            }
                                        }
                                    }
                                }
                                i6 = i16;
                            }
                            i6 = i16;
                        }
                        i10 = i14;
                    }
                    i10 = i12;
                }
                this.f11390f = i10;
                return i6;
            }
        }
        return (int) P();
    }

    public final long O() {
        long j4;
        long j6;
        long j7;
        long j8;
        int i6 = this.f11390f;
        int i7 = this.f11388d;
        if (i7 != i6) {
            int i8 = i6 + 1;
            byte[] bArr = this.f11387c;
            byte b5 = bArr[i6];
            if (b5 >= 0) {
                this.f11390f = i8;
                return b5;
            }
            if (i7 - i8 >= 9) {
                int i9 = i6 + 2;
                int i10 = (bArr[i8] << 7) ^ b5;
                if (i10 < 0) {
                    j4 = i10 ^ (-128);
                } else {
                    int i11 = i6 + 3;
                    int i12 = (bArr[i9] << 14) ^ i10;
                    if (i12 >= 0) {
                        j4 = i12 ^ 16256;
                        i9 = i11;
                    } else {
                        int i13 = i6 + 4;
                        int i14 = i12 ^ (bArr[i11] << 21);
                        if (i14 < 0) {
                            j8 = (-2080896) ^ i14;
                        } else {
                            long j9 = i14;
                            i9 = i6 + 5;
                            long j10 = j9 ^ (((long) bArr[i13]) << 28);
                            if (j10 >= 0) {
                                j7 = 266354560;
                            } else {
                                i13 = i6 + 6;
                                long j11 = j10 ^ (((long) bArr[i9]) << 35);
                                if (j11 < 0) {
                                    j6 = -34093383808L;
                                } else {
                                    i9 = i6 + 7;
                                    j10 = j11 ^ (((long) bArr[i13]) << 42);
                                    if (j10 >= 0) {
                                        j7 = 4363953127296L;
                                    } else {
                                        i13 = i6 + 8;
                                        j11 = j10 ^ (((long) bArr[i9]) << 49);
                                        if (j11 < 0) {
                                            j6 = -558586000294016L;
                                        } else {
                                            i9 = i6 + 9;
                                            long j12 = (j11 ^ (((long) bArr[i13]) << 56)) ^ 71499008037633920L;
                                            if (j12 < 0) {
                                                int i15 = i6 + 10;
                                                if (bArr[i9] >= 0) {
                                                    i9 = i15;
                                                }
                                            }
                                            j4 = j12;
                                        }
                                    }
                                }
                                j8 = j6 ^ j11;
                            }
                            j4 = j7 ^ j10;
                        }
                        i9 = i13;
                        j4 = j8;
                    }
                }
                this.f11390f = i9;
                return j4;
            }
        }
        return P();
    }

    public final long P() throws C1034x {
        long j4 = 0;
        for (int i6 = 0; i6 < 64; i6 += 7) {
            int i7 = this.f11390f;
            if (i7 == this.f11388d) {
                throw C1034x.e();
            }
            this.f11390f = i7 + 1;
            byte b5 = this.f11387c[i7];
            j4 |= ((long) (b5 & 127)) << i6;
            if ((b5 & 128) == 0) {
                return j4;
            }
        }
        throw C1034x.c();
    }

    public final void Q() {
        int i6 = this.f11388d + this.f11389e;
        this.f11388d = i6;
        int i7 = i6 - this.f11391j;
        int i8 = this.l;
        if (i7 <= i8) {
            this.f11389e = 0;
            return;
        }
        int i9 = i7 - i8;
        this.f11389e = i9;
        this.f11388d = i6 - i9;
    }

    public final void R(int i6) throws C1034x {
        if (i6 >= 0) {
            int i7 = this.f11388d;
            int i8 = this.f11390f;
            if (i6 <= i7 - i8) {
                this.f11390f = i8 + i6;
                return;
            }
        }
        if (i6 >= 0) {
            throw C1034x.e();
        }
        throw C1034x.d();
    }

    @Override // F1.L
    public final void c(int i6) throws C1034x {
        if (this.f11392k != i6) {
            throw new C1034x("Protocol message end-group tag did not match expected tag.");
        }
    }

    @Override // F1.L
    public final int g() {
        return this.f11390f - this.f11391j;
    }

    @Override // F1.L
    public final boolean h() {
        return this.f11390f == this.f11388d;
    }

    @Override // F1.L
    public final void o(int i6) {
        this.l = i6;
        Q();
    }

    @Override // F1.L
    public final int q(int i6) throws C1034x {
        if (i6 < 0) {
            throw C1034x.d();
        }
        int iG = g() + i6;
        if (iG < 0) {
            throw new C1034x("Failed to parse the message.");
        }
        int i7 = this.l;
        if (iG > i7) {
            throw C1034x.e();
        }
        this.l = iG;
        Q();
        return i7;
    }

    @Override // F1.L
    public final boolean r() {
        return O() != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x002f  */
    @Override // F1.L
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C1018g s() throws C1034x {
        byte[] bArrCopyOfRange;
        int iN = N();
        byte[] bArr = this.f11387c;
        if (iN > 0) {
            int i6 = this.f11388d;
            int i7 = this.f11390f;
            if (iN <= i6 - i7) {
                C1018g c1018gH = C1018g.h(bArr, i7, iN);
                this.f11390f += iN;
                return c1018gH;
            }
        }
        if (iN == 0) {
            return C1018g.f11383c;
        }
        if (iN > 0) {
            int i8 = this.f11388d;
            int i9 = this.f11390f;
            if (iN <= i8 - i9) {
                int i10 = iN + i9;
                this.f11390f = i10;
                bArrCopyOfRange = Arrays.copyOfRange(bArr, i9, i10);
            } else {
                if (iN > 0) {
                    throw C1034x.e();
                }
                if (iN != 0) {
                    throw C1034x.d();
                }
                bArrCopyOfRange = AbstractC1032v.f11446b;
            }
        }
        C1018g c1018g = C1018g.f11383c;
        return new C1018g(bArrCopyOfRange);
    }

    @Override // F1.L
    public final double u() {
        return Double.longBitsToDouble(M());
    }

    @Override // F1.L
    public final int v() {
        return N();
    }

    @Override // F1.L
    public final int w() {
        return L();
    }

    @Override // F1.L
    public final long x() {
        return M();
    }

    @Override // F1.L
    public final float y() {
        return Float.intBitsToFloat(L());
    }

    @Override // F1.L
    public final int z() {
        return N();
    }
}
