package o1;

import T0.z;
import java.io.EOFException;
import java.io.IOException;
import x0.AbstractC1709a;
import x0.v;

/* JADX INFO: renamed from: o1.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1326b implements InterfaceC1331g {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public long f15581A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public long f15582B;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final C1330f f15583q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final long f15584r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final long f15585s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final AbstractC1333i f15586t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f15587u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public long f15588v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public long f15589w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public long f15590x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public long f15591y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public long f15592z;

    public C1326b(AbstractC1333i abstractC1333i, long j8, long j9, long j10, long j11, boolean z8) {
        AbstractC1709a.d(j8 >= 0 && j9 > j8);
        this.f15586t = abstractC1333i;
        this.f15584r = j8;
        this.f15585s = j9;
        if (j10 == j9 - j8 || z8) {
            this.f15588v = j11;
            this.f15587u = 4;
        } else {
            this.f15587u = 0;
        }
        this.f15583q = new C1330f();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00c3 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00c4  */
    /* JADX WARN: Type inference failed for: r4v0 */
    /* JADX WARN: Type inference failed for: r4v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r4v5 */
    @Override // o1.InterfaceC1331g
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long b(T0.j jVar) throws IOException {
        C1330f c1330f;
        long j8;
        ?? r42;
        long j9;
        long j10;
        C1330f c1330f2;
        long j11;
        int i = this.f15587u;
        long j12 = this.f15585s;
        C1330f c1330f3 = this.f15583q;
        if (i == 0) {
            c1330f = c1330f3;
            j8 = 0;
            long j13 = jVar.f6428t;
            this.f15589w = j13;
            this.f15587u = 1;
            long j14 = j12 - 65307;
            if (j14 > j13) {
                return j14;
            }
            r42 = 0;
        } else if (i != 1) {
            if (i == 2) {
                j9 = 2;
                long j15 = this.f15591y;
                long j16 = this.f15592z;
                if (j15 == j16) {
                    j11 = -1;
                    j10 = -1;
                    c1330f2 = c1330f3;
                    if (j11 == j10) {
                        return j11;
                    }
                    this.f15587u = 3;
                } else {
                    long j17 = jVar.f6428t;
                    if (c1330f3.b(jVar, j16)) {
                        c1330f3.a(jVar, false);
                        jVar.f6430v = 0;
                        long j18 = this.f15590x;
                        long j19 = c1330f3.f15604b;
                        long j20 = j18 - j19;
                        int i5 = c1330f3.f15606d + c1330f3.f15607e;
                        if (0 > j20 || j20 >= 72000) {
                            if (j20 < 0) {
                                this.f15592z = j17;
                                this.f15582B = j19;
                            } else {
                                this.f15591y = jVar.f6428t + ((long) i5);
                                this.f15581A = j19;
                            }
                            long j21 = this.f15592z;
                            long j22 = this.f15591y;
                            if (j21 - j22 < 100000) {
                                this.f15592z = j22;
                                j10 = -1;
                                c1330f2 = c1330f3;
                                j11 = j22;
                            } else {
                                j10 = -1;
                                c1330f2 = c1330f3;
                                j11 = v.j((((j21 - j22) * j20) / (this.f15582B - this.f15581A)) + (jVar.f6428t - (((long) i5) * (j20 <= 0 ? 2L : 1L))), j22, j21 - 1);
                            }
                            if (j11 == j10) {
                            }
                        }
                        j11 = -1;
                        j10 = -1;
                        c1330f2 = c1330f3;
                        if (j11 == j10) {
                        }
                    } else {
                        j11 = this.f15591y;
                        if (j11 == j17) {
                            throw new IOException("No ogg page can be found.");
                        }
                        j10 = -1;
                        c1330f2 = c1330f3;
                        if (j11 == j10) {
                        }
                    }
                }
            } else {
                if (i != 3) {
                    if (i == 4) {
                        return -1L;
                    }
                    throw new IllegalStateException();
                }
                j10 = -1;
                c1330f2 = c1330f3;
                j9 = 2;
            }
            long j23 = j10;
            while (true) {
                c1330f2.b(jVar, j23);
                c1330f2.a(jVar, false);
                if (c1330f2.f15604b > this.f15590x) {
                    jVar.f6430v = 0;
                    this.f15587u = 4;
                    return -(this.f15581A + j9);
                }
                jVar.b(c1330f2.f15606d + c1330f2.f15607e);
                this.f15591y = jVar.f6428t;
                this.f15581A = c1330f2.f15604b;
                j23 = -1;
            }
        } else {
            c1330f = c1330f3;
            j8 = 0;
            r42 = 0;
        }
        c1330f.f15603a = r42;
        c1330f.f15604b = j8;
        c1330f.f15605c = r42;
        c1330f.f15606d = r42;
        c1330f.f15607e = r42;
        if (!c1330f.b(jVar, -1L)) {
            throw new EOFException();
        }
        c1330f.a(jVar, r42);
        jVar.b(c1330f.f15606d + c1330f.f15607e);
        long j24 = c1330f.f15604b;
        while ((c1330f.f15603a & 4) != 4 && c1330f.b(jVar, -1L) && jVar.f6428t < j12 && c1330f.a(jVar, true)) {
            try {
                jVar.b(c1330f.f15606d + c1330f.f15607e);
                j24 = c1330f.f15604b;
            } catch (EOFException unused) {
            }
        }
        this.f15588v = j24;
        this.f15587u = 4;
        return this.f15589w;
    }

    @Override // o1.InterfaceC1331g
    public final z f() {
        if (this.f15588v != 0) {
            return new C1325a(this);
        }
        return null;
    }

    @Override // o1.InterfaceC1331g
    public final void k(long j8) {
        this.f15590x = v.j(j8, 0L, this.f15588v - 1);
        this.f15587u = 2;
        this.f15591y = this.f15584r;
        this.f15592z = this.f15585s;
        this.f15581A = 0L;
        this.f15582B = this.f15588v;
    }
}
