package defpackage;

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

/* JADX INFO: renamed from: ᵳˀٴﹳ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4558 extends InputStream {

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C2470 f17328;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public C4837 f17331;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public DataInputStream f17332;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public C3180 f17334;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public C3928 f17335;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public int f17336 = 0;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public boolean f17327 = false;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public boolean f17329 = true;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public boolean f17337 = true;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public boolean f17330 = false;

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public IOException f17326 = null;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public final byte[] f17333 = new byte[1];

    public C4558(InputStream inputStream, int i, C2470 c2470) {
        inputStream.getClass();
        this.f17328 = c2470;
        this.f17332 = new DataInputStream(inputStream);
        this.f17334 = new C3180(c2470);
        this.f17331 = new C4837(m9645(i), c2470);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static int m9645(int i) {
        if (i >= 4096 && i <= 2147483632) {
            return (i + 15) & (-16);
        }
        ᵕᵩʽᵲ.ᵮᵣᵗˈ(AbstractC2704.m6517(i, "Unsupported dictionary size "));
        return 0;
    }

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

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        if (this.f17332 != null) {
            C4837 c4837 = this.f17331;
            if (c4837 != null) {
                byte[] bArr = c4837.f18442;
                C2470 c2470 = this.f17328;
                c2470.mo4893(bArr);
                this.f17331 = null;
                c2470.mo4893(this.f17334.f12075);
                this.f17334 = null;
            }
            try {
                this.f17332.close();
            } finally {
                this.f17332 = null;
            }
        }
    }

    @Override // java.io.InputStream
    public final int read() {
        byte[] bArr = this.f17333;
        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.
    */
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        int i3;
        if (i < 0 || i2 < 0 || (i3 = i + i2) < 0 || i3 > bArr.length) {
            C4468.m9514();
            return 0;
        }
        if (i2 == 0) {
            return 0;
        }
        if (this.f17332 == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f17326;
        if (iOException != null) {
            throw iOException;
        }
        if (this.f17330) {
            return -1;
        }
        int i4 = 0;
        while (true) {
            if (i2 <= 0) {
                break;
            }
            try {
                if (this.f17336 == 0) {
                    m9646();
                    if (this.f17330) {
                        if (i4 == 0) {
                            return -1;
                        }
                    }
                }
                int iMin = Math.min(this.f17336, i2);
                boolean z = this.f17327;
                C4837 c4837 = this.f17331;
                if (z) {
                    int i5 = c4837.f18438;
                    int i6 = c4837.f18444;
                    if (i5 - i6 <= iMin) {
                        c4837.f18445 = i5;
                    } else {
                        c4837.f18445 = i6 + iMin;
                    }
                    this.f17335.m8661();
                } else {
                    DataInputStream dataInputStream = this.f17332;
                    int iMin2 = Math.min(c4837.f18438 - c4837.f18444, iMin);
                    dataInputStream.readFully(c4837.f18442, c4837.f18444, iMin2);
                    int i7 = c4837.f18444 + iMin2;
                    c4837.f18444 = i7;
                    if (c4837.f18441 < i7) {
                        c4837.f18441 = i7;
                    }
                }
                C4837 c48372 = this.f17331;
                int i8 = c48372.f18444;
                int i9 = c48372.f18440;
                int i10 = i8 - i9;
                if (i8 == c48372.f18438) {
                    c48372.f18444 = 0;
                }
                System.arraycopy(c48372.f18442, i9, bArr, i, i10);
                c48372.f18440 = c48372.f18444;
                i += i10;
                i2 -= i10;
                i4 += i10;
                int i11 = this.f17336 - i10;
                this.f17336 = i11;
                if (i11 == 0) {
                    C3180 c3180 = this.f17334;
                    if (c3180.f12077 != c3180.f12075.length || c3180.f12079 != 0 || this.f17331.f18443 > 0) {
                        break;
                    }
                }
            } catch (IOException e) {
                this.f17326 = e;
                throw e;
            }
        }
        throw new CorruptedInputException();
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m9646() throws IOException {
        int unsignedByte = this.f17332.readUnsignedByte();
        if (unsignedByte == 0) {
            this.f17330 = true;
            C4837 c4837 = this.f17331;
            if (c4837 != null) {
                byte[] bArr = c4837.f18442;
                C2470 c2470 = this.f17328;
                c2470.mo4893(bArr);
                this.f17331 = null;
                c2470.mo4893(this.f17334.f12075);
                this.f17334 = null;
                return;
            }
            return;
        }
        if (unsignedByte >= 224 || unsignedByte == 1) {
            this.f17337 = true;
            this.f17329 = false;
            C4837 c48372 = this.f17331;
            c48372.f18440 = 0;
            c48372.f18444 = 0;
            c48372.f18441 = 0;
            c48372.f18445 = 0;
            c48372.f18442[c48372.f18438 - 1] = 0;
        } else if (this.f17329) {
            throw new CorruptedInputException();
        }
        if (unsignedByte < 128) {
            if (unsignedByte > 2) {
                throw new CorruptedInputException();
            }
            this.f17327 = false;
            this.f17336 = this.f17332.readUnsignedShort() + 1;
            return;
        }
        this.f17327 = true;
        int i = (unsignedByte & 31) << 16;
        this.f17336 = i;
        this.f17336 = this.f17332.readUnsignedShort() + 1 + i;
        int unsignedShort = this.f17332.readUnsignedShort();
        int i2 = unsignedShort + 1;
        if (unsignedByte >= 192) {
            this.f17337 = false;
            int unsignedByte2 = this.f17332.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.f17335 = new C3928(this.f17331, this.f17334, i6, i5, i3);
        } else {
            if (this.f17337) {
                throw new CorruptedInputException();
            }
            if (unsignedByte >= 160) {
                this.f17335.m8660();
            }
        }
        C3180 c3180 = this.f17334;
        DataInputStream dataInputStream = this.f17332;
        c3180.getClass();
        if (i2 < 5) {
            throw new CorruptedInputException();
        }
        if (dataInputStream.readUnsignedByte() != 0) {
            throw new CorruptedInputException();
        }
        c3180.f12079 = dataInputStream.readInt();
        c3180.f12076 = -1;
        int i7 = unsignedShort - 4;
        byte[] bArr2 = c3180.f12075;
        int length = bArr2.length - i7;
        c3180.f12077 = length;
        dataInputStream.readFully(bArr2, length, i7);
    }
}
