package lp;

import dn.l;
import hp.b0;
import hp.d1;
import hp.e0;
import hp.e1;
import hp.f0;
import hp.h1;
import hp.j1;
import hp.l1;
import hp.m0;
import hp.m1;
import hp.p1;
import hp.r1;
import hp.s1;
import hp.t1;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import qn.g;
import sm.c0;
import uo.d;

/* loaded from: classes3.dex */
public abstract class b {

    /* loaded from: classes3.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f28493a;

        static {
            int[] iArr = new int[t1.values().length];
            try {
                iArr[t1.INVARIANT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[t1.IN_VARIANCE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[t1.OUT_VARIANCE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            f28493a = iArr;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: lp.b$b, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public static final class C0639b extends v implements l {

        /* renamed from: p, reason: collision with root package name */
        public static final C0639b f28494p = new C0639b();

        C0639b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(s1 s1Var) {
            t.d(s1Var);
            return Boolean.valueOf(d.d(s1Var));
        }
    }

    /* loaded from: classes3.dex */
    public static final class c extends e1 {
        c() {
        }

        @Override // hp.e1
        public h1 k(d1 key) {
            t.g(key, "key");
            uo.b bVar = key instanceof uo.b ? (uo.b) key : null;
            if (bVar == null) {
                return null;
            }
            return bVar.getProjection().b() ? new j1(t1.OUT_VARIANCE, bVar.getProjection().getType()) : bVar.getProjection();
        }
    }

    public static final lp.a a(e0 type) {
        List<rm.v> b12;
        Object e10;
        t.g(type, "type");
        if (b0.b(type)) {
            lp.a a10 = a(b0.c(type));
            lp.a a11 = a(b0.d(type));
            return new lp.a(r1.b(f0.d(b0.c((e0) a10.c()), b0.d((e0) a11.c())), type), r1.b(f0.d(b0.c((e0) a10.d()), b0.d((e0) a11.d())), type));
        }
        d1 K0 = type.K0();
        if (d.d(type)) {
            t.e(K0, "null cannot be cast to non-null type org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor");
            h1 projection = ((uo.b) K0).getProjection();
            e0 type2 = projection.getType();
            t.f(type2, "getType(...)");
            e0 b10 = b(type2, type);
            int i10 = a.f28493a[projection.a().ordinal()];
            if (i10 == 2) {
                m0 I = kp.a.i(type).I();
                t.f(I, "getNullableAnyType(...)");
                return new lp.a(b10, I);
            }
            if (i10 == 3) {
                m0 H = kp.a.i(type).H();
                t.f(H, "getNothingType(...)");
                return new lp.a(b(H, type), b10);
            }
            throw new AssertionError("Only nontrivial projections should have been captured, not: " + projection);
        }
        if (type.I0().isEmpty() || type.I0().size() != K0.getParameters().size()) {
            return new lp.a(type, type);
        }
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        List I0 = type.I0();
        List parameters = K0.getParameters();
        t.f(parameters, "getParameters(...)");
        b12 = c0.b1(I0, parameters);
        for (rm.v vVar : b12) {
            h1 h1Var = (h1) vVar.a();
            tn.e1 e1Var = (tn.e1) vVar.b();
            t.d(e1Var);
            lp.c g10 = g(h1Var, e1Var);
            if (h1Var.b()) {
                arrayList.add(g10);
                arrayList2.add(g10);
            } else {
                lp.a d10 = d(g10);
                lp.c cVar = (lp.c) d10.a();
                lp.c cVar2 = (lp.c) d10.b();
                arrayList.add(cVar);
                arrayList2.add(cVar2);
            }
        }
        boolean z10 = false;
        if (!arrayList.isEmpty()) {
            Iterator it = arrayList.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                if (!((lp.c) it.next()).d()) {
                    z10 = true;
                    break;
                }
            }
        }
        if (z10) {
            e10 = kp.a.i(type).H();
            t.f(e10, "getNothingType(...)");
        } else {
            e10 = e(type, arrayList);
        }
        return new lp.a(e10, e(type, arrayList2));
    }

    private static final e0 b(e0 e0Var, e0 e0Var2) {
        e0 q10 = p1.q(e0Var, e0Var2.L0());
        t.f(q10, "makeNullableIfNeeded(...)");
        return q10;
    }

    public static final h1 c(h1 h1Var, boolean z10) {
        if (h1Var == null) {
            return null;
        }
        if (h1Var.b()) {
            return h1Var;
        }
        e0 type = h1Var.getType();
        t.f(type, "getType(...)");
        if (!p1.c(type, C0639b.f28494p)) {
            return h1Var;
        }
        t1 a10 = h1Var.a();
        t.f(a10, "getProjectionKind(...)");
        return a10 == t1.OUT_VARIANCE ? new j1(a10, (e0) a(type).d()) : z10 ? new j1(a10, (e0) a(type).c()) : f(h1Var);
    }

    private static final lp.a d(lp.c cVar) {
        lp.a a10 = a(cVar.a());
        e0 e0Var = (e0) a10.a();
        e0 e0Var2 = (e0) a10.b();
        lp.a a11 = a(cVar.b());
        return new lp.a(new lp.c(cVar.c(), e0Var2, (e0) a11.a()), new lp.c(cVar.c(), e0Var, (e0) a11.b()));
    }

    private static final e0 e(e0 e0Var, List list) {
        int v10;
        e0Var.I0().size();
        list.size();
        List list2 = list;
        v10 = sm.v.v(list2, 10);
        ArrayList arrayList = new ArrayList(v10);
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            arrayList.add(h((lp.c) it.next()));
        }
        return l1.e(e0Var, arrayList, null, null, 6, null);
    }

    private static final h1 f(h1 h1Var) {
        m1 g10 = m1.g(new c());
        t.f(g10, "create(...)");
        return g10.t(h1Var);
    }

    private static final lp.c g(h1 h1Var, tn.e1 e1Var) {
        int i10 = a.f28493a[m1.c(e1Var.l(), h1Var).ordinal()];
        if (i10 == 1) {
            e0 type = h1Var.getType();
            t.f(type, "getType(...)");
            e0 type2 = h1Var.getType();
            t.f(type2, "getType(...)");
            return new lp.c(e1Var, type, type2);
        }
        if (i10 == 2) {
            e0 type3 = h1Var.getType();
            t.f(type3, "getType(...)");
            m0 I = xo.c.j(e1Var).I();
            t.f(I, "getNullableAnyType(...)");
            return new lp.c(e1Var, type3, I);
        }
        if (i10 != 3) {
            throw new rm.t();
        }
        m0 H = xo.c.j(e1Var).H();
        t.f(H, "getNothingType(...)");
        e0 type4 = h1Var.getType();
        t.f(type4, "getType(...)");
        return new lp.c(e1Var, H, type4);
    }

    private static final h1 h(lp.c cVar) {
        cVar.d();
        if (!t.b(cVar.a(), cVar.b())) {
            t1 l10 = cVar.c().l();
            t1 t1Var = t1.IN_VARIANCE;
            if (l10 != t1Var) {
                if ((!g.n0(cVar.a()) || cVar.c().l() == t1Var) && g.p0(cVar.b())) {
                    return new j1(i(cVar, t1Var), cVar.a());
                }
                return new j1(i(cVar, t1.OUT_VARIANCE), cVar.b());
            }
        }
        return new j1(cVar.a());
    }

    private static final t1 i(lp.c cVar, t1 t1Var) {
        return t1Var == cVar.c().l() ? t1.INVARIANT : t1Var;
    }
}
