package o;

import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
import java.util.zip.CRC32;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.wE, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2794wE implements T90 {
    public byte l;
    public final C1822m00 m;
    public final Inflater n;

    /* renamed from: o, reason: collision with root package name */
    public final C1658kH f769o;
    public final CRC32 p;

    public C2794wE(T90 t90) {
        C1822m00 c1822m00 = new C1822m00(t90);
        this.m = c1822m00;
        Inflater inflater = new Inflater(true);
        this.n = inflater;
        this.f769o = new C1658kH(c1822m00, inflater);
        this.p = new CRC32();
    }

    public static void b(int i, String str, int i2) throws IOException {
        if (i2 != i) {
            throw new IOException(String.format("%s: actual 0x%08x != expected 0x%08x", Arrays.copyOf(new Object[]{str, Integer.valueOf(i2), Integer.valueOf(i)}, 3)));
        }
    }

    @Override // o.T90
    public final long C(long j, C0732af c0732af) throws DataFormatException, IOException {
        C2794wE c2794wE = this;
        if (j < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.l("byteCount < 0: ", j).toString());
        }
        if (j == 0) {
            return 0L;
        }
        byte b = c2794wE.l;
        CRC32 crc32 = c2794wE.p;
        C1822m00 c1822m00 = c2794wE.m;
        if (b == 0) {
            c1822m00.I(10L);
            C0732af c0732af2 = c1822m00.m;
            byte bG = c0732af2.g(3L);
            boolean z = ((bG >> 1) & 1) == 1;
            if (z) {
                c2794wE.c(c0732af2, 0L, 10L);
            }
            b(8075, "ID1ID2", c1822m00.readShort());
            c1822m00.skip(8L);
            if (((bG >> 2) & 1) == 1) {
                c1822m00.I(2L);
                if (z) {
                    c(c0732af2, 0L, 2L);
                }
                long jX = c0732af2.x() & 65535;
                c1822m00.I(jX);
                if (z) {
                    c(c0732af2, 0L, jX);
                }
                c1822m00.skip(jX);
            }
            if (((bG >> 3) & 1) == 1) {
                long jC = c1822m00.c((byte) 0, 0L, Long.MAX_VALUE);
                if (jC == -1) {
                    throw new EOFException();
                }
                if (z) {
                    c(c0732af2, 0L, jC + 1);
                }
                c1822m00.skip(jC + 1);
            }
            if (((bG >> 4) & 1) == 1) {
                long jC2 = c1822m00.c((byte) 0, 0L, Long.MAX_VALUE);
                if (jC2 == -1) {
                    throw new EOFException();
                }
                if (z) {
                    c2794wE = this;
                    c2794wE.c(c0732af2, 0L, jC2 + 1);
                } else {
                    c2794wE = this;
                }
                c1822m00.skip(jC2 + 1);
            } else {
                c2794wE = this;
            }
            if (z) {
                b(c1822m00.x(), "FHCRC", (short) crc32.getValue());
                crc32.reset();
            }
            c2794wE.l = (byte) 1;
        }
        if (c2794wE.l == 1) {
            long j2 = c0732af.m;
            long jC3 = c2794wE.f769o.C(j, c0732af);
            if (jC3 != -1) {
                c2794wE.c(c0732af, j2, jC3);
                return jC3;
            }
            c2794wE.l = (byte) 2;
        }
        if (c2794wE.l == 2) {
            b(c1822m00.t(), "CRC", (int) crc32.getValue());
            b(c1822m00.t(), "ISIZE", (int) c2794wE.n.getBytesWritten());
            c2794wE.l = (byte) 3;
            if (!c1822m00.b()) {
                throw new IOException("gzip finished without exhausting source");
            }
        }
        return -1L;
    }

    @Override // o.T90
    public final Cf0 a() {
        return this.m.l.a();
    }

    public final void c(C0732af c0732af, long j, long j2) {
        C2496t50 c2496t50 = c0732af.l;
        while (true) {
            int i = c2496t50.c;
            int i2 = c2496t50.b;
            if (j < i - i2) {
                break;
            }
            j -= i - i2;
            c2496t50 = c2496t50.f;
        }
        while (j2 > 0) {
            int iMin = (int) Math.min(c2496t50.c - r6, j2);
            this.p.update(c2496t50.a, (int) (c2496t50.b + j), iMin);
            j2 -= iMin;
            c2496t50 = c2496t50.f;
            j = 0;
        }
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        this.f769o.close();
    }
}
