package com.appsflyer.internal;

import com.google.android.material.progressindicator.BaseProgressIndicator;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public final class an extends FilterInputStream {

    /* renamed from: ʻ  reason: contains not printable characters */
    public int f2037;

    /* renamed from: ʼ  reason: contains not printable characters */
    public int f2038 = 8;

    /* renamed from: ˊ  reason: contains not printable characters */
    public int[] f2039 = new int[8];

    /* renamed from: ˋ  reason: contains not printable characters */
    public final int f2040;

    /* renamed from: ˎ  reason: contains not printable characters */
    public int[] f2041 = new int[8];

    /* renamed from: ˏ  reason: contains not printable characters */
    public int[] f2042 = new int[8];

    /* renamed from: ॱ  reason: contains not printable characters */
    public aj f2043;

    /* renamed from: ॱॱ  reason: contains not printable characters */
    public int[] f2044 = new int[2];

    /* renamed from: ᐝ  reason: contains not printable characters */
    public int f2045;

    public an(InputStream inputStream, int[] iArr, byte[] bArr, int i, boolean z, int i2) throws IOException {
        super(inputStream);
        this.f2040 = Math.min(Math.max(i, 3), 16);
        this.f2045 = i2;
        if (i2 == 2) {
            System.arraycopy(m1202(bArr), 0, this.f2039, 0, 8);
        }
        this.f2043 = new aj(iArr, this.f2040, true);
        this.f2037 = ((FilterInputStream) this).in.read();
    }

    /* renamed from: ˊ  reason: contains not printable characters */
    public static int[] m1202(byte[] bArr) {
        int length = bArr.length;
        int[] iArr = new int[length];
        for (int i = 0; i < length; i++) {
            iArr[i] = bArr[i] & 255;
        }
        return iArr;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int available() throws IOException {
        return 8 - this.f2038;
    }

    public final boolean markSupported() {
        return false;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        if (i2 == 0) {
            return 0;
        }
        int read = read();
        if (read == -1) {
            return -1;
        }
        bArr[i] = (byte) read;
        int i3 = 1;
        while (i3 < i2) {
            int read2 = read();
            if (read2 == -1) {
                return i3;
            }
            bArr[i + i3] = (byte) read2;
            i3++;
        }
        return i3;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final long skip(long j) throws IOException {
        long j2 = 0;
        while (j2 < j && read() != -1) {
            j2++;
        }
        return j2;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read() throws IOException {
        if (this.f2038 == 8) {
            int i = this.f2037;
            if (i == -1) {
                Arrays.fill(this.f2041, -1);
            } else {
                this.f2041[0] = i;
                for (int i2 = 1; i2 < 8; i2++) {
                    this.f2041[i2] = ((FilterInputStream) this).in.read();
                }
                if (this.f2045 == 2) {
                    int[] iArr = this.f2041;
                    System.arraycopy(iArr, 0, this.f2042, 0, iArr.length);
                }
                int[] iArr2 = this.f2041;
                int i3 = ((iArr2[0] << 24) & -16777216) + ((iArr2[1] << 16) & 16711680) + ((iArr2[2] << 8) & 65280) + (iArr2[3] & BaseProgressIndicator.MAX_ALPHA);
                int i4 = (-16777216 & (iArr2[4] << 24)) + (16711680 & (iArr2[5] << 16)) + ((iArr2[6] << 8) & 65280) + (iArr2[7] & BaseProgressIndicator.MAX_ALPHA);
                int i5 = this.f2040;
                aj ajVar = this.f2043;
                ap.m1205(i3, i4, false, i5, ajVar.f2026, ajVar.f2028, this.f2044);
                int[] iArr3 = this.f2044;
                int i6 = iArr3[0];
                int i7 = iArr3[1];
                int[] iArr4 = this.f2041;
                iArr4[0] = i6 >>> 24;
                iArr4[1] = (i6 >> 16) & BaseProgressIndicator.MAX_ALPHA;
                iArr4[2] = (i6 >> 8) & BaseProgressIndicator.MAX_ALPHA;
                iArr4[3] = i6 & BaseProgressIndicator.MAX_ALPHA;
                iArr4[4] = i7 >>> 24;
                iArr4[5] = (i7 >> 16) & BaseProgressIndicator.MAX_ALPHA;
                iArr4[6] = (i7 >> 8) & BaseProgressIndicator.MAX_ALPHA;
                iArr4[7] = i7 & BaseProgressIndicator.MAX_ALPHA;
                if (this.f2045 == 2) {
                    for (int i8 = 0; i8 < 8; i8++) {
                        int[] iArr5 = this.f2041;
                        iArr5[i8] = (iArr5[i8] ^ this.f2039[i8]) & BaseProgressIndicator.MAX_ALPHA;
                    }
                    int[] iArr6 = this.f2042;
                    System.arraycopy(iArr6, 0, this.f2039, 0, iArr6.length);
                }
                this.f2037 = ((FilterInputStream) this).in.read();
                if (this.f2037 == -1) {
                    int[] iArr7 = this.f2041;
                    Arrays.fill(iArr7, 8 - iArr7[7], 8, -1);
                }
            }
            this.f2038 = 0;
        }
        int[] iArr8 = this.f2041;
        int i9 = this.f2038;
        this.f2038 = i9 + 1;
        return iArr8[i9];
    }
}
