package androidx.datastore.preferences.protobuf;

import defpackage.AbstractC0715;
import defpackage.AbstractC2475;
import defpackage.AbstractC2819;
import defpackage.AbstractC3915;
import defpackage.C5050;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;

/* renamed from: androidx.datastore.preferences.protobuf.ˏᵙ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0005 extends AbstractC0715 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public int f346;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public int f347;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public int f348;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final FileInputStream f349;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public int f350;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public int f351 = Integer.MAX_VALUE;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public int f352;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final byte[] f353;

    public C0005(FileInputStream fileInputStream) {
        Charset charset = AbstractC2819.f10860;
        this.f349 = fileInputStream;
        this.f353 = new byte[4096];
        this.f346 = 0;
        this.f347 = 0;
        this.f350 = 0;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final String mo153() throws IOException {
        int iM173 = m173();
        int i = this.f347;
        int i2 = this.f346;
        int i3 = i2 - i;
        byte[] bArrM167 = this.f353;
        if (iM173 <= i3 && iM173 > 0) {
            this.f347 = i + iM173;
        } else {
            if (iM173 == 0) {
                return "";
            }
            if (iM173 < 0) {
                throw InvalidProtocolBufferException.m98();
            }
            i = 0;
            if (iM173 <= i2) {
                m156(iM173);
                this.f347 = iM173;
            } else {
                bArrM167 = m167(iM173);
            }
        }
        return AbstractC2475.f9678.ᵶᵷᵕ(bArrM167, i, iM173);
    }

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public final void m154() {
        int i = this.f346 + this.f348;
        this.f346 = i;
        int i2 = this.f350 + i;
        int i3 = this.f351;
        if (i2 <= i3) {
            this.f348 = 0;
            return;
        }
        int i4 = i2 - i3;
        this.f348 = i4;
        this.f346 = i - i4;
    }

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public final ArrayList m155(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.f349.read(bArr, i2, iMin - i2);
                if (i3 == -1) {
                    throw InvalidProtocolBufferException.m94();
                }
                this.f350 += i3;
                i2 += i3;
            }
            i -= iMin;
            arrayList.add(bArr);
        }
        return arrayList;
    }

    /* renamed from: ˆᵼᵷˊ, reason: contains not printable characters */
    public final void m156(int i) throws InvalidProtocolBufferException {
        if (m160(i)) {
            return;
        }
        if (i <= (Integer.MAX_VALUE - this.f350) - this.f347) {
            throw InvalidProtocolBufferException.m94();
        }
        throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit.");
    }

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public final long m157() throws InvalidProtocolBufferException {
        long j = 0;
        for (int i = 0; i < 64; i += 7) {
            if (this.f347 == this.f346) {
                m156(1);
            }
            int i2 = this.f347;
            this.f347 = i2 + 1;
            j |= (r3 & Byte.MAX_VALUE) << i;
            if ((this.f353[i2] & 128) == 0) {
                return j;
            }
        }
        throw InvalidProtocolBufferException.m95();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final double mo158() {
        return Double.longBitsToDouble(m168());
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final int mo159(int i) throws InvalidProtocolBufferException {
        if (i < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        int i2 = this.f350 + this.f347 + i;
        if (i2 < 0) {
            throw new InvalidProtocolBufferException("Failed to parse the message.");
        }
        int i3 = this.f351;
        if (i2 > i3) {
            throw InvalidProtocolBufferException.m94();
        }
        this.f351 = i2;
        m154();
        return i3;
    }

    /* renamed from: ˌᵪ, reason: contains not printable characters */
    public final boolean m160(int i) throws IOException {
        FileInputStream fileInputStream = this.f349;
        int i2 = this.f347;
        int i3 = i2 + i;
        int i4 = this.f346;
        if (i3 <= i4) {
            ᵹˉᵞ.ᵳٴᵶ(AbstractC3915.m8596(i, "refillBuffer() called when ", " bytes were already available in buffer"));
            return false;
        }
        int i5 = this.f350;
        if (i <= (Integer.MAX_VALUE - i5) - i2 && i5 + i2 + i <= this.f351) {
            byte[] bArr = this.f353;
            if (i2 > 0) {
                if (i4 > i2) {
                    System.arraycopy(bArr, i2, bArr, 0, i4 - i2);
                }
                this.f350 += i2;
                this.f346 -= i2;
                this.f347 = 0;
            }
            int i6 = this.f346;
            try {
                int i7 = fileInputStream.read(bArr, i6, Math.min(bArr.length - i6, (Integer.MAX_VALUE - this.f350) - 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.f346 += i7;
                    m154();
                    if (this.f346 >= i) {
                        return true;
                    }
                    return m160(i);
                }
            } catch (InvalidProtocolBufferException e) {
                e.f329 = true;
                throw e;
            }
        }
        return false;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final boolean mo161() {
        return this.f347 == this.f346 && !m160(1);
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final long mo162() {
        return m164();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final int mo163() {
        return this.f350 + this.f347;
    }

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public final long m164() {
        long j;
        long j2;
        long j3;
        long j4;
        int i = this.f347;
        int i2 = this.f346;
        if (i2 != i) {
            int i3 = i + 1;
            byte[] bArr = this.f353;
            byte b = bArr[i];
            if (b >= 0) {
                this.f347 = 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 ^ (bArr[i8] << 28);
                            if (j6 >= 0) {
                                j3 = 266354560;
                            } else {
                                i8 = i + 6;
                                long j7 = j6 ^ (bArr[i4] << 35);
                                if (j7 < 0) {
                                    j2 = -34093383808L;
                                } else {
                                    i4 = i + 7;
                                    j6 = j7 ^ (bArr[i8] << 42);
                                    if (j6 >= 0) {
                                        j3 = 4363953127296L;
                                    } else {
                                        i8 = i + 8;
                                        j7 = j6 ^ (bArr[i4] << 49);
                                        if (j7 < 0) {
                                            j2 = -558586000294016L;
                                        } else {
                                            i4 = i + 9;
                                            long j8 = (j7 ^ (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.f347 = i4;
                return j;
            }
        }
        return m157();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public final int mo165() {
        return m173();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˑᵱ, reason: contains not printable characters */
    public final int mo166() {
        return m173();
    }

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public final byte[] m167(int i) throws IOException {
        byte[] bArrM183 = m183(i);
        if (bArrM183 != null) {
            return bArrM183;
        }
        int i2 = this.f347;
        int i3 = this.f346;
        int length = i3 - i2;
        this.f350 += i3;
        this.f347 = 0;
        this.f346 = 0;
        ArrayList arrayListM155 = m155(i - length);
        byte[] bArr = new byte[i];
        System.arraycopy(this.f353, i2, bArr, 0, length);
        int size = arrayListM155.size();
        int i4 = 0;
        while (i4 < size) {
            Object obj = arrayListM155.get(i4);
            i4++;
            byte[] bArr2 = (byte[]) obj;
            System.arraycopy(bArr2, 0, bArr, length, bArr2.length);
            length += bArr2.length;
        }
        return bArr;
    }

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public final long m168() throws InvalidProtocolBufferException {
        int i = this.f347;
        if (this.f346 - i < 8) {
            m156(8);
            i = this.f347;
        }
        this.f347 = i + 8;
        byte[] bArr = this.f353;
        return ((bArr[i + 1] & 255) << 8) | (bArr[i] & 255) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 3] & 255) << 24) | ((bArr[i + 4] & 255) << 32) | ((bArr[i + 5] & 255) << 40) | ((bArr[i + 6] & 255) << 48) | ((bArr[i + 7] & 255) << 56);
    }

    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    public final void m169(int i) throws InvalidProtocolBufferException {
        int i2 = this.f346;
        int i3 = this.f347;
        int i4 = i2 - i3;
        if (i <= i4 && i >= 0) {
            this.f347 = i3 + i;
            return;
        }
        FileInputStream fileInputStream = this.f349;
        if (i < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        int i5 = this.f350;
        int i6 = i5 + i3;
        int i7 = i6 + i;
        int i8 = this.f351;
        if (i7 > i8) {
            m169((i8 - i5) - i3);
            throw InvalidProtocolBufferException.m94();
        }
        this.f350 = i6;
        this.f346 = 0;
        this.f347 = 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.f350 += i4;
                m154();
                throw th;
            }
        }
        this.f350 += i4;
        m154();
        if (i4 >= i) {
            return;
        }
        int i9 = this.f346;
        int i10 = i9 - this.f347;
        this.f347 = i9;
        m156(1);
        while (true) {
            int i11 = i - i10;
            int i12 = this.f346;
            if (i11 <= i12) {
                this.f347 = i11;
                return;
            } else {
                i10 += i12;
                this.f347 = i12;
                m156(1);
            }
        }
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final long mo170() {
        return m168();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final int mo171() {
        return m173();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final int mo172() throws InvalidProtocolBufferException {
        if (mo161()) {
            this.f352 = 0;
            return 0;
        }
        int iM173 = m173();
        this.f352 = iM173;
        if ((iM173 >>> 3) != 0) {
            return iM173;
        }
        throw new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
    }

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public final int m173() {
        int i;
        int i2 = this.f347;
        int i3 = this.f346;
        if (i3 != i2) {
            int i4 = i2 + 1;
            byte[] bArr = this.f353;
            byte b = bArr[i2];
            if (b >= 0) {
                this.f347 = 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.f347 = i5;
                return i;
            }
        }
        return (int) m157();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final String mo174() throws InvalidProtocolBufferException {
        int iM173 = m173();
        byte[] bArr = this.f353;
        if (iM173 > 0) {
            int i = this.f346;
            int i2 = this.f347;
            if (iM173 <= i - i2) {
                String str = new String(bArr, i2, iM173, AbstractC2819.f10860);
                this.f347 += iM173;
                return str;
            }
        }
        if (iM173 == 0) {
            return "";
        }
        if (iM173 < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        if (iM173 > this.f346) {
            return new String(m167(iM173), AbstractC2819.f10860);
        }
        m156(iM173);
        String str2 = new String(bArr, this.f347, iM173, AbstractC2819.f10860);
        this.f347 += iM173;
        return str2;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final int mo175() {
        return m188();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final long mo176() {
        long jM164 = m164();
        return (-(jM164 & 1)) ^ (jM164 >>> 1);
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final long mo177() {
        return m164();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵨᵳʝ, reason: contains not printable characters */
    public final float mo178() {
        return Float.intBitsToFloat(m188());
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public final boolean mo179(int i) throws InvalidProtocolBufferException {
        int i2 = i & 7;
        int i3 = 0;
        if (i2 != 0) {
            if (i2 == 1) {
                m169(8);
                return true;
            }
            if (i2 == 2) {
                m169(m173());
                return true;
            }
            if (i2 == 3) {
                m2717();
                mo182(((i >>> 3) << 3) | 4);
                return true;
            }
            if (i2 == 4) {
                return false;
            }
            if (i2 != 5) {
                throw InvalidProtocolBufferException.m97();
            }
            m169(4);
            return true;
        }
        int i4 = this.f346 - this.f347;
        byte[] bArr = this.f353;
        if (i4 >= 10) {
            while (i3 < 10) {
                int i5 = this.f347;
                this.f347 = i5 + 1;
                if (bArr[i5] < 0) {
                    i3++;
                }
            }
            throw InvalidProtocolBufferException.m95();
        }
        while (i3 < 10) {
            if (this.f347 == this.f346) {
                m156(1);
            }
            int i6 = this.f347;
            this.f347 = i6 + 1;
            if (bArr[i6] < 0) {
                i3++;
            }
        }
        throw InvalidProtocolBufferException.m95();
        return true;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final boolean mo180() {
        return m164() != 0;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final C5050 mo181() throws IOException {
        int iM173 = m173();
        int i = this.f346;
        int i2 = this.f347;
        int i3 = i - i2;
        byte[] bArr = this.f353;
        if (iM173 <= i3 && iM173 > 0) {
            C5050 c5050M10520 = C5050.m10520(bArr, i2, iM173);
            this.f347 += iM173;
            return c5050M10520;
        }
        if (iM173 == 0) {
            return C5050.f18874;
        }
        if (iM173 < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        byte[] bArrM183 = m183(iM173);
        if (bArrM183 != null) {
            return C5050.m10520(bArrM183, 0, bArrM183.length);
        }
        int i4 = this.f347;
        int i5 = this.f346;
        int length = i5 - i4;
        this.f350 += i5;
        this.f347 = 0;
        this.f346 = 0;
        ArrayList arrayListM155 = m155(iM173 - length);
        byte[] bArr2 = new byte[iM173];
        System.arraycopy(bArr, i4, bArr2, 0, length);
        int size = arrayListM155.size();
        int i6 = 0;
        while (i6 < size) {
            Object obj = arrayListM155.get(i6);
            i6++;
            byte[] bArr3 = (byte[]) obj;
            System.arraycopy(bArr3, 0, bArr2, length, bArr3.length);
            length += bArr3.length;
        }
        C5050 c5050 = C5050.f18874;
        return new C5050(bArr2);
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void mo182(int i) throws InvalidProtocolBufferException {
        if (this.f352 != i) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public final byte[] m183(int i) throws IOException {
        if (i == 0) {
            return AbstractC2819.f10861;
        }
        if (i < 0) {
            throw InvalidProtocolBufferException.m98();
        }
        int i2 = this.f350;
        int i3 = this.f347;
        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.f351;
        if (i4 > i5) {
            m169((i5 - i2) - i3);
            throw InvalidProtocolBufferException.m94();
        }
        int i6 = this.f346 - i3;
        int i7 = i - i6;
        FileInputStream fileInputStream = this.f349;
        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.f353, this.f347, bArr, 0, i6);
        this.f350 += this.f346;
        this.f347 = 0;
        this.f346 = 0;
        while (i6 < i) {
            try {
                int i8 = fileInputStream.read(bArr, i6, i - i6);
                if (i8 == -1) {
                    throw InvalidProtocolBufferException.m94();
                }
                this.f350 += i8;
                i6 += i8;
            } catch (InvalidProtocolBufferException e2) {
                e2.f329 = true;
                throw e2;
            }
        }
        return bArr;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void mo184(int i) {
        this.f351 = i;
        m154();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final int mo185() {
        return m188();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final int mo186() {
        int iM173 = m173();
        return (-(iM173 & 1)) ^ (iM173 >>> 1);
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final long mo187() {
        return m168();
    }

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public final int m188() throws InvalidProtocolBufferException {
        int i = this.f347;
        if (this.f346 - i < 4) {
            m156(4);
            i = this.f347;
        }
        this.f347 = i + 4;
        byte[] bArr = this.f353;
        return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
    }
}
