package kotlinx.coroutines.internal;

import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import p054r1.C1599e;
import p054r1.C1602g;
import p060t1.AbstractC1669d1;

/* renamed from: kotlinx.coroutines.internal.p */
/* loaded from: classes.dex */
public final class C1377p {

    /* renamed from: a */
    public static final C1377p f3058a;

    /* renamed from: b */
    public static final boolean f3059b;

    /* renamed from: c */
    public static final AbstractC1669d1 f3060c;

    static {
        C1377p c1377p = new C1377p();
        f3058a = c1377p;
        f3059b = C1385x.m1477e("kotlinx.coroutines.fast.service.loader", true);
        f3060c = c1377p.m1495a();
    }

    /* renamed from: a */
    public final AbstractC1669d1 m1495a() {
        Object next;
        try {
            List<InterfaceC1376o> m1539c = f3059b ? C1363f.f3034a.m1539c() : C1602g.m805d(C1599e.m808a(ServiceLoader.load(InterfaceC1376o.class, InterfaceC1376o.class.getClassLoader()).iterator()));
            Iterator<T> it = m1539c.iterator();
            if (it.hasNext()) {
                next = it.next();
                if (it.hasNext()) {
                    int loadPriority = ((InterfaceC1376o) next).getLoadPriority();
                    do {
                        Object next2 = it.next();
                        int loadPriority2 = ((InterfaceC1376o) next2).getLoadPriority();
                        if (loadPriority < loadPriority2) {
                            next = next2;
                            loadPriority = loadPriority2;
                        }
                    } while (it.hasNext());
                }
            } else {
                next = null;
            }
            InterfaceC1376o interfaceC1376o = (InterfaceC1376o) next;
            AbstractC1669d1 m1490e = interfaceC1376o == null ? null : C1378q.m1490e(interfaceC1376o, m1539c);
            return m1490e == null ? C1378q.m1493b(null, null, 3, null) : m1490e;
        } catch (Throwable th) {
            return C1378q.m1493b(th, null, 2, null);
        }
    }
}