package ᨨ;

import java.io.EOFException;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.Inflater;
import ඓ.K.K.K.C1293;

/* renamed from: ᨨ.㑃  reason: contains not printable characters */
/* compiled from: GzipSource */
public final class C1485 implements AbstractC1494 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC1496 f5515;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C1498 f5516;

    /* renamed from: ῲ  reason: contains not printable characters */
    public int f5517 = 0;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final CRC32 f5518 = new CRC32();

    /* renamed from: 㸾  reason: contains not printable characters */
    public final Inflater f5519;

    public C1485(AbstractC1494 r3) {
        if (r3 != null) {
            this.f5519 = new Inflater(true);
            this.f5515 = C1486.m3741(r3);
            this.f5516 = new C1498(this.f5515, this.f5519);
            return;
        }
        throw new IllegalArgumentException("source == null");
    }

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

    @Override // ᨨ.AbstractC1494
    public long read(C1492 r21, long j) throws IOException {
        long j2;
        int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
        if (i < 0) {
            throw new IllegalArgumentException(C1293.m3409("byteCount < 0: ", j));
        } else if (i == 0) {
            return 0;
        } else {
            if (this.f5517 == 0) {
                this.f5515.m3823(10);
                byte r13 = this.f5515.m3819().m3777(3);
                boolean z = ((r13 >> 1) & 1) == 1;
                if (z) {
                    m3734(this.f5515.m3819(), 0, 10);
                }
                m3733("ID1ID2", 8075, this.f5515.readShort());
                this.f5515.skip(8);
                if (((r13 >> 2) & 1) == 1) {
                    this.f5515.m3823(2);
                    if (z) {
                        m3734(this.f5515.m3819(), 0, 2);
                    }
                    long r4 = (long) this.f5515.m3819().m3776();
                    this.f5515.m3823(r4);
                    if (z) {
                        j2 = r4;
                        m3734(this.f5515.m3819(), 0, r4);
                    } else {
                        j2 = r4;
                    }
                    this.f5515.skip(j2);
                }
                if (((r13 >> 3) & 1) == 1) {
                    long r18 = this.f5515.m3816((byte) 0);
                    if (r18 != -1) {
                        if (z) {
                            m3734(this.f5515.m3819(), 0, r18 + 1);
                        }
                        this.f5515.skip(r18 + 1);
                    } else {
                        throw new EOFException();
                    }
                }
                if (((r13 >> 4) & 1) == 1) {
                    long r132 = this.f5515.m3816((byte) 0);
                    if (r132 != -1) {
                        if (z) {
                            m3734(this.f5515.m3819(), 0, r132 + 1);
                        }
                        this.f5515.skip(r132 + 1);
                    } else {
                        throw new EOFException();
                    }
                }
                if (z) {
                    m3733("FHCRC", this.f5515.m3814(), (short) ((int) this.f5518.getValue()));
                    this.f5518.reset();
                }
                this.f5517 = 1;
            }
            if (this.f5517 == 1) {
                long j3 = r21.f5529;
                long read = this.f5516.read(r21, j);
                if (read != -1) {
                    m3734(r21, j3, read);
                    return read;
                }
                this.f5517 = 2;
            }
            if (this.f5517 == 2) {
                m3733("CRC", this.f5515.m3812(), (int) this.f5518.getValue());
                m3733("ISIZE", this.f5515.m3812(), (int) this.f5519.getBytesWritten());
                this.f5517 = 3;
                if (!this.f5515.m3821()) {
                    throw new IOException("gzip finished without exhausting source");
                }
            }
            return -1;
        }
    }

    @Override // ᨨ.AbstractC1494
    public C1477 timeout() {
        return this.f5515.timeout();
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3734(C1492 r6, long j, long j2) {
        C1475 r62 = r6.f5530;
        while (true) {
            int i = r62.f5494;
            int i2 = r62.f5496;
            if (j < ((long) (i - i2))) {
                break;
            }
            j -= (long) (i - i2);
            r62 = r62.f5499;
        }
        while (j2 > 0) {
            int i3 = (int) (((long) r62.f5496) + j);
            int min = (int) Math.min((long) (r62.f5494 - i3), j2);
            this.f5518.update(r62.f5498, i3, min);
            j2 -= (long) min;
            r62 = r62.f5499;
            j = 0;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3733(String str, int i, int i2) throws IOException {
        if (i2 != i) {
            throw new IOException(String.format("%s: actual 0x%08x != expected 0x%08x", str, Integer.valueOf(i2), Integer.valueOf(i)));
        }
    }
}
