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

import com.google.crypto.tink.shaded.protobuf.ByteString;
import java.util.Arrays;

/* JADX INFO: loaded from: classes2.dex */
public final class j extends l {

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

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

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

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

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

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

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

    public j(byte[] bArr, int i10, int i11, boolean z10) {
        this.f23910e = bArr;
        this.f23911f = i11 + i10;
        this.f23913h = i10;
        this.f23914i = i10;
    }

    public final int A() throws InvalidProtocolBufferException {
        int i10 = this.f23913h;
        if (this.f23911f - i10 < 4) {
            throw InvalidProtocolBufferException.j();
        }
        this.f23913h = i10 + 4;
        byte[] bArr = this.f23910e;
        return ((bArr[i10 + 3] & 255) << 24) | (bArr[i10] & 255) | ((bArr[i10 + 1] & 255) << 8) | ((bArr[i10 + 2] & 255) << 16);
    }

    public final long B() throws InvalidProtocolBufferException {
        int i10 = this.f23913h;
        if (this.f23911f - i10 < 8) {
            throw InvalidProtocolBufferException.j();
        }
        this.f23913h = i10 + 8;
        byte[] bArr = this.f23910e;
        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 int C() {
        int i10;
        int i11 = this.f23913h;
        int i12 = this.f23911f;
        if (i12 != i11) {
            int i13 = i11 + 1;
            byte[] bArr = this.f23910e;
            byte b10 = bArr[i11];
            if (b10 >= 0) {
                this.f23913h = 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.f23913h = i14;
                return i10;
            }
        }
        return (int) E();
    }

    public final long D() {
        long j10;
        long j11;
        long j12;
        long j13;
        int i10 = this.f23913h;
        int i11 = this.f23911f;
        if (i11 != i10) {
            int i12 = i10 + 1;
            byte[] bArr = this.f23910e;
            byte b10 = bArr[i10];
            if (b10 >= 0) {
                this.f23913h = 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;
                        i13 = i15;
                    } else {
                        int i17 = i10 + 4;
                        int i18 = i16 ^ (bArr[i15] << 21);
                        if (i18 < 0) {
                            j13 = (-2080896) ^ i18;
                        } else {
                            long j14 = i18;
                            i13 = i10 + 5;
                            long j15 = j14 ^ (((long) bArr[i17]) << 28);
                            if (j15 >= 0) {
                                j12 = 266354560;
                            } else {
                                i17 = i10 + 6;
                                long j16 = j15 ^ (((long) bArr[i13]) << 35);
                                if (j16 < 0) {
                                    j11 = -34093383808L;
                                } else {
                                    i13 = i10 + 7;
                                    j15 = j16 ^ (((long) bArr[i17]) << 42);
                                    if (j15 >= 0) {
                                        j12 = 4363953127296L;
                                    } else {
                                        i17 = i10 + 8;
                                        j16 = j15 ^ (((long) bArr[i13]) << 49);
                                        if (j16 < 0) {
                                            j11 = -558586000294016L;
                                        } else {
                                            i13 = i10 + 9;
                                            long j17 = (j16 ^ (((long) bArr[i17]) << 56)) ^ 71499008037633920L;
                                            if (j17 < 0) {
                                                int i19 = i10 + 10;
                                                if (bArr[i13] >= 0) {
                                                    i13 = i19;
                                                }
                                            }
                                            j10 = j17;
                                        }
                                    }
                                }
                                j13 = j11 ^ j16;
                            }
                            j10 = j12 ^ j15;
                        }
                        i13 = i17;
                        j10 = j13;
                    }
                }
                this.f23913h = i13;
                return j10;
            }
        }
        return E();
    }

    public final long E() throws InvalidProtocolBufferException {
        long j10 = 0;
        for (int i10 = 0; i10 < 64; i10 += 7) {
            int i11 = this.f23913h;
            if (i11 == this.f23911f) {
                throw InvalidProtocolBufferException.j();
            }
            this.f23913h = i11 + 1;
            byte b10 = this.f23910e[i11];
            j10 |= ((long) (b10 & 127)) << i10;
            if ((b10 & 128) == 0) {
                return j10;
            }
        }
        throw InvalidProtocolBufferException.e();
    }

    public final void F() {
        int i10 = this.f23911f + this.f23912g;
        this.f23911f = i10;
        int i11 = i10 - this.f23914i;
        int i12 = this.f23916k;
        if (i11 <= i12) {
            this.f23912g = 0;
            return;
        }
        int i13 = i11 - i12;
        this.f23912g = i13;
        this.f23911f = i10 - i13;
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final void a(int i10) {
        if (this.f23915j != i10) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int d() {
        return this.f23913h - this.f23914i;
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final boolean e() {
        return this.f23913h == this.f23911f;
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final void g(int i10) {
        this.f23916k = i10;
        F();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int h(int i10) throws InvalidProtocolBufferException {
        if (i10 < 0) {
            throw InvalidProtocolBufferException.f();
        }
        int iD = d() + i10;
        if (iD < 0) {
            throw new InvalidProtocolBufferException("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 i11 = this.f23916k;
        if (iD > i11) {
            throw InvalidProtocolBufferException.j();
        }
        this.f23916k = iD;
        F();
        return i11;
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final boolean i() {
        return D() != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x002f  */
    @Override // com.google.crypto.tink.shaded.protobuf.l
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final ByteString j() throws InvalidProtocolBufferException {
        byte[] bArrCopyOfRange;
        int iC = C();
        byte[] bArr = this.f23910e;
        if (iC > 0) {
            int i10 = this.f23911f;
            int i11 = this.f23913h;
            if (iC <= i10 - i11) {
                ByteString byteStringG = ByteString.g(i11, iC, bArr);
                this.f23913h += iC;
                return byteStringG;
            }
        }
        if (iC == 0) {
            return ByteString.f23846a;
        }
        if (iC > 0) {
            int i12 = this.f23911f;
            int i13 = this.f23913h;
            if (iC <= i12 - i13) {
                int i14 = iC + i13;
                this.f23913h = i14;
                bArrCopyOfRange = Arrays.copyOfRange(bArr, i13, i14);
            } else {
                if (iC > 0) {
                    throw InvalidProtocolBufferException.j();
                }
                if (iC != 0) {
                    throw InvalidProtocolBufferException.f();
                }
                bArrCopyOfRange = b0.f23883b;
            }
        }
        ByteString byteString = ByteString.f23846a;
        return new ByteString.LiteralByteString(bArrCopyOfRange);
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final double k() {
        return Double.longBitsToDouble(B());
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int l() {
        return C();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int m() {
        return A();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final long n() {
        return B();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final float o() {
        return Float.intBitsToFloat(A());
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int p() {
        return C();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final long q() {
        return D();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int r() {
        return A();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final long s() {
        return B();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int t() {
        return l.b(C());
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final long u() {
        return l.c(D());
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final String v() throws InvalidProtocolBufferException {
        int iC = C();
        if (iC > 0) {
            int i10 = this.f23911f;
            int i11 = this.f23913h;
            if (iC <= i10 - i11) {
                String str = new String(this.f23910e, i11, iC, b0.f23882a);
                this.f23913h += iC;
                return str;
            }
        }
        if (iC == 0) {
            return "";
        }
        if (iC < 0) {
            throw InvalidProtocolBufferException.f();
        }
        throw InvalidProtocolBufferException.j();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final String w() throws InvalidProtocolBufferException {
        int iC = C();
        if (iC > 0) {
            int i10 = this.f23911f;
            int i11 = this.f23913h;
            if (iC <= i10 - i11) {
                String strW = n1.f23950a.W(i11, iC, this.f23910e);
                this.f23913h += iC;
                return strW;
            }
        }
        if (iC == 0) {
            return "";
        }
        if (iC <= 0) {
            throw InvalidProtocolBufferException.f();
        }
        throw InvalidProtocolBufferException.j();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int x() throws InvalidProtocolBufferException {
        if (e()) {
            this.f23915j = 0;
            return 0;
        }
        int iC = C();
        this.f23915j = iC;
        if ((iC >>> 3) != 0) {
            return iC;
        }
        throw InvalidProtocolBufferException.b();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final int y() {
        return C();
    }

    @Override // com.google.crypto.tink.shaded.protobuf.l
    public final long z() {
        return D();
    }
}
