package o;

import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class IF extends Oc0 {
    public final /* synthetic */ int e;
    public final /* synthetic */ Object f;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ IF(String str, Object obj, int i) {
        super(str, true);
        this.e = i;
        this.f = obj;
    }

    @Override // o.Oc0
    public final long a() throws IOException {
        switch (this.e) {
            case 0:
                KF kf = (KF) this.f;
                kf.getClass();
                try {
                    kf.H.j(2, false, 0);
                    return -1L;
                } catch (IOException e) {
                    kf.b(2, 2, e);
                    return -1L;
                }
            case 1:
                C1715kt c1715kt = (C1715kt) this.f;
                long jNanoTime = System.nanoTime();
                Iterator it = ((ConcurrentLinkedQueue) c1715kt.e).iterator();
                int i = 0;
                long j = Long.MIN_VALUE;
                C2486t00 c2486t00 = null;
                int i2 = 0;
                while (it.hasNext()) {
                    C2486t00 c2486t002 = (C2486t00) it.next();
                    synchronized (c2486t002) {
                        if (c1715kt.b(c2486t002, jNanoTime) > 0) {
                            i2++;
                        } else {
                            i++;
                            long j2 = jNanoTime - c2486t002.q;
                            if (j2 > j) {
                                c2486t00 = c2486t002;
                                j = j2;
                            }
                        }
                    }
                }
                long j3 = c1715kt.b;
                if (j < j3 && i <= c1715kt.a) {
                    if (i > 0) {
                        return j3 - j;
                    }
                    if (i2 > 0) {
                        return j3;
                    }
                    return -1L;
                }
                synchronized (c2486t00) {
                    if (!c2486t00.p.isEmpty()) {
                        return 0L;
                    }
                    if (c2486t00.q + j != jNanoTime) {
                        return 0L;
                    }
                    c2486t00.j = true;
                    ((ConcurrentLinkedQueue) c1715kt.e).remove(c2486t00);
                    AbstractC2264qi0.e(c2486t00.d);
                    if (!((ConcurrentLinkedQueue) c1715kt.e).isEmpty()) {
                        return 0L;
                    }
                    ((Tc0) c1715kt.c).a();
                    return 0L;
                }
            default:
                ((NC) this.f).a();
                return -1L;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public IF(C1715kt c1715kt, String str) {
        super(str, true);
        this.e = 1;
        this.f = c1715kt;
    }
}
