package defpackage;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.tukaani.xz.CorruptedInputException;
import org.tukaani.xz.XZIOException;

/* renamed from: ᵣˇˌ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3342 extends InputStream {

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public DataInputStream f12488;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public C3738 f12489;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final C0471 f12491;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public C4089 f12493;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public C2790 f12494;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public int f12487 = 0;

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public boolean f12483 = false;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public boolean f12486 = true;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public boolean f12485 = true;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public boolean f12484 = false;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public IOException f12492 = null;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public final byte[] f12490 = new byte[1];

    public C3342(InputStream inputStream, int i, C0471 c0471) {
        inputStream.getClass();
        this.f12491 = c0471;
        this.f12488 = new DataInputStream(inputStream);
        this.f12493 = new C4089(c0471);
        this.f12494 = new C2790(m7741(i), c0471);
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static int m7741(int i) {
        if (i >= 4096 && i <= 2147483632) {
            return (i + 15) & (-16);
        }
        ᵹˉᵞ.ˌᵜᵹᵩ(AbstractC2990.m7313(i, "Unsupported dictionary size "));
        return 0;
    }

    @Override // java.io.InputStream
    public final int available() throws IOException {
        DataInputStream dataInputStream = this.f12488;
        if (dataInputStream == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f12492;
        if (iOException != null) {
            throw iOException;
        }
        boolean z = this.f12483;
        int i = this.f12487;
        return z ? i : Math.min(i, dataInputStream.available());
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        if (this.f12488 != null) {
            C2790 c2790 = this.f12494;
            if (c2790 != null) {
                byte[] bArr = c2790.f10752;
                C0471 c0471 = this.f12491;
                c0471.mo2067(bArr);
                this.f12494 = null;
                c0471.mo2067(this.f12493.f15282);
                this.f12493 = null;
            }
            try {
                this.f12488.close();
            } finally {
                this.f12488 = null;
            }
        }
    }

    @Override // java.io.InputStream
    public final int read() {
        byte[] bArr = this.f12490;
        if (read(bArr, 0, 1) == -1) {
            return -1;
        }
        return bArr[0] & 255;
    }

    /* JADX WARN: Code restructure failed: missing block: B:56:0x00ad, code lost:
    
        return r1;
     */
    @Override // java.io.InputStream
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int read(byte[] r8, int r9, int r10) throws java.io.IOException {
        /*
            r7 = this;
            r0 = 0
            if (r9 < 0) goto Lb7
            if (r10 < 0) goto Lb7
            int r1 = r9 + r10
            if (r1 < 0) goto Lb7
            int r2 = r8.length
            if (r1 > r2) goto Lb7
            if (r10 != 0) goto Lf
            return r0
        Lf:
            java.io.DataInputStream r1 = r7.f12488
            if (r1 == 0) goto Laf
            java.io.IOException r1 = r7.f12492
            if (r1 != 0) goto Lae
            boolean r1 = r7.f12484
            if (r1 == 0) goto L1c
            goto L2c
        L1c:
            r1 = r0
        L1d:
            if (r10 <= 0) goto Lad
            int r2 = r7.f12487     // Catch: java.io.IOException -> L2e
            if (r2 != 0) goto L31
            r7.m7742()     // Catch: java.io.IOException -> L2e
            boolean r2 = r7.f12484     // Catch: java.io.IOException -> L2e
            if (r2 == 0) goto L31
            if (r1 != 0) goto Lad
        L2c:
            r7 = -1
            return r7
        L2e:
            r8 = move-exception
            goto Laa
        L31:
            int r2 = r7.f12487     // Catch: java.io.IOException -> L2e
            int r2 = java.lang.Math.min(r2, r10)     // Catch: java.io.IOException -> L2e
            boolean r3 = r7.f12483     // Catch: java.io.IOException -> L2e
            ᵜʕˈ r4 = r7.f12494
            if (r3 != 0) goto L5b
            java.io.DataInputStream r3 = r7.f12488     // Catch: java.io.IOException -> L2e
            int r5 = r4.f10753     // Catch: java.io.IOException -> L2e
            int r6 = r4.f10755     // Catch: java.io.IOException -> L2e
            int r5 = r5 - r6
            int r2 = java.lang.Math.min(r5, r2)     // Catch: java.io.IOException -> L2e
            byte[] r5 = r4.f10752     // Catch: java.io.IOException -> L2e
            int r6 = r4.f10755     // Catch: java.io.IOException -> L2e
            r3.readFully(r5, r6, r2)     // Catch: java.io.IOException -> L2e
            int r3 = r4.f10755     // Catch: java.io.IOException -> L2e
            int r3 = r3 + r2
            r4.f10755 = r3     // Catch: java.io.IOException -> L2e
            int r2 = r4.f10748     // Catch: java.io.IOException -> L2e
            if (r2 >= r3) goto L6e
            r4.f10748 = r3     // Catch: java.io.IOException -> L2e
            goto L6e
        L5b:
            int r3 = r4.f10753     // Catch: java.io.IOException -> L2e
            int r5 = r4.f10755     // Catch: java.io.IOException -> L2e
            int r6 = r3 - r5
            if (r6 > r2) goto L66
            r4.f10750 = r3     // Catch: java.io.IOException -> L2e
            goto L69
        L66:
            int r5 = r5 + r2
            r4.f10750 = r5     // Catch: java.io.IOException -> L2e
        L69:
            ᵨᐧᵼ r2 = r7.f12489     // Catch: java.io.IOException -> L2e
            r2.m8362()     // Catch: java.io.IOException -> L2e
        L6e:
            ᵜʕˈ r2 = r7.f12494     // Catch: java.io.IOException -> L2e
            int r3 = r2.f10755     // Catch: java.io.IOException -> L2e
            int r4 = r2.f10751     // Catch: java.io.IOException -> L2e
            int r5 = r3 - r4
            int r6 = r2.f10753     // Catch: java.io.IOException -> L2e
            if (r3 != r6) goto L7c
            r2.f10755 = r0     // Catch: java.io.IOException -> L2e
        L7c:
            byte[] r3 = r2.f10752     // Catch: java.io.IOException -> L2e
            java.lang.System.arraycopy(r3, r4, r8, r9, r5)     // Catch: java.io.IOException -> L2e
            int r3 = r2.f10755     // Catch: java.io.IOException -> L2e
            r2.f10751 = r3     // Catch: java.io.IOException -> L2e
            int r9 = r9 + r5
            int r10 = r10 - r5
            int r1 = r1 + r5
            int r2 = r7.f12487     // Catch: java.io.IOException -> L2e
            int r2 = r2 - r5
            r7.f12487 = r2     // Catch: java.io.IOException -> L2e
            if (r2 != 0) goto L1d
            ᵭʢ r2 = r7.f12493     // Catch: java.io.IOException -> L2e
            int r3 = r2.f15279     // Catch: java.io.IOException -> L2e
            byte[] r4 = r2.f15282     // Catch: java.io.IOException -> L2e
            int r4 = r4.length     // Catch: java.io.IOException -> L2e
            if (r3 != r4) goto La4
            int r2 = r2.f15283     // Catch: java.io.IOException -> L2e
            if (r2 != 0) goto La4
            ᵜʕˈ r2 = r7.f12494     // Catch: java.io.IOException -> L2e
            int r2 = r2.f10749     // Catch: java.io.IOException -> L2e
            if (r2 > 0) goto La4
            goto L1d
        La4:
            org.tukaani.xz.CorruptedInputException r8 = new org.tukaani.xz.CorruptedInputException     // Catch: java.io.IOException -> L2e
            r8.<init>()     // Catch: java.io.IOException -> L2e
            throw r8     // Catch: java.io.IOException -> L2e
        Laa:
            r7.f12492 = r8
            throw r8
        Lad:
            return r1
        Lae:
            throw r1
        Laf:
            org.tukaani.xz.XZIOException r7 = new org.tukaani.xz.XZIOException
            java.lang.String r8 = "Stream closed"
            r7.<init>(r8)
            throw r7
        Lb7:
            defpackage.C0190.m1431()
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C3342.read(byte[], int, int):int");
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m7742() throws IOException {
        int unsignedByte = this.f12488.readUnsignedByte();
        if (unsignedByte == 0) {
            this.f12484 = true;
            C2790 c2790 = this.f12494;
            if (c2790 != null) {
                byte[] bArr = c2790.f10752;
                C0471 c0471 = this.f12491;
                c0471.mo2067(bArr);
                this.f12494 = null;
                c0471.mo2067(this.f12493.f15282);
                this.f12493 = null;
                return;
            }
            return;
        }
        if (unsignedByte >= 224 || unsignedByte == 1) {
            this.f12485 = true;
            this.f12486 = false;
            C2790 c27902 = this.f12494;
            c27902.f10751 = 0;
            c27902.f10755 = 0;
            c27902.f10748 = 0;
            c27902.f10750 = 0;
            c27902.f10752[c27902.f10753 - 1] = 0;
        } else if (this.f12486) {
            throw new CorruptedInputException();
        }
        if (unsignedByte < 128) {
            if (unsignedByte > 2) {
                throw new CorruptedInputException();
            }
            this.f12483 = false;
            this.f12487 = this.f12488.readUnsignedShort() + 1;
            return;
        }
        this.f12483 = true;
        int i = (unsignedByte & 31) << 16;
        this.f12487 = i;
        this.f12487 = this.f12488.readUnsignedShort() + 1 + i;
        int unsignedShort = this.f12488.readUnsignedShort();
        int i2 = unsignedShort + 1;
        if (unsignedByte >= 192) {
            this.f12485 = false;
            int unsignedByte2 = this.f12488.readUnsignedByte();
            if (unsignedByte2 > 224) {
                throw new CorruptedInputException();
            }
            int i3 = unsignedByte2 / 45;
            int i4 = unsignedByte2 - (i3 * 45);
            int i5 = i4 / 9;
            int i6 = i4 - (i5 * 9);
            if (i6 + i5 > 4) {
                throw new CorruptedInputException();
            }
            this.f12489 = new C3738(this.f12494, this.f12493, i6, i5, i3);
        } else {
            if (this.f12485) {
                throw new CorruptedInputException();
            }
            if (unsignedByte >= 160) {
                this.f12489.m8363();
            }
        }
        C4089 c4089 = this.f12493;
        DataInputStream dataInputStream = this.f12488;
        c4089.getClass();
        if (i2 < 5) {
            throw new CorruptedInputException();
        }
        if (dataInputStream.readUnsignedByte() != 0) {
            throw new CorruptedInputException();
        }
        c4089.f15283 = dataInputStream.readInt();
        c4089.f15280 = -1;
        int i7 = unsignedShort - 4;
        byte[] bArr2 = c4089.f15282;
        int length = bArr2.length - i7;
        c4089.f15279 = length;
        dataInputStream.readFully(bArr2, length, i7);
    }
}
