package com.google.android.gms.internal.ads;

import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes2.dex */
public final class r6 implements o6 {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f15999b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final int f16001d;

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

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

    @Nullable
    private final long[] zzg;

    private r6(long j10, int i10, long j11, int i11, long j12, @Nullable long[] jArr) {
        this.f15998a = j10;
        this.f15999b = i10;
        this.f16000c = j11;
        this.f16001d = i11;
        this.f16002e = j12;
        this.zzg = jArr;
        this.f16003f = j12 != -1 ? j10 + j12 : -1L;
    }

    @Nullable
    public static r6 zzd(q6 q6Var, long j10) {
        long jB = q6Var.b();
        if (jB == -9223372036854775807L) {
            return null;
        }
        long j11 = q6Var.f15595c;
        long[] jArr = q6Var.zzf;
        i3 i3Var = q6Var.f15593a;
        return new r6(j10, i3Var.f12347b, jB, i3Var.f12350e, j11, jArr);
    }

    @Override // com.google.android.gms.internal.ads.o6
    public final long a(long j10) {
        if (!zzb()) {
            return 0L;
        }
        long j11 = j10 - this.f15998a;
        if (j11 <= this.f15999b) {
            return 0L;
        }
        long[] jArr = this.zzg;
        jArr.getClass();
        double d10 = (j11 * 256.0d) / this.f16002e;
        int iN = bb1.n(jArr, (long) d10, true);
        long j12 = this.f16000c;
        long j13 = (((long) iN) * j12) / 100;
        long j14 = jArr[iN];
        int i10 = iN + 1;
        long j15 = (j12 * ((long) i10)) / 100;
        return Math.round((j14 == (iN == 99 ? 256L : jArr[i10]) ? 0.0d : (d10 - j14) / (r0 - j14)) * (j15 - j13)) + j13;
    }

    @Override // com.google.android.gms.internal.ads.k3
    public final long zza() {
        return this.f16000c;
    }

    @Override // com.google.android.gms.internal.ads.k3
    public final boolean zzb() {
        return this.zzg != null;
    }

    @Override // com.google.android.gms.internal.ads.k3
    public final j3 zzc(long j10) {
        boolean zZzb = zzb();
        int i10 = this.f15999b;
        long j11 = this.f15998a;
        if (!zZzb) {
            l3 l3Var = new l3(0L, j11 + ((long) i10));
            return new j3(l3Var, l3Var);
        }
        String str = bb1.f9474a;
        long j12 = this.f16000c;
        long jMax = Math.max(0L, Math.min(j10, j12));
        double d10 = (jMax * 100.0d) / j12;
        double d11 = 0.0d;
        if (d10 > 0.0d) {
            if (d10 >= 100.0d) {
                d11 = 256.0d;
            } else {
                int i11 = (int) d10;
                long[] jArr = this.zzg;
                jArr.getClass();
                double d12 = jArr[i11];
                d11 = (((i11 == 99 ? 256.0d : jArr[i11 + 1]) - d12) * (d10 - ((double) i11))) + d12;
            }
        }
        long j13 = this.f16002e;
        l3 l3Var2 = new l3(jMax, j11 + Math.max(i10, Math.min(Math.round((d11 / 256.0d) * j13), j13 - 1)));
        return new j3(l3Var2, l3Var2);
    }

    @Override // com.google.android.gms.internal.ads.o6
    public final long zzf() {
        return this.f16003f;
    }

    @Override // com.google.android.gms.internal.ads.o6
    public final int zzg() {
        return this.f16001d;
    }
}
