package com.google.android.gms.internal.pal;

/* JADX INFO: loaded from: classes2.dex */
public final class q {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public r f21144b;

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

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

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

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

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

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

    public /* synthetic */ q(byte[] bArr, int i10) {
        this.f21145c = bArr;
        this.f21146d = i10;
    }

    public static int j(int i10) {
        return (-(i10 & 1)) ^ (i10 >>> 1);
    }

    public static long k(long j10) {
        return (-(j10 & 1)) ^ (j10 >>> 1);
    }

    public final int a(int i10) {
        if (i10 < 0) {
            throw zzadi.c();
        }
        int i11 = i10 + this.f21148f;
        if (i11 < 0) {
            throw zzadi.d();
        }
        int i12 = this.f21150h;
        if (i11 > i12) {
            throw zzadi.f();
        }
        this.f21150h = i11;
        int i13 = this.f21146d + this.f21147e;
        this.f21146d = i13;
        if (i13 > i11) {
            int i14 = i13 - i11;
            this.f21147e = i14;
            this.f21146d = i13 - i14;
        } else {
            this.f21147e = 0;
        }
        return i12;
    }

    public final int b() throws zzadi {
        int i10 = this.f21148f;
        if (this.f21146d - i10 < 4) {
            throw zzadi.f();
        }
        this.f21148f = i10 + 4;
        byte[] bArr = this.f21145c;
        return ((bArr[i10 + 3] & 255) << 24) | (bArr[i10] & 255) | ((bArr[i10 + 1] & 255) << 8) | ((bArr[i10 + 2] & 255) << 16);
    }

    public final int c() {
        int i10;
        int i11 = this.f21148f;
        int i12 = this.f21146d;
        if (i12 != i11) {
            int i13 = i11 + 1;
            byte[] bArr = this.f21145c;
            byte b10 = bArr[i11];
            if (b10 >= 0) {
                this.f21148f = i13;
                return b10;
            }
            if (i12 - i13 >= 9) {
                int i14 = i11 + 2;
                int i15 = (bArr[i13] << 7) ^ b10;
                if (i15 < 0) {
                    i10 = i15 ^ (-128);
                } else {
                    int i16 = i11 + 3;
                    int i17 = (bArr[i14] << 14) ^ i15;
                    if (i17 >= 0) {
                        i10 = i17 ^ 16256;
                    } else {
                        int i18 = i11 + 4;
                        int i19 = i17 ^ (bArr[i16] << 21);
                        if (i19 < 0) {
                            i10 = (-2080896) ^ i19;
                        } else {
                            i16 = i11 + 5;
                            byte b11 = bArr[i18];
                            int i20 = (i19 ^ (b11 << 28)) ^ 266354560;
                            if (b11 < 0) {
                                i18 = i11 + 6;
                                if (bArr[i16] < 0) {
                                    i16 = i11 + 7;
                                    if (bArr[i18] < 0) {
                                        i18 = i11 + 8;
                                        if (bArr[i16] < 0) {
                                            i16 = i11 + 9;
                                            if (bArr[i18] < 0) {
                                                int i21 = i11 + 10;
                                                if (bArr[i16] >= 0) {
                                                    i14 = i21;
                                                    i10 = i20;
                                                }
                                            }
                                        }
                                    }
                                }
                                i10 = i20;
                            }
                            i10 = i20;
                        }
                        i14 = i18;
                    }
                    i14 = i16;
                }
                this.f21148f = i14;
                return i10;
            }
        }
        return (int) g();
    }

    public final int d() throws zzadi {
        if (h()) {
            this.f21149g = 0;
            return 0;
        }
        int iC = c();
        this.f21149g = iC;
        if ((iC >>> 3) != 0) {
            return iC;
        }
        throw new zzadi("Protocol message contained an invalid tag (zero).");
    }

    public final long e() throws zzadi {
        int i10 = this.f21148f;
        if (this.f21146d - i10 < 8) {
            throw zzadi.f();
        }
        this.f21148f = i10 + 8;
        byte[] bArr = this.f21145c;
        return ((((long) bArr[i10 + 7]) & 255) << 56) | (((long) bArr[i10]) & 255) | ((((long) bArr[i10 + 1]) & 255) << 8) | ((((long) bArr[i10 + 2]) & 255) << 16) | ((((long) bArr[i10 + 3]) & 255) << 24) | ((((long) bArr[i10 + 4]) & 255) << 32) | ((((long) bArr[i10 + 5]) & 255) << 40) | ((((long) bArr[i10 + 6]) & 255) << 48);
    }

    public final long f() {
        long j10;
        long j11;
        long j12;
        int i10 = this.f21148f;
        int i11 = this.f21146d;
        if (i11 != i10) {
            int i12 = i10 + 1;
            byte[] bArr = this.f21145c;
            byte b10 = bArr[i10];
            if (b10 >= 0) {
                this.f21148f = i12;
                return b10;
            }
            if (i11 - i12 >= 9) {
                int i13 = i10 + 2;
                int i14 = (bArr[i12] << 7) ^ b10;
                if (i14 < 0) {
                    j10 = i14 ^ (-128);
                } else {
                    int i15 = i10 + 3;
                    int i16 = (bArr[i13] << 14) ^ i14;
                    if (i16 >= 0) {
                        j10 = i16 ^ 16256;
                    } else {
                        int i17 = i10 + 4;
                        int i18 = i16 ^ (bArr[i15] << 21);
                        if (i18 < 0) {
                            long j13 = (-2080896) ^ i18;
                            i13 = i17;
                            j10 = j13;
                        } else {
                            i15 = i10 + 5;
                            long j14 = (((long) bArr[i17]) << 28) ^ ((long) i18);
                            if (j14 >= 0) {
                                j12 = 266354560;
                            } else {
                                int i19 = i10 + 6;
                                long j15 = j14 ^ (((long) bArr[i15]) << 35);
                                if (j15 < 0) {
                                    j11 = -34093383808L;
                                } else {
                                    i15 = i10 + 7;
                                    j14 = j15 ^ (((long) bArr[i19]) << 42);
                                    if (j14 >= 0) {
                                        j12 = 4363953127296L;
                                    } else {
                                        i19 = i10 + 8;
                                        j15 = j14 ^ (((long) bArr[i15]) << 49);
                                        if (j15 < 0) {
                                            j11 = -558586000294016L;
                                        } else {
                                            i15 = i10 + 9;
                                            long j16 = (j15 ^ (((long) bArr[i19]) << 56)) ^ 71499008037633920L;
                                            if (j16 < 0) {
                                                int i20 = i10 + 10;
                                                if (bArr[i15] >= 0) {
                                                    j10 = j16;
                                                    i13 = i20;
                                                }
                                            } else {
                                                j10 = j16;
                                            }
                                        }
                                    }
                                }
                                j10 = j15 ^ j11;
                                i13 = i19;
                            }
                            j10 = j14 ^ j12;
                        }
                    }
                    i13 = i15;
                }
                this.f21148f = i13;
                return j10;
            }
        }
        return g();
    }

    public final long g() throws zzadi {
        long j10 = 0;
        for (int i10 = 0; i10 < 64; i10 += 7) {
            int i11 = this.f21148f;
            if (i11 == this.f21146d) {
                throw zzadi.f();
            }
            this.f21148f = i11 + 1;
            byte b10 = this.f21145c[i11];
            j10 |= ((long) (b10 & 127)) << i10;
            if ((b10 & 128) == 0) {
                return j10;
            }
        }
        throw new zzadi("CodedInputStream encountered a malformed varint.");
    }

    public final boolean h() {
        return this.f21148f == this.f21146d;
    }

    public final boolean i() {
        return f() != 0;
    }
}
