package com.google.crypto.tink.shaded.protobuf;

import java.util.Arrays;

/* JADX INFO: renamed from: com.google.crypto.tink.shaded.protobuf.i, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0743i extends J3.e {

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

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

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

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

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

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

    public C0743i(byte[] bArr, int i, int i5, boolean z8) {
        this.f10500c = bArr;
        this.f10501d = i5 + i;
        this.f10503f = i;
        this.f10504g = i;
    }

    @Override // J3.e
    public final String A() throws B {
        int iJ = J();
        if (iJ > 0) {
            int i = this.f10501d;
            int i5 = this.f10503f;
            if (iJ <= i - i5) {
                String str = new String(this.f10500c, i5, iJ, AbstractC0759z.f10544a);
                this.f10503f += iJ;
                return str;
            }
        }
        if (iJ == 0) {
            return "";
        }
        if (iJ < 0) {
            throw B.e();
        }
        throw B.g();
    }

    @Override // J3.e
    public final String B() throws B {
        int iJ = J();
        if (iJ > 0) {
            int i = this.f10501d;
            int i5 = this.f10503f;
            if (iJ <= i - i5) {
                String strF = q0.f10539a.f(this.f10500c, i5, iJ);
                this.f10503f += iJ;
                return strF;
            }
        }
        if (iJ == 0) {
            return "";
        }
        if (iJ <= 0) {
            throw B.e();
        }
        throw B.g();
    }

    @Override // J3.e
    public final int C() throws B {
        if (g()) {
            this.f10505h = 0;
            return 0;
        }
        int iJ = J();
        this.f10505h = iJ;
        if ((iJ >>> 3) != 0) {
            return iJ;
        }
        throw B.a();
    }

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

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

    public final int H() throws B {
        int i = this.f10503f;
        if (this.f10501d - i < 4) {
            throw B.g();
        }
        this.f10503f = i + 4;
        byte[] bArr = this.f10500c;
        return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
    }

    public final long I() throws B {
        int i = this.f10503f;
        if (this.f10501d - i < 8) {
            throw B.g();
        }
        this.f10503f = i + 8;
        byte[] bArr = this.f10500c;
        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.f10503f;
        int i8 = this.f10501d;
        if (i8 != i5) {
            int i9 = i5 + 1;
            byte[] bArr = this.f10500c;
            byte b8 = bArr[i5];
            if (b8 >= 0) {
                this.f10503f = 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.f10503f = i10;
                return i;
            }
        }
        return (int) L();
    }

    public final long K() {
        long j8;
        long j9;
        long j10;
        long j11;
        int i = this.f10503f;
        int i5 = this.f10501d;
        if (i5 != i) {
            int i8 = i + 1;
            byte[] bArr = this.f10500c;
            byte b8 = bArr[i];
            if (b8 >= 0) {
                this.f10503f = 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.f10503f = i9;
                return j8;
            }
        }
        return L();
    }

    public final long L() throws B {
        long j8 = 0;
        for (int i = 0; i < 64; i += 7) {
            int i5 = this.f10503f;
            if (i5 == this.f10501d) {
                throw B.g();
            }
            this.f10503f = i5 + 1;
            byte b8 = this.f10500c[i5];
            j8 |= ((long) (b8 & 127)) << i;
            if ((b8 & 128) == 0) {
                return j8;
            }
        }
        throw B.d();
    }

    public final void M() {
        int i = this.f10501d + this.f10502e;
        this.f10501d = i;
        int i5 = i - this.f10504g;
        int i8 = this.i;
        if (i5 <= i8) {
            this.f10502e = 0;
            return;
        }
        int i9 = i5 - i8;
        this.f10502e = i9;
        this.f10501d = i - i9;
    }

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

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

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

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

    @Override // J3.e
    public final int l(int i) {
        if (i < 0) {
            throw B.e();
        }
        int iF = f() + i;
        if (iF < 0) {
            throw B.f();
        }
        int i5 = this.i;
        if (iF > i5) {
            throw B.g();
        }
        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 C0741g o() throws B {
        byte[] bArrCopyOfRange;
        int iJ = J();
        byte[] bArr = this.f10500c;
        if (iJ > 0) {
            int i = this.f10501d;
            int i5 = this.f10503f;
            if (iJ <= i - i5) {
                C0741g c0741gC = AbstractC0742h.c(bArr, i5, iJ);
                this.f10503f += iJ;
                return c0741gC;
            }
        }
        if (iJ == 0) {
            return AbstractC0742h.f10496r;
        }
        if (iJ > 0) {
            int i8 = this.f10501d;
            int i9 = this.f10503f;
            if (iJ <= i8 - i9) {
                int i10 = iJ + i9;
                this.f10503f = i10;
                bArrCopyOfRange = Arrays.copyOfRange(bArr, i9, i10);
            } else {
                if (iJ > 0) {
                    throw B.g();
                }
                if (iJ != 0) {
                    throw B.e();
                }
                bArrCopyOfRange = AbstractC0759z.f10545b;
            }
        }
        C0741g c0741g = AbstractC0742h.f10496r;
        return new C0741g(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() {
        return J3.e.d(J());
    }

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