package androidx.datastore.preferences.protobuf;

import defpackage.AbstractC0793;
import defpackage.AbstractC2638;
import defpackage.AbstractC2956;
import defpackage.AbstractC3332;
import defpackage.C3056;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;

/* JADX INFO: renamed from: androidx.datastore.preferences.protobuf.ːˏᵟᵯ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0003 extends AbstractC2638 {

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public int f340;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final FileInputStream f341;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public int f342;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public int f343 = Integer.MAX_VALUE;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public int f344;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final byte[] f345;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public int f346;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public int f347;

    public C0003(FileInputStream fileInputStream) {
        Charset charset = AbstractC2956.f11367;
        this.f341 = fileInputStream;
        this.f345 = new byte[4096];
        this.f342 = 0;
        this.f344 = 0;
        this.f346 = 0;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo99(int i) throws InvalidProtocolBufferException {
        if (this.f340 != i) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    /* JADX INFO: renamed from: ʽᵡᵢᵾ, reason: contains not printable characters */
    public final long m139() throws InvalidProtocolBufferException {
        long j = 0;
        for (int i = 0; i < 64; i += 7) {
            if (this.f344 == this.f342) {
                m149(1);
            }
            int i2 = this.f344;
            this.f344 = i2 + 1;
            byte b = this.f345[i2];
            j |= ((long) (b & 127)) << i;
            if ((b & 128) == 0) {
                return j;
            }
        }
        throw InvalidProtocolBufferException.m95();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ʿٴˇ */
    public final boolean mo100(int i) throws InvalidProtocolBufferException {
        int i2 = i & 7;
        int i3 = 0;
        if (i2 != 0) {
            if (i2 == 1) {
                m148(8);
                return true;
            }
            if (i2 == 2) {
                m148(m150());
                return true;
            }
            if (i2 == 3) {
                m6411();
                mo99(((i >>> 3) << 3) | 4);
                return true;
            }
            if (i2 == 4) {
                return false;
            }
            if (i2 != 5) {
                throw InvalidProtocolBufferException.m94();
            }
            m148(4);
            return true;
        }
        int i4 = this.f342 - this.f344;
        byte[] bArr = this.f345;
        if (i4 >= 10) {
            while (i3 < 10) {
                int i5 = this.f344;
                this.f344 = i5 + 1;
                if (bArr[i5] < 0) {
                    i3++;
                }
            }
            throw InvalidProtocolBufferException.m95();
        }
        while (i3 < 10) {
            if (this.f344 == this.f342) {
                m149(1);
            }
            int i6 = this.f344;
            this.f344 = i6 + 1;
            if (bArr[i6] < 0) {
                i3++;
            }
        }
        throw InvalidProtocolBufferException.m95();
        return true;
    }

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public final byte[] m140(int i) throws IOException {
        if (i == 0) {
            return AbstractC2956.f11366;
        }
        if (i < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        int i2 = this.f346;
        int i3 = this.f344;
        int i4 = i2 + i3 + i;
        if (i4 - Integer.MAX_VALUE > 0) {
            throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit.");
        }
        int i5 = this.f343;
        if (i4 > i5) {
            m148((i5 - i2) - i3);
            throw InvalidProtocolBufferException.m96();
        }
        int i6 = this.f342 - i3;
        int i7 = i - i6;
        FileInputStream fileInputStream = this.f341;
        if (i7 >= 4096) {
            try {
                if (i7 > fileInputStream.available()) {
                    return null;
                }
            } catch (InvalidProtocolBufferException e) {
                e.f329 = true;
                throw e;
            }
        }
        byte[] bArr = new byte[i];
        System.arraycopy(this.f345, this.f344, bArr, 0, i6);
        this.f346 += this.f342;
        this.f344 = 0;
        this.f342 = 0;
        while (i6 < i) {
            try {
                int i8 = fileInputStream.read(bArr, i6, i - i6);
                if (i8 == -1) {
                    throw InvalidProtocolBufferException.m96();
                }
                this.f346 += i8;
                i6 += i8;
            } catch (InvalidProtocolBufferException e2) {
                e2.f329 = true;
                throw e2;
            }
        }
        return bArr;
    }

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public final byte[] m141(int i) throws IOException {
        byte[] bArrM140 = m140(i);
        if (bArrM140 != null) {
            return bArrM140;
        }
        int i2 = this.f344;
        int i3 = this.f342;
        int length = i3 - i2;
        this.f346 += i3;
        this.f344 = 0;
        this.f342 = 0;
        ArrayList arrayListM145 = m145(i - length);
        byte[] bArr = new byte[i];
        System.arraycopy(this.f345, i2, bArr, 0, length);
        int size = arrayListM145.size();
        int i4 = 0;
        while (i4 < size) {
            Object obj = arrayListM145.get(i4);
            i4++;
            byte[] bArr2 = (byte[]) obj;
            System.arraycopy(bArr2, 0, bArr, length, bArr2.length);
            length += bArr2.length;
        }
        return bArr;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˈᵲᵢ */
    public final String mo103() throws IOException {
        int iM150 = m150();
        int i = this.f344;
        int i2 = this.f342;
        int i3 = i2 - i;
        byte[] bArrM141 = this.f345;
        if (iM150 <= i3 && iM150 > 0) {
            this.f344 = i + iM150;
        } else {
            if (iM150 == 0) {
                return "";
            }
            if (iM150 < 0) {
                throw InvalidProtocolBufferException.m98();
            }
            i = 0;
            if (iM150 <= i2) {
                m149(iM150);
                this.f344 = iM150;
            } else {
                bArrM141 = m141(iM150);
            }
        }
        return AbstractC3332.f12789.ᵪᵹᵥᵻ(bArrM141, i, iM150);
    }

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public final void m142() {
        int i = this.f342 + this.f347;
        this.f342 = i;
        int i2 = this.f346 + i;
        int i3 = this.f343;
        if (i2 <= i3) {
            this.f347 = 0;
            return;
        }
        int i4 = i2 - i3;
        this.f347 = i4;
        this.f342 = i - i4;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˉᵲ */
    public final long mo104() {
        return m147();
    }

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public final boolean m143(int i) throws IOException {
        FileInputStream fileInputStream = this.f341;
        int i2 = this.f344;
        int i3 = i2 + i;
        int i4 = this.f342;
        if (i3 <= i4) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ(AbstractC0793.m2876(i, "refillBuffer() called when ", " bytes were already available in buffer"));
            return false;
        }
        int i5 = this.f346;
        if (i <= (Integer.MAX_VALUE - i5) - i2 && i5 + i2 + i <= this.f343) {
            byte[] bArr = this.f345;
            if (i2 > 0) {
                if (i4 > i2) {
                    System.arraycopy(bArr, i2, bArr, 0, i4 - i2);
                }
                this.f346 += i2;
                this.f342 -= i2;
                this.f344 = 0;
            }
            int i6 = this.f342;
            try {
                int i7 = fileInputStream.read(bArr, i6, Math.min(bArr.length - i6, (Integer.MAX_VALUE - this.f346) - i6));
                if (i7 == 0 || i7 < -1 || i7 > bArr.length) {
                    throw new IllegalStateException(fileInputStream.getClass() + "#read(byte[]) returned invalid result: " + i7 + "\nThe InputStream implementation is buggy.");
                }
                if (i7 > 0) {
                    this.f342 += i7;
                    m142();
                    if (this.f342 >= i) {
                        return true;
                    }
                    return m143(i);
                }
            } catch (InvalidProtocolBufferException e) {
                e.f329 = true;
                throw e;
            }
        }
        return false;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˊᵙᵾᵲ */
    public final int mo105() {
        return m144();
    }

    /* JADX INFO: renamed from: ˊᵡᵗʨ, reason: contains not printable characters */
    public final int m144() throws InvalidProtocolBufferException {
        int i = this.f344;
        if (this.f342 - i < 4) {
            m149(4);
            i = this.f344;
        }
        this.f344 = i + 4;
        byte[] bArr = this.f345;
        return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˊᵨᵧ */
    public final int mo107() {
        return m150();
    }

    /* JADX INFO: renamed from: ˊᵾʽʼ, reason: contains not printable characters */
    public final ArrayList m145(int i) throws IOException {
        ArrayList arrayList = new ArrayList();
        while (i > 0) {
            int iMin = Math.min(i, 4096);
            byte[] bArr = new byte[iMin];
            int i2 = 0;
            while (i2 < iMin) {
                int i3 = this.f341.read(bArr, i2, iMin - i2);
                if (i3 == -1) {
                    throw InvalidProtocolBufferException.m96();
                }
                this.f346 += i3;
                i2 += i3;
            }
            i -= iMin;
            arrayList.add(bArr);
        }
        return arrayList;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˌᴵ */
    public final long mo109() {
        return m146();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˌᵨʠᵫ */
    public final int mo110() throws InvalidProtocolBufferException {
        if (mo126()) {
            this.f340 = 0;
            return 0;
        }
        int iM150 = m150();
        this.f340 = iM150;
        if ((iM150 >>> 3) != 0) {
            return iM150;
        }
        throw new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˏːˆ */
    public final float mo111() {
        return Float.intBitsToFloat(m144());
    }

    /* JADX INFO: renamed from: ˑʢ, reason: contains not printable characters */
    public final long m146() {
        long j;
        long j2;
        long j3;
        long j4;
        int i = this.f344;
        int i2 = this.f342;
        if (i2 != i) {
            int i3 = i + 1;
            byte[] bArr = this.f345;
            byte b = bArr[i];
            if (b >= 0) {
                this.f344 = i3;
                return b;
            }
            if (i2 - i3 >= 9) {
                int i4 = i + 2;
                int i5 = (bArr[i3] << 7) ^ b;
                if (i5 < 0) {
                    j = i5 ^ (-128);
                } else {
                    int i6 = i + 3;
                    int i7 = (bArr[i4] << 14) ^ i5;
                    if (i7 >= 0) {
                        j = i7 ^ 16256;
                        i4 = i6;
                    } else {
                        int i8 = i + 4;
                        int i9 = i7 ^ (bArr[i6] << 21);
                        if (i9 < 0) {
                            j4 = (-2080896) ^ i9;
                        } else {
                            long j5 = i9;
                            i4 = i + 5;
                            long j6 = j5 ^ (((long) bArr[i8]) << 28);
                            if (j6 >= 0) {
                                j3 = 266354560;
                            } else {
                                i8 = i + 6;
                                long j7 = j6 ^ (((long) bArr[i4]) << 35);
                                if (j7 < 0) {
                                    j2 = -34093383808L;
                                } else {
                                    i4 = i + 7;
                                    j6 = j7 ^ (((long) bArr[i8]) << 42);
                                    if (j6 >= 0) {
                                        j3 = 4363953127296L;
                                    } else {
                                        i8 = i + 8;
                                        j7 = j6 ^ (((long) bArr[i4]) << 49);
                                        if (j7 < 0) {
                                            j2 = -558586000294016L;
                                        } else {
                                            i4 = i + 9;
                                            long j8 = (j7 ^ (((long) bArr[i8]) << 56)) ^ 71499008037633920L;
                                            if (j8 < 0) {
                                                int i10 = i + 10;
                                                if (bArr[i4] >= 0) {
                                                    i4 = i10;
                                                }
                                            }
                                            j = j8;
                                        }
                                    }
                                }
                                j4 = j2 ^ j7;
                            }
                            j = j3 ^ j6;
                        }
                        i4 = i8;
                        j = j4;
                    }
                }
                this.f344 = i4;
                return j;
            }
        }
        return m139();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˑˊᵲ */
    public final long mo113() {
        return m146();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵔᵖᵹᵫ */
    public final long mo114() {
        return m147();
    }

    /* JADX INFO: renamed from: ᵛˑﹳ, reason: contains not printable characters */
    public final long m147() throws InvalidProtocolBufferException {
        int i = this.f344;
        if (this.f342 - i < 8) {
            m149(8);
            i = this.f344;
        }
        this.f344 = i + 8;
        byte[] bArr = this.f345;
        return ((((long) bArr[i + 1]) & 255) << 8) | (((long) bArr[i]) & 255) | ((((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) | ((((long) bArr[i + 7]) & 255) << 56);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵜᵪʾ */
    public final int mo116() {
        return m144();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵝᵶ */
    public final boolean mo117() {
        return m146() != 0;
    }

    /* JADX INFO: renamed from: ᵞᵛᵘ, reason: contains not printable characters */
    public final void m148(int i) throws InvalidProtocolBufferException {
        int i2 = this.f342;
        int i3 = this.f344;
        int i4 = i2 - i3;
        if (i <= i4 && i >= 0) {
            this.f344 = i3 + i;
            return;
        }
        FileInputStream fileInputStream = this.f341;
        if (i < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        int i5 = this.f346;
        int i6 = i5 + i3;
        int i7 = i6 + i;
        int i8 = this.f343;
        if (i7 > i8) {
            m148((i8 - i5) - i3);
            throw InvalidProtocolBufferException.m96();
        }
        this.f346 = i6;
        this.f342 = 0;
        this.f344 = 0;
        while (i4 < i) {
            long j = i - i4;
            try {
                try {
                    long jSkip = fileInputStream.skip(j);
                    if (jSkip < 0 || jSkip > j) {
                        throw new IllegalStateException(fileInputStream.getClass() + "#skip returned invalid result: " + jSkip + "\nThe InputStream implementation is buggy.");
                    }
                    if (jSkip == 0) {
                        break;
                    } else {
                        i4 += (int) jSkip;
                    }
                } catch (InvalidProtocolBufferException e) {
                    e.f329 = true;
                    throw e;
                }
            } catch (Throwable th) {
                this.f346 += i4;
                m142();
                throw th;
            }
        }
        this.f346 += i4;
        m142();
        if (i4 >= i) {
            return;
        }
        int i9 = this.f342;
        int i10 = i9 - this.f344;
        this.f344 = i9;
        m149(1);
        while (true) {
            int i11 = i - i10;
            int i12 = this.f342;
            if (i11 <= i12) {
                this.f344 = i11;
                return;
            } else {
                i10 += i12;
                this.f344 = i12;
                m149(1);
            }
        }
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵟᵹᵙ */
    public final double mo118() {
        return Double.longBitsToDouble(m147());
    }

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public final void m149(int i) throws InvalidProtocolBufferException {
        if (m143(i)) {
            return;
        }
        if (i <= (Integer.MAX_VALUE - this.f346) - this.f344) {
            throw InvalidProtocolBufferException.m96();
        }
        throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit.");
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵨᵼⁱ */
    public final int mo119() {
        int iM150 = m150();
        return (-(iM150 & 1)) ^ (iM150 >>> 1);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵪᵹᵥᵻ */
    public final C3056 mo120() throws IOException {
        int iM150 = m150();
        int i = this.f342;
        int i2 = this.f344;
        int i3 = i - i2;
        byte[] bArr = this.f345;
        if (iM150 <= i3 && iM150 > 0) {
            C3056 c3056M7154 = C3056.m7154(bArr, i2, iM150);
            this.f344 += iM150;
            return c3056M7154;
        }
        if (iM150 == 0) {
            return C3056.f11705;
        }
        if (iM150 < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        byte[] bArrM140 = m140(iM150);
        if (bArrM140 != null) {
            return C3056.m7154(bArrM140, 0, bArrM140.length);
        }
        int i4 = this.f344;
        int i5 = this.f342;
        int length = i5 - i4;
        this.f346 += i5;
        this.f344 = 0;
        this.f342 = 0;
        ArrayList arrayListM145 = m145(iM150 - length);
        byte[] bArr2 = new byte[iM150];
        System.arraycopy(bArr, i4, bArr2, 0, length);
        int size = arrayListM145.size();
        int i6 = 0;
        while (i6 < size) {
            Object obj = arrayListM145.get(i6);
            i6++;
            byte[] bArr3 = (byte[]) obj;
            System.arraycopy(bArr3, 0, bArr2, length, bArr3.length);
            length += bArr3.length;
        }
        C3056 c3056 = C3056.f11705;
        return new C3056(bArr2);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵮᵣᵗˈ */
    public final int mo121(int i) throws InvalidProtocolBufferException {
        if (i < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        int i2 = this.f346 + this.f344 + i;
        if (i2 < 0) {
            throw new InvalidProtocolBufferException("Failed to parse the message.");
        }
        int i3 = this.f343;
        if (i2 > i3) {
            throw InvalidProtocolBufferException.m96();
        }
        this.f343 = i2;
        m142();
        return i3;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵯᵷʽ */
    public final long mo122() {
        long jM146 = m146();
        return (-(jM146 & 1)) ^ (jM146 >>> 1);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵱʡˏ */
    public final int mo123() {
        return m150();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public final void mo124(int i) {
        this.f343 = i;
        m142();
    }

    /* JADX INFO: renamed from: ᵵᵬᵽ, reason: contains not printable characters */
    public final int m150() {
        int i;
        int i2 = this.f344;
        int i3 = this.f342;
        if (i3 != i2) {
            int i4 = i2 + 1;
            byte[] bArr = this.f345;
            byte b = bArr[i2];
            if (b >= 0) {
                this.f344 = i4;
                return b;
            }
            if (i3 - i4 >= 9) {
                int i5 = i2 + 2;
                int i6 = (bArr[i4] << 7) ^ b;
                if (i6 < 0) {
                    i = i6 ^ (-128);
                } else {
                    int i7 = i2 + 3;
                    int i8 = (bArr[i5] << 14) ^ i6;
                    if (i8 >= 0) {
                        i = i8 ^ 16256;
                    } else {
                        int i9 = i2 + 4;
                        int i10 = i8 ^ (bArr[i7] << 21);
                        if (i10 < 0) {
                            i = (-2080896) ^ i10;
                        } else {
                            i7 = i2 + 5;
                            byte b2 = bArr[i9];
                            int i11 = (i10 ^ (b2 << 28)) ^ 266354560;
                            if (b2 < 0) {
                                i9 = i2 + 6;
                                if (bArr[i7] < 0) {
                                    i7 = i2 + 7;
                                    if (bArr[i9] < 0) {
                                        i9 = i2 + 8;
                                        if (bArr[i7] < 0) {
                                            i7 = i2 + 9;
                                            if (bArr[i9] < 0) {
                                                int i12 = i2 + 10;
                                                if (bArr[i7] >= 0) {
                                                    i5 = i12;
                                                    i = i11;
                                                }
                                            }
                                        }
                                    }
                                }
                                i = i11;
                            }
                            i = i11;
                        }
                        i5 = i9;
                    }
                    i5 = i7;
                }
                this.f344 = i5;
                return i;
            }
        }
        return (int) m139();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵵᵽ */
    public final boolean mo126() {
        return this.f344 == this.f342 && !m143(1);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵶˇᵱ */
    public final String mo127() throws InvalidProtocolBufferException {
        int iM150 = m150();
        byte[] bArr = this.f345;
        if (iM150 > 0) {
            int i = this.f342;
            int i2 = this.f344;
            if (iM150 <= i - i2) {
                String str = new String(bArr, i2, iM150, AbstractC2956.f11367);
                this.f344 += iM150;
                return str;
            }
        }
        if (iM150 == 0) {
            return "";
        }
        if (iM150 < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        if (iM150 > this.f342) {
            return new String(m141(iM150), AbstractC2956.f11367);
        }
        m149(iM150);
        String str2 = new String(bArr, this.f344, iM150, AbstractC2956.f11367);
        this.f344 += iM150;
        return str2;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵸˆˁ */
    public final int mo128() {
        return m150();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final int mo129() {
        return this.f346 + this.f344;
    }
}
