package defpackage;

import androidx.media3.container.NalUnitUtil;
import defpackage.q38;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Iterator;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0003\n\u0002\b\u0002*(\b\u0002\u0010\u0002\"\u0010\u0012\u0004\u0012\u00020\u0001\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u00002\u0010\u0012\u0004\u0012\u00020\u0001\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u0000¨\u0006\u0003"}, d2 = {"Lkotlin/Function1;", "", "Ctor", "kotlinx-coroutines-core"}, k = 2, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class ar2 {
    public static final int a;

    static {
        rna rnaVar = rna.a;
        a = b(Throwable.class, -1);
        try {
            int i = aw2.a;
        } catch (Throwable unused) {
            rna rnaVar2 = rna.a;
        }
    }

    public static final sq3 a(Class cls) {
        Object next;
        sq3 sq3Var;
        q07 q07Var;
        q07 q07Var2;
        if (a == b(cls, 0)) {
            Constructor<?>[] constructors = cls.getConstructors();
            ArrayList arrayList = new ArrayList(constructors.length);
            int length = constructors.length;
            int i = 0;
            while (true) {
                next = null;
                if (i >= length) {
                    break;
                }
                final Constructor<?> constructor = constructors[i];
                Class<?>[] parameterTypes = constructor.getParameterTypes();
                int length2 = parameterTypes.length;
                if (length2 != 0) {
                    if (length2 == 1) {
                        Class<?> cls2 = parameterTypes[0];
                        if (cr4.b(cls2, String.class)) {
                            final int i2 = 1;
                            q07Var = new q07(new yq2(new sq3() { // from class: xq2
                                @Override // defpackage.sq3
                                public final Object invoke(Object obj) throws IllegalAccessException, InstantiationException, InvocationTargetException {
                                    int i3 = i2;
                                    Constructor constructor2 = constructor;
                                    Throwable th = (Throwable) obj;
                                    switch (i3) {
                                        case 0:
                                            int i4 = ar2.a;
                                            Object objNewInstance = constructor2.newInstance(th.getMessage(), th);
                                            cr4.e(objNewInstance, "null cannot be cast to non-null type kotlin.Throwable");
                                            return (Throwable) objNewInstance;
                                        case 1:
                                            int i5 = ar2.a;
                                            Object objNewInstance2 = constructor2.newInstance(th.getMessage());
                                            cr4.e(objNewInstance2, "null cannot be cast to non-null type kotlin.Throwable");
                                            Throwable th2 = (Throwable) objNewInstance2;
                                            th2.initCause(th);
                                            return th2;
                                        case 2:
                                            int i6 = ar2.a;
                                            Object objNewInstance3 = constructor2.newInstance(th);
                                            cr4.e(objNewInstance3, "null cannot be cast to non-null type kotlin.Throwable");
                                            return (Throwable) objNewInstance3;
                                        default:
                                            int i7 = ar2.a;
                                            Object objNewInstance4 = constructor2.newInstance(null);
                                            cr4.e(objNewInstance4, "null cannot be cast to non-null type kotlin.Throwable");
                                            Throwable th3 = (Throwable) objNewInstance4;
                                            th3.initCause(th);
                                            return th3;
                                    }
                                }
                            }, 0), 2);
                        } else if (cr4.b(cls2, Throwable.class)) {
                            final int i3 = 2;
                            q07Var = new q07(new yq2(new sq3() { // from class: xq2
                                @Override // defpackage.sq3
                                public final Object invoke(Object obj) throws IllegalAccessException, InstantiationException, InvocationTargetException {
                                    int i32 = i3;
                                    Constructor constructor2 = constructor;
                                    Throwable th = (Throwable) obj;
                                    switch (i32) {
                                        case 0:
                                            int i4 = ar2.a;
                                            Object objNewInstance = constructor2.newInstance(th.getMessage(), th);
                                            cr4.e(objNewInstance, "null cannot be cast to non-null type kotlin.Throwable");
                                            return (Throwable) objNewInstance;
                                        case 1:
                                            int i5 = ar2.a;
                                            Object objNewInstance2 = constructor2.newInstance(th.getMessage());
                                            cr4.e(objNewInstance2, "null cannot be cast to non-null type kotlin.Throwable");
                                            Throwable th2 = (Throwable) objNewInstance2;
                                            th2.initCause(th);
                                            return th2;
                                        case 2:
                                            int i6 = ar2.a;
                                            Object objNewInstance3 = constructor2.newInstance(th);
                                            cr4.e(objNewInstance3, "null cannot be cast to non-null type kotlin.Throwable");
                                            return (Throwable) objNewInstance3;
                                        default:
                                            int i7 = ar2.a;
                                            Object objNewInstance4 = constructor2.newInstance(null);
                                            cr4.e(objNewInstance4, "null cannot be cast to non-null type kotlin.Throwable");
                                            Throwable th3 = (Throwable) objNewInstance4;
                                            th3.initCause(th);
                                            return th3;
                                    }
                                }
                            }, 0), 1);
                        } else {
                            q07Var2 = new q07(null, -1);
                        }
                    } else if (length2 != 2) {
                        q07Var2 = new q07(null, -1);
                    } else if (cr4.b(parameterTypes[0], String.class) && cr4.b(parameterTypes[1], Throwable.class)) {
                        final int i4 = 0;
                        q07Var = new q07(new yq2(new sq3() { // from class: xq2
                            @Override // defpackage.sq3
                            public final Object invoke(Object obj) throws IllegalAccessException, InstantiationException, InvocationTargetException {
                                int i32 = i4;
                                Constructor constructor2 = constructor;
                                Throwable th = (Throwable) obj;
                                switch (i32) {
                                    case 0:
                                        int i42 = ar2.a;
                                        Object objNewInstance = constructor2.newInstance(th.getMessage(), th);
                                        cr4.e(objNewInstance, "null cannot be cast to non-null type kotlin.Throwable");
                                        return (Throwable) objNewInstance;
                                    case 1:
                                        int i5 = ar2.a;
                                        Object objNewInstance2 = constructor2.newInstance(th.getMessage());
                                        cr4.e(objNewInstance2, "null cannot be cast to non-null type kotlin.Throwable");
                                        Throwable th2 = (Throwable) objNewInstance2;
                                        th2.initCause(th);
                                        return th2;
                                    case 2:
                                        int i6 = ar2.a;
                                        Object objNewInstance3 = constructor2.newInstance(th);
                                        cr4.e(objNewInstance3, "null cannot be cast to non-null type kotlin.Throwable");
                                        return (Throwable) objNewInstance3;
                                    default:
                                        int i7 = ar2.a;
                                        Object objNewInstance4 = constructor2.newInstance(null);
                                        cr4.e(objNewInstance4, "null cannot be cast to non-null type kotlin.Throwable");
                                        Throwable th3 = (Throwable) objNewInstance4;
                                        th3.initCause(th);
                                        return th3;
                                }
                            }
                        }, 0), 3);
                    } else {
                        q07Var2 = new q07(null, -1);
                    }
                    arrayList.add(q07Var2);
                    i++;
                } else {
                    final int i5 = 3;
                    q07Var = new q07(new yq2(new sq3() { // from class: xq2
                        @Override // defpackage.sq3
                        public final Object invoke(Object obj) throws IllegalAccessException, InstantiationException, InvocationTargetException {
                            int i32 = i5;
                            Constructor constructor2 = constructor;
                            Throwable th = (Throwable) obj;
                            switch (i32) {
                                case 0:
                                    int i42 = ar2.a;
                                    Object objNewInstance = constructor2.newInstance(th.getMessage(), th);
                                    cr4.e(objNewInstance, "null cannot be cast to non-null type kotlin.Throwable");
                                    return (Throwable) objNewInstance;
                                case 1:
                                    int i52 = ar2.a;
                                    Object objNewInstance2 = constructor2.newInstance(th.getMessage());
                                    cr4.e(objNewInstance2, "null cannot be cast to non-null type kotlin.Throwable");
                                    Throwable th2 = (Throwable) objNewInstance2;
                                    th2.initCause(th);
                                    return th2;
                                case 2:
                                    int i6 = ar2.a;
                                    Object objNewInstance3 = constructor2.newInstance(th);
                                    cr4.e(objNewInstance3, "null cannot be cast to non-null type kotlin.Throwable");
                                    return (Throwable) objNewInstance3;
                                default:
                                    int i7 = ar2.a;
                                    Object objNewInstance4 = constructor2.newInstance(null);
                                    cr4.e(objNewInstance4, "null cannot be cast to non-null type kotlin.Throwable");
                                    Throwable th3 = (Throwable) objNewInstance4;
                                    th3.initCause(th);
                                    return th3;
                            }
                        }
                    }, 0), 0);
                }
                q07Var2 = q07Var;
                arrayList.add(q07Var2);
                i++;
            }
            Iterator it = arrayList.iterator();
            if (it.hasNext()) {
                next = it.next();
                if (it.hasNext()) {
                    int iIntValue = ((Number) ((q07) next).b).intValue();
                    do {
                        Object next2 = it.next();
                        int iIntValue2 = ((Number) ((q07) next2).b).intValue();
                        if (iIntValue < iIntValue2) {
                            next = next2;
                            iIntValue = iIntValue2;
                        }
                    } while (it.hasNext());
                }
            }
            q07 q07Var3 = (q07) next;
            if (q07Var3 != null && (sq3Var = (sq3) q07Var3.a) != null) {
                return sq3Var;
            }
        }
        return zq2.a;
    }

    public static final int b(Class cls, int i) {
        Object objA;
        h15.e(cls);
        int i2 = 0;
        do {
            try {
                int i3 = 0;
                for (Field field : cls.getDeclaredFields()) {
                    if (!Modifier.isStatic(field.getModifiers())) {
                        i3++;
                    }
                }
                i2 += i3;
                cls = cls.getSuperclass();
            } catch (Throwable th) {
                objA = s38.a(th);
            }
        } while (cls != null);
        objA = Integer.valueOf(i2);
        Object objValueOf = Integer.valueOf(i);
        if (objA instanceof q38.b) {
            objA = objValueOf;
        }
        return ((Number) objA).intValue();
    }
}
