package k1;

import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import m1.C0632d;

/* JADX INFO: loaded from: classes.dex */
public class Y extends InputStream {

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    private byte[] f4748H;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    W f4749I;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private long f4750b;

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private int f4752r;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private int f4753x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private int f4754y;

    public Y(String str) {
        this(new W(str));
    }

    /* JADX WARN: Code restructure failed: missing block: B:43:0x00ed, code lost:
    
        return (int) (r10 - r4);
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public int a(byte[] r18, int r19, int r20) throws java.io.IOException {
        /*
            Method dump skipped, instruction units count: 268
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: k1.Y.a(byte[], int, int):int");
    }

    @Override // java.io.InputStream
    public int available() throws IOException {
        W w2 = this.f4749I;
        if (w2.f4739f0 != 16) {
            return 0;
        }
        try {
            b0 b0Var = (b0) w2;
            w2.N(32, b0Var.f4773s0 & 16711680, 128, 0);
            W w3 = this.f4749I;
            r0 r0Var = new r0(w3.f4737d0, w3.f4738e0);
            s0 s0Var = new s0(b0Var);
            b0Var.T(r0Var, s0Var);
            int i2 = s0Var.f5033O0;
            if (i2 != 1 && i2 != 4) {
                return s0Var.f5034P0;
            }
            this.f4749I.f4741g0 = false;
            return 0;
        } catch (V e2) {
            throw b(e2);
        }
    }

    protected IOException b(V v2) {
        Throwable thD = v2.d();
        IOException iOException = v2;
        if (thD instanceof C0632d) {
            C0632d c0632d = (C0632d) thD;
            thD = c0632d.a();
            iOException = c0632d;
        }
        if (!(thD instanceof InterruptedException)) {
            return iOException;
        }
        InterruptedIOException interruptedIOException = new InterruptedIOException(thD.getMessage());
        interruptedIOException.initCause(thD);
        return interruptedIOException;
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        try {
            this.f4749I.d();
            this.f4748H = null;
        } catch (V e2) {
            throw b(e2);
        }
    }

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

    @Override // java.io.InputStream
    public long skip(long j2) {
        if (j2 <= 0) {
            return 0L;
        }
        this.f4750b += j2;
        return j2;
    }

    public Y(W w2) {
        this(w2, 1);
    }

    Y(W w2, int i2) {
        this.f4748H = new byte[1];
        this.f4749I = w2;
        this.f4753x = i2 & 65535;
        int i3 = 65535 & (i2 >>> 16);
        this.f4754y = i3;
        if (w2.f4739f0 != 16) {
            w2.N(i2, i3, 128, 0);
            this.f4753x &= -81;
        } else {
            w2.g();
        }
        e0 e0Var = w2.f4736c0.f4870f.f4790h;
        int iMin = Math.min(e0Var.f4839o0 - 70, e0Var.f4835k0.f4845b - 70);
        this.f4751g = iMin;
        if ((w2.f4736c0.f4870f.f4790h.f4835k0.f4847d & 16384) == 16384) {
            this.f4752r = Math.min(U.f4709n - 70, 65465);
        } else {
            this.f4752r = iMin;
        }
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr) {
        return read(bArr, 0, bArr.length);
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr, int i2, int i3) {
        return a(bArr, i2, i3);
    }
}
