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

import java.util.Arrays;

/* JADX INFO: loaded from: classes2.dex */
public final class ka2 extends ma2 {

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

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

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

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

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

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

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

    public /* synthetic */ ka2(byte[] bArr, int i10, int i11) {
        this.f13197d = bArr;
        this.f13198e = i11 + i10;
        this.f13200g = i10;
        this.f13201h = i10;
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int A() {
        return ma2.g(F());
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final long B() {
        return ma2.h(G());
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int C(int i10) throws zzicg {
        if (i10 < 0) {
            throw new zzicg("CodedInputStream encountered an embedded string or message which claimed to have negative size.");
        }
        int i11 = (this.f13200g - this.f13201h) + i10;
        if (i11 < 0) {
            throw new zzicg("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit. If reading multiple messages, consider resetting the counter between each message using CodedInputStream.resetSizeCounter().");
        }
        int i12 = this.f13203j;
        if (i11 > i12) {
            throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
        }
        this.f13203j = i11;
        E();
        return i12;
    }

    public final void D(int i10) throws zzicg {
        if (i10 >= 0) {
            int i11 = this.f13198e;
            int i12 = this.f13200g;
            if (i10 <= i11 - i12) {
                this.f13200g = i12 + i10;
                return;
            }
        }
        if (i10 >= 0) {
            throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
        }
        throw new zzicg("CodedInputStream encountered an embedded string or message which claimed to have negative size.");
    }

    public final void E() {
        int i10 = this.f13198e + this.f13199f;
        this.f13198e = i10;
        int i11 = i10 - this.f13201h;
        int i12 = this.f13203j;
        if (i11 <= i12) {
            this.f13199f = 0;
            return;
        }
        int i13 = i11 - i12;
        this.f13199f = i13;
        this.f13198e = i10 - i13;
    }

    public final int F() {
        int i10;
        int i11 = this.f13200g;
        int i12 = this.f13198e;
        if (i12 != i11) {
            int i13 = i11 + 1;
            byte[] bArr = this.f13197d;
            byte b10 = bArr[i11];
            if (b10 >= 0) {
                this.f13200g = 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.f13200g = i14;
                return i10;
            }
        }
        return (int) H();
    }

    public final long G() {
        long j10;
        long j11;
        long j12;
        int i10 = this.f13200g;
        int i11 = this.f13198e;
        if (i11 != i10) {
            int i12 = i10 + 1;
            byte[] bArr = this.f13197d;
            byte b10 = bArr[i10];
            if (b10 >= 0) {
                this.f13200g = 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) i18) ^ (((long) bArr[i17]) << 28);
                            if (j14 >= 0) {
                                j11 = 266354560;
                            } else {
                                int i19 = i10 + 6;
                                long j15 = j14 ^ (((long) bArr[i15]) << 35);
                                if (j15 < 0) {
                                    j12 = -34093383808L;
                                } else {
                                    i15 = i10 + 7;
                                    j14 = j15 ^ (((long) bArr[i19]) << 42);
                                    if (j14 >= 0) {
                                        j11 = 4363953127296L;
                                    } else {
                                        i19 = i10 + 8;
                                        j15 = j14 ^ (((long) bArr[i15]) << 49);
                                        if (j15 < 0) {
                                            j12 = -558586000294016L;
                                        } else {
                                            i15 = i10 + 9;
                                            j14 = j15 ^ (((long) bArr[i19]) << 56);
                                            if (j14 >= 0) {
                                                j11 = 71499008037633920L;
                                            } else {
                                                int i20 = i10 + 10;
                                                long j16 = j14 ^ (((long) bArr[i15]) << 63);
                                                if (j16 >= 0) {
                                                    j10 = j16 ^ (-9151873028817141888L);
                                                    i13 = i20;
                                                }
                                            }
                                        }
                                    }
                                }
                                j10 = j15 ^ j12;
                                i13 = i19;
                            }
                            j10 = j14 ^ j11;
                        }
                    }
                    i13 = i15;
                }
                this.f13200g = i13;
                return j10;
            }
        }
        return H();
    }

    public final long H() throws zzicg {
        long j10 = 0;
        for (int i10 = 0; i10 < 64; i10 += 7) {
            int i11 = this.f13200g;
            if (i11 == this.f13198e) {
                throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
            }
            this.f13200g = i11 + 1;
            byte b10 = this.f13197d[i11];
            j10 |= ((long) (b10 & 127)) << i10;
            if ((b10 & 128) == 0) {
                return j10;
            }
        }
        throw new zzicg("CodedInputStream encountered a malformed varint.");
    }

    public final int I() throws zzicg {
        int i10 = this.f13200g;
        if (this.f13198e - i10 < 4) {
            throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
        }
        this.f13200g = i10 + 4;
        byte[] bArr = this.f13197d;
        int i11 = bArr[i10] & 255;
        int i12 = bArr[i10 + 1] & 255;
        int i13 = bArr[i10 + 2] & 255;
        return ((bArr[i10 + 3] & 255) << 24) | (i12 << 8) | i11 | (i13 << 16);
    }

    public final long J() throws zzicg {
        int i10 = this.f13200g;
        if (this.f13198e - i10 < 8) {
            throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
        }
        this.f13200g = i10 + 8;
        byte[] bArr = this.f13197d;
        long j10 = bArr[i10];
        long j11 = (((long) bArr[i10 + 1]) & 255) << 8;
        long j12 = bArr[i10 + 2];
        long j13 = bArr[i10 + 3];
        return ((((long) bArr[i10 + 7]) & 255) << 56) | (j10 & 255) | j11 | ((j12 & 255) << 16) | ((j13 & 255) << 24) | ((bArr[i10 + 4] & 255) << 32) | ((bArr[i10 + 5] & 255) << 40) | ((bArr[i10 + 6] & 255) << 48);
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final void a(int i10) {
        this.f13203j = i10;
        E();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final boolean b() {
        return this.f13200g == this.f13198e;
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int c() {
        return this.f13200g - this.f13201h;
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int i() throws zzicg {
        if (b()) {
            this.f13202i = 0;
            return 0;
        }
        int iF = F();
        this.f13202i = iF;
        if ((iF >>> 3) != 0) {
            return iF;
        }
        throw new zzicg("Protocol message contained an invalid tag (zero).");
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final void j(int i10) throws zzicg {
        if (this.f13202i != i10) {
            throw new zzicg("Protocol message end-group tag did not match expected tag.");
        }
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final boolean k(int i10) throws zzicg {
        int i11 = i10 & 7;
        int i12 = 0;
        if (i11 != 0) {
            if (i11 == 1) {
                D(8);
                return true;
            }
            if (i11 == 2) {
                D(F());
                return true;
            }
            if (i11 == 3) {
                f();
                j(((i10 >>> 3) << 3) | 4);
                return true;
            }
            if (i11 == 4) {
                if (this.f14050b == 0) {
                    j(0);
                }
                return false;
            }
            if (i11 != 5) {
                throw new zzicf();
            }
            D(4);
            return true;
        }
        int i13 = this.f13198e - this.f13200g;
        byte[] bArr = this.f13197d;
        if (i13 >= 10) {
            while (i12 < 10) {
                int i14 = this.f13200g;
                this.f13200g = i14 + 1;
                if (bArr[i14] < 0) {
                    i12++;
                }
            }
            throw new zzicg("CodedInputStream encountered a malformed varint.");
        }
        while (i12 < 10) {
            int i15 = this.f13200g;
            if (i15 == this.f13198e) {
                throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
            }
            this.f13200g = i15 + 1;
            if (bArr[i15] < 0) {
                i12++;
            }
        }
        throw new zzicg("CodedInputStream encountered a malformed varint.");
        return true;
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final double l() {
        return Double.longBitsToDouble(J());
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final float m() {
        return Float.intBitsToFloat(I());
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final long n() {
        return G();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final long o() {
        return G();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int p() {
        return F();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final long q() {
        return J();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int r() {
        return I();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final boolean s() {
        return G() != 0;
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final String t() throws zzicg {
        int iF = F();
        if (iF > 0) {
            int i10 = this.f13198e;
            int i11 = this.f13200g;
            if (iF <= i10 - i11) {
                String str = new String(this.f13197d, i11, iF, kb2.f13211a);
                this.f13200g += iF;
                return str;
            }
        }
        if (iF == 0) {
            return "";
        }
        if (iF < 0) {
            throw new zzicg("CodedInputStream encountered an embedded string or message which claimed to have negative size.");
        }
        throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final String u() throws zzicg {
        int iF = F();
        if (iF > 0) {
            int i10 = this.f13198e;
            int i11 = this.f13200g;
            if (iF <= i10 - i11) {
                String strD = tc2.d(i11, iF, this.f13197d);
                this.f13200g += iF;
                return strD;
            }
        }
        if (iF == 0) {
            return "";
        }
        if (iF <= 0) {
            throw new zzicg("CodedInputStream encountered an embedded string or message which claimed to have negative size.");
        }
        throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final zzian v() throws zzicg {
        int iF = F();
        byte[] bArr = this.f13197d;
        if (iF > 0) {
            int i10 = this.f13198e;
            int i11 = this.f13200g;
            if (iF <= i10 - i11) {
                zzian zzianVarX = zzian.x(bArr, i11, iF);
                this.f13200g += iF;
                return zzianVarX;
            }
        }
        if (iF == 0) {
            return zzian.f19856a;
        }
        if (iF > 0) {
            int i12 = this.f13198e;
            int i13 = this.f13200g;
            if (iF <= i12 - i13) {
                int i14 = iF + i13;
                this.f13200g = i14;
                byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, i13, i14);
                zzian zzianVar = zzian.f19856a;
                return new zzial(bArrCopyOfRange);
            }
        }
        if (iF <= 0) {
            throw new zzicg("CodedInputStream encountered an embedded string or message which claimed to have negative size.");
        }
        throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int w() {
        return F();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int x() {
        return F();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final int y() {
        return I();
    }

    @Override // com.google.android.gms.internal.ads.ma2
    public final long z() {
        return J();
    }
}
