package androidx.datastore.preferences.protobuf;

import androidx.datastore.preferences.protobuf.ByteString;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class i extends k {

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

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

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

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

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

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

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

    public i(byte[] bArr, int i10, int i11, boolean z10) {
        this.f2081e = bArr;
        this.f2082f = i11 + i10;
        this.f2084h = i10;
        this.f2085i = i10;
    }

    public final long A() throws InvalidProtocolBufferException {
        int i10 = this.f2084h;
        if (this.f2082f - i10 < 8) {
            throw InvalidProtocolBufferException.h();
        }
        this.f2084h = i10 + 8;
        byte[] bArr = this.f2081e;
        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 B() {
        int i10;
        int i11 = this.f2084h;
        int i12 = this.f2082f;
        if (i12 != i11) {
            int i13 = i11 + 1;
            byte[] bArr = this.f2081e;
            byte b10 = bArr[i11];
            if (b10 >= 0) {
                this.f2084h = 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.f2084h = i14;
                return i10;
            }
        }
        return (int) D();
    }

    public final long C() {
        long j10;
        long j11;
        long j12;
        long j13;
        int i10 = this.f2084h;
        int i11 = this.f2082f;
        if (i11 != i10) {
            int i12 = i10 + 1;
            byte[] bArr = this.f2081e;
            byte b10 = bArr[i10];
            if (b10 >= 0) {
                this.f2084h = 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.f2084h = i13;
                return j10;
            }
        }
        return D();
    }

    public final long D() throws InvalidProtocolBufferException {
        long j10 = 0;
        for (int i10 = 0; i10 < 64; i10 += 7) {
            int i11 = this.f2084h;
            if (i11 == this.f2082f) {
                throw InvalidProtocolBufferException.h();
            }
            this.f2084h = i11 + 1;
            byte b10 = this.f2081e[i11];
            j10 |= ((long) (b10 & 127)) << i10;
            if ((b10 & 128) == 0) {
                return j10;
            }
        }
        throw InvalidProtocolBufferException.d();
    }

    public final void E() {
        int i10 = this.f2082f + this.f2083g;
        this.f2082f = i10;
        int i11 = i10 - this.f2085i;
        int i12 = this.f2087k;
        if (i11 <= i12) {
            this.f2083g = 0;
            return;
        }
        int i13 = i11 - i12;
        this.f2083g = i13;
        this.f2082f = i10 - i13;
    }

    public final void F(int i10) throws InvalidProtocolBufferException {
        if (i10 >= 0) {
            int i11 = this.f2082f;
            int i12 = this.f2084h;
            if (i10 <= i11 - i12) {
                this.f2084h = i12 + i10;
                return;
            }
        }
        if (i10 >= 0) {
            throw InvalidProtocolBufferException.h();
        }
        throw InvalidProtocolBufferException.e();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final void a(int i10) throws InvalidProtocolBufferException {
        if (this.f2086j != i10) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int b() {
        return this.f2084h - this.f2085i;
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final boolean c() {
        return this.f2084h == this.f2082f;
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final void d(int i10) {
        this.f2087k = i10;
        E();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int e(int i10) throws InvalidProtocolBufferException {
        if (i10 < 0) {
            throw InvalidProtocolBufferException.e();
        }
        int iB = b() + i10;
        if (iB < 0) {
            throw new InvalidProtocolBufferException("Failed to parse the message.");
        }
        int i11 = this.f2087k;
        if (iB > i11) {
            throw InvalidProtocolBufferException.h();
        }
        this.f2087k = iB;
        E();
        return i11;
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final boolean f() {
        return C() != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x002f  */
    @Override // androidx.datastore.preferences.protobuf.k
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final ByteString g() throws InvalidProtocolBufferException {
        byte[] bArrCopyOfRange;
        int iB = B();
        byte[] bArr = this.f2081e;
        if (iB > 0) {
            int i10 = this.f2082f;
            int i11 = this.f2084h;
            if (iB <= i10 - i11) {
                ByteString byteStringG = ByteString.g(i11, iB, bArr);
                this.f2084h += iB;
                return byteStringG;
            }
        }
        if (iB == 0) {
            return ByteString.f1995a;
        }
        if (iB > 0) {
            int i12 = this.f2082f;
            int i13 = this.f2084h;
            if (iB <= i12 - i13) {
                int i14 = iB + i13;
                this.f2084h = i14;
                bArrCopyOfRange = Arrays.copyOfRange(bArr, i13, i14);
            } else {
                if (iB > 0) {
                    throw InvalidProtocolBufferException.h();
                }
                if (iB != 0) {
                    throw InvalidProtocolBufferException.e();
                }
                bArrCopyOfRange = b0.f2048b;
            }
        }
        ByteString byteString = ByteString.f1995a;
        return new ByteString.LiteralByteString(bArrCopyOfRange);
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final double h() {
        return Double.longBitsToDouble(A());
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int i() {
        return B();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int j() {
        return z();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final long k() {
        return A();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final float l() {
        return Float.intBitsToFloat(z());
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int m() {
        return B();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final long n() {
        return C();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int o() {
        return z();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final long p() {
        return A();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int q() {
        int iB = B();
        return (-(iB & 1)) ^ (iB >>> 1);
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final long r() {
        long jC = C();
        return (-(jC & 1)) ^ (jC >>> 1);
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final String s() throws InvalidProtocolBufferException {
        int iB = B();
        if (iB > 0) {
            int i10 = this.f2082f;
            int i11 = this.f2084h;
            if (iB <= i10 - i11) {
                String str = new String(this.f2081e, i11, iB, b0.f2047a);
                this.f2084h += iB;
                return str;
            }
        }
        if (iB == 0) {
            return "";
        }
        if (iB < 0) {
            throw InvalidProtocolBufferException.e();
        }
        throw InvalidProtocolBufferException.h();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final String t() throws InvalidProtocolBufferException {
        int iB = B();
        if (iB > 0) {
            int i10 = this.f2082f;
            int i11 = this.f2084h;
            if (iB <= i10 - i11) {
                String strI = p1.f2130a.i(i11, iB, this.f2081e);
                this.f2084h += iB;
                return strI;
            }
        }
        if (iB == 0) {
            return "";
        }
        if (iB <= 0) {
            throw InvalidProtocolBufferException.e();
        }
        throw InvalidProtocolBufferException.h();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int u() throws InvalidProtocolBufferException {
        if (c()) {
            this.f2086j = 0;
            return 0;
        }
        int iB = B();
        this.f2086j = iB;
        if ((iB >>> 3) != 0) {
            return iB;
        }
        throw new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final int v() {
        return B();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final long w() {
        return C();
    }

    @Override // androidx.datastore.preferences.protobuf.k
    public final boolean x(int i10) throws InvalidProtocolBufferException {
        int i11 = i10 & 7;
        int i12 = 0;
        if (i11 != 0) {
            if (i11 == 1) {
                F(8);
                return true;
            }
            if (i11 == 2) {
                F(B());
                return true;
            }
            if (i11 == 3) {
                y();
                a(((i10 >>> 3) << 3) | 4);
                return true;
            }
            if (i11 == 4) {
                return false;
            }
            if (i11 != 5) {
                throw InvalidProtocolBufferException.c();
            }
            F(4);
            return true;
        }
        int i13 = this.f2082f - this.f2084h;
        byte[] bArr = this.f2081e;
        if (i13 >= 10) {
            while (i12 < 10) {
                int i14 = this.f2084h;
                this.f2084h = i14 + 1;
                if (bArr[i14] < 0) {
                    i12++;
                }
            }
            throw InvalidProtocolBufferException.d();
        }
        while (i12 < 10) {
            int i15 = this.f2084h;
            if (i15 == this.f2082f) {
                throw InvalidProtocolBufferException.h();
            }
            this.f2084h = i15 + 1;
            if (bArr[i15] < 0) {
                i12++;
            }
        }
        throw InvalidProtocolBufferException.d();
        return true;
    }

    public final int z() throws InvalidProtocolBufferException {
        int i10 = this.f2084h;
        if (this.f2082f - i10 < 4) {
            throw InvalidProtocolBufferException.h();
        }
        this.f2084h = i10 + 4;
        byte[] bArr = this.f2081e;
        return ((bArr[i10 + 3] & 255) << 24) | (bArr[i10] & 255) | ((bArr[i10 + 1] & 255) << 8) | ((bArr[i10 + 2] & 255) << 16);
    }
}
