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 C0430h extends J3.e {

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

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f8079h;
    public int i = Integer.MAX_VALUE;

    public C0430h(byte[] bArr, int i, int i5, boolean z8) {
        this.f8074c = bArr;
        this.f8075d = i5 + i;
        this.f8077f = i;
        this.f8078g = i;
    }

    @Override // J3.e
    public final String A() throws C0446y {
        int iJ = J();
        if (iJ > 0) {
            int i = this.f8075d;
            int i5 = this.f8077f;
            if (iJ <= i - i5) {
                String str = new String(this.f8074c, i5, iJ, AbstractC0444w.f8140a);
                this.f8077f += iJ;
                return str;
            }
        }
        if (iJ == 0) {
            return "";
        }
        if (iJ < 0) {
            throw C0446y.d();
        }
        throw C0446y.e();
    }

    @Override // J3.e
    public final String B() throws C0446y {
        int iJ = J();
        if (iJ > 0) {
            int i = this.f8075d;
            int i5 = this.f8077f;
            if (iJ <= i - i5) {
                String strU = k0.f8106a.u(this.f8074c, i5, iJ);
                this.f8077f += iJ;
                return strU;
            }
        }
        if (iJ == 0) {
            return "";
        }
        if (iJ <= 0) {
            throw C0446y.d();
        }
        throw C0446y.e();
    }

    @Override // J3.e
    public final int C() throws C0446y {
        if (g()) {
            this.f8079h = 0;
            return 0;
        }
        int iJ = J();
        this.f8079h = iJ;
        if ((iJ >>> 3) != 0) {
            return iJ;
        }
        throw new C0446y("Protocol message contained an invalid tag (zero).");
    }

    @Override // J3.e
    public final int D() {
        return J();
    }

    @Override // J3.e
    public final long E() {
        return K();
    }

    @Override // J3.e
    public final boolean F(int i) throws C0446y {
        int i5 = i & 7;
        int i8 = 0;
        if (i5 != 0) {
            if (i5 == 1) {
                N(8);
                return true;
            }
            if (i5 == 2) {
                N(J());
                return true;
            }
            if (i5 == 3) {
                G();
                b(((i >>> 3) << 3) | 4);
                return true;
            }
            if (i5 == 4) {
                return false;
            }
            if (i5 != 5) {
                throw C0446y.b();
            }
            N(4);
            return true;
        }
        int i9 = this.f8075d - this.f8077f;
        byte[] bArr = this.f8074c;
        if (i9 >= 10) {
            while (i8 < 10) {
                int i10 = this.f8077f;
                this.f8077f = i10 + 1;
                if (bArr[i10] < 0) {
                    i8++;
                }
            }
            throw C0446y.c();
        }
        while (i8 < 10) {
            int i11 = this.f8077f;
            if (i11 == this.f8075d) {
                throw C0446y.e();
            }
            this.f8077f = i11 + 1;
            if (bArr[i11] < 0) {
                i8++;
            }
        }
        throw C0446y.c();
        return true;
    }

    public final int H() throws C0446y {
        int i = this.f8077f;
        if (this.f8075d - i < 4) {
            throw C0446y.e();
        }
        this.f8077f = i + 4;
        byte[] bArr = this.f8074c;
        return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
    }

    public final long I() throws C0446y {
        int i = this.f8077f;
        if (this.f8075d - i < 8) {
            throw C0446y.e();
        }
        this.f8077f = i + 8;
        byte[] bArr = this.f8074c;
        return ((((long) bArr[i + 7]) & 255) << 56) | (((long) bArr[i]) & 255) | ((((long) bArr[i + 1]) & 255) << 8) | ((((long) bArr[i + 2]) & 255) << 16) | ((((long) bArr[i + 3]) & 255) << 24) | ((((long) bArr[i + 4]) & 255) << 32) | ((((long) bArr[i + 5]) & 255) << 40) | ((((long) bArr[i + 6]) & 255) << 48);
    }

    public final int J() {
        int i;
        int i5 = this.f8077f;
        int i8 = this.f8075d;
        if (i8 != i5) {
            int i9 = i5 + 1;
            byte[] bArr = this.f8074c;
            byte b8 = bArr[i5];
            if (b8 >= 0) {
                this.f8077f = i9;
                return b8;
            }
            if (i8 - i9 >= 9) {
                int i10 = i5 + 2;
                int i11 = (bArr[i9] << 7) ^ b8;
                if (i11 < 0) {
                    i = i11 ^ (-128);
                } else {
                    int i12 = i5 + 3;
                    int i13 = (bArr[i10] << 14) ^ i11;
                    if (i13 >= 0) {
                        i = i13 ^ 16256;
                    } else {
                        int i14 = i5 + 4;
                        int i15 = i13 ^ (bArr[i12] << 21);
                        if (i15 < 0) {
                            i = (-2080896) ^ i15;
                        } else {
                            i12 = i5 + 5;
                            byte b9 = bArr[i14];
                            int i16 = (i15 ^ (b9 << 28)) ^ 266354560;
                            if (b9 < 0) {
                                i14 = i5 + 6;
                                if (bArr[i12] < 0) {
                                    i12 = i5 + 7;
                                    if (bArr[i14] < 0) {
                                        i14 = i5 + 8;
                                        if (bArr[i12] < 0) {
                                            i12 = i5 + 9;
                                            if (bArr[i14] < 0) {
                                                int i17 = i5 + 10;
                                                if (bArr[i12] >= 0) {
                                                    i10 = i17;
                                                    i = i16;
                                                }
                                            }
                                        }
                                    }
                                }
                                i = i16;
                            }
                            i = i16;
                        }
                        i10 = i14;
                    }
                    i10 = i12;
                }
                this.f8077f = i10;
                return i;
            }
        }
        return (int) L();
    }

    public final long K() {
        long j8;
        long j9;
        long j10;
        long j11;
        int i = this.f8077f;
        int i5 = this.f8075d;
        if (i5 != i) {
            int i8 = i + 1;
            byte[] bArr = this.f8074c;
            byte b8 = bArr[i];
            if (b8 >= 0) {
                this.f8077f = i8;
                return b8;
            }
            if (i5 - i8 >= 9) {
                int i9 = i + 2;
                int i10 = (bArr[i8] << 7) ^ b8;
                if (i10 < 0) {
                    j8 = i10 ^ (-128);
                } else {
                    int i11 = i + 3;
                    int i12 = (bArr[i9] << 14) ^ i10;
                    if (i12 >= 0) {
                        j8 = i12 ^ 16256;
                        i9 = i11;
                    } else {
                        int i13 = i + 4;
                        int i14 = i12 ^ (bArr[i11] << 21);
                        if (i14 < 0) {
                            j11 = (-2080896) ^ i14;
                        } else {
                            long j12 = i14;
                            i9 = i + 5;
                            long j13 = j12 ^ (((long) bArr[i13]) << 28);
                            if (j13 >= 0) {
                                j10 = 266354560;
                            } else {
                                i13 = i + 6;
                                long j14 = j13 ^ (((long) bArr[i9]) << 35);
                                if (j14 < 0) {
                                    j9 = -34093383808L;
                                } else {
                                    i9 = i + 7;
                                    j13 = j14 ^ (((long) bArr[i13]) << 42);
                                    if (j13 >= 0) {
                                        j10 = 4363953127296L;
                                    } else {
                                        i13 = i + 8;
                                        j14 = j13 ^ (((long) bArr[i9]) << 49);
                                        if (j14 < 0) {
                                            j9 = -558586000294016L;
                                        } else {
                                            i9 = i + 9;
                                            long j15 = (j14 ^ (((long) bArr[i13]) << 56)) ^ 71499008037633920L;
                                            if (j15 < 0) {
                                                int i15 = i + 10;
                                                if (bArr[i9] >= 0) {
                                                    i9 = i15;
                                                }
                                            }
                                            j8 = j15;
                                        }
                                    }
                                }
                                j11 = j9 ^ j14;
                            }
                            j8 = j10 ^ j13;
                        }
                        i9 = i13;
                        j8 = j11;
                    }
                }
                this.f8077f = i9;
                return j8;
            }
        }
        return L();
    }

    public final long L() throws C0446y {
        long j8 = 0;
        for (int i = 0; i < 64; i += 7) {
            int i5 = this.f8077f;
            if (i5 == this.f8075d) {
                throw C0446y.e();
            }
            this.f8077f = i5 + 1;
            byte b8 = this.f8074c[i5];
            j8 |= ((long) (b8 & 127)) << i;
            if ((b8 & 128) == 0) {
                return j8;
            }
        }
        throw C0446y.c();
    }

    public final void M() {
        int i = this.f8075d + this.f8076e;
        this.f8075d = i;
        int i5 = i - this.f8078g;
        int i8 = this.i;
        if (i5 <= i8) {
            this.f8076e = 0;
            return;
        }
        int i9 = i5 - i8;
        this.f8076e = i9;
        this.f8075d = i - i9;
    }

    public final void N(int i) throws C0446y {
        if (i >= 0) {
            int i5 = this.f8075d;
            int i8 = this.f8077f;
            if (i <= i5 - i8) {
                this.f8077f = i8 + i;
                return;
            }
        }
        if (i >= 0) {
            throw C0446y.e();
        }
        throw C0446y.d();
    }

    @Override // J3.e
    public final void b(int i) throws C0446y {
        if (this.f8079h != i) {
            throw new C0446y("Protocol message end-group tag did not match expected tag.");
        }
    }

    @Override // J3.e
    public final int f() {
        return this.f8077f - this.f8078g;
    }

    @Override // J3.e
    public final boolean g() {
        return this.f8077f == this.f8075d;
    }

    @Override // J3.e
    public final void j(int i) {
        this.i = i;
        M();
    }

    @Override // J3.e
    public final int l(int i) throws C0446y {
        if (i < 0) {
            throw C0446y.d();
        }
        int iF = f() + i;
        if (iF < 0) {
            throw new C0446y("Failed to parse the message.");
        }
        int i5 = this.i;
        if (iF > i5) {
            throw C0446y.e();
        }
        this.i = iF;
        M();
        return i5;
    }

    @Override // J3.e
    public final boolean m() {
        return K() != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x002f  */
    @Override // J3.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C0429g n() throws C0446y {
        byte[] bArrCopyOfRange;
        int iJ = J();
        byte[] bArr = this.f8074c;
        if (iJ > 0) {
            int i = this.f8075d;
            int i5 = this.f8077f;
            if (iJ <= i - i5) {
                C0429g c0429gC = C0429g.c(bArr, i5, iJ);
                this.f8077f += iJ;
                return c0429gC;
            }
        }
        if (iJ == 0) {
            return C0429g.f8069s;
        }
        if (iJ > 0) {
            int i8 = this.f8075d;
            int i9 = this.f8077f;
            if (iJ <= i8 - i9) {
                int i10 = iJ + i9;
                this.f8077f = i10;
                bArrCopyOfRange = Arrays.copyOfRange(bArr, i9, i10);
            } else {
                if (iJ > 0) {
                    throw C0446y.e();
                }
                if (iJ != 0) {
                    throw C0446y.d();
                }
                bArrCopyOfRange = AbstractC0444w.f8141b;
            }
        }
        C0429g c0429g = C0429g.f8069s;
        return new C0429g(bArrCopyOfRange);
    }

    @Override // J3.e
    public final double p() {
        return Double.longBitsToDouble(I());
    }

    @Override // J3.e
    public final int q() {
        return J();
    }

    @Override // J3.e
    public final int r() {
        return H();
    }

    @Override // J3.e
    public final long s() {
        return I();
    }

    @Override // J3.e
    public final float t() {
        return Float.intBitsToFloat(H());
    }

    @Override // J3.e
    public final int u() {
        return J();
    }

    @Override // J3.e
    public final long v() {
        return K();
    }

    @Override // J3.e
    public final int w() {
        return H();
    }

    @Override // J3.e
    public final long x() {
        return I();
    }

    @Override // J3.e
    public final int y() {
        int iJ = J();
        return (-(iJ & 1)) ^ (iJ >>> 1);
    }

    @Override // J3.e
    public final long z() {
        long jK = K();
        return (-(jK & 1)) ^ (jK >>> 1);
    }
}
