package kotlin.reflect.w.internal.y0.n;

import d.f.a.g;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.o;
import kotlin.reflect.w.internal.y0.c.f;
import kotlin.reflect.w.internal.y0.c.i;
import kotlin.reflect.w.internal.y0.d.b1;
import kotlin.reflect.w.internal.y0.d.l1.k;
import kotlin.reflect.w.internal.y0.d.l1.l;
import kotlin.reflect.w.internal.y0.n.a2.i;
import kotlin.reflect.w.internal.y0.n.a2.j;
import kotlin.reflect.w.internal.y0.n.c2.c;
import kotlin.reflect.w.internal.y0.n.d2.b;
import kotlin.reflect.w.internal.y0.n.z1.h;

/* JADX INFO: loaded from: classes2.dex */
public class r1 {
    public static final r1 a = e(o1.a);

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

    public static final class a extends Exception {
        public a(String str) {
            super(str);
        }
    }

    public r1(o1 o1Var) {
        if (o1Var != null) {
            this.f8980b = o1Var;
        } else {
            a(7);
            throw null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0021 A[FALL_THROUGH] */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00b8  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static /* synthetic */ void a(int r13) {
        /*
            Method dump skipped, instruction units count: 660
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: kotlin.reflect.w.internal.y0.n.r1.a(int):void");
    }

    public static x1 b(x1 x1Var, x1 x1Var2) {
        if (x1Var == null) {
            a(38);
            throw null;
        }
        if (x1Var2 == null) {
            a(39);
            throw null;
        }
        x1 x1Var3 = x1.INVARIANT;
        if (x1Var == x1Var3) {
            if (x1Var2 != null) {
                return x1Var2;
            }
            a(40);
            throw null;
        }
        if (x1Var2 == x1Var3) {
            if (x1Var != null) {
                return x1Var;
            }
            a(41);
            throw null;
        }
        if (x1Var == x1Var2) {
            if (x1Var2 != null) {
                return x1Var2;
            }
            a(42);
            throw null;
        }
        throw new AssertionError("Variance conflict: type parameter variance '" + x1Var + "' and projection kind '" + x1Var2 + "' cannot be combined");
    }

    public static int c(x1 x1Var, x1 x1Var2) {
        x1 x1Var3 = x1.OUT_VARIANCE;
        x1 x1Var4 = x1.IN_VARIANCE;
        if (x1Var == x1Var4 && x1Var2 == x1Var3) {
            return 3;
        }
        return (x1Var == x1Var3 && x1Var2 == x1Var4) ? 2 : 1;
    }

    public static r1 d(h0 h0Var) {
        if (h0Var == null) {
            a(6);
            throw null;
        }
        return e(g1.f8930b.b(h0Var.L0(), h0Var.J0()));
    }

    public static r1 e(o1 o1Var) {
        return new r1(o1Var);
    }

    public static r1 f(o1 o1Var, o1 o1Var2) {
        if (o1Var == null) {
            a(3);
            throw null;
        }
        if (o1Var2 == null) {
            a(4);
            throw null;
        }
        o.f(o1Var, "first");
        o.f(o1Var2, "second");
        if (o1Var.f()) {
            o1Var = o1Var2;
        } else if (!o1Var2.f()) {
            o1Var = new x(o1Var, o1Var2, null);
        }
        return e(o1Var);
    }

    public static String j(Object obj) {
        try {
            return obj.toString();
        } catch (Throwable th) {
            if (c.c0(th)) {
                throw th;
            }
            return "[Exception while computing toString(): " + th + "]";
        }
    }

    public o1 g() {
        o1 o1Var = this.f8980b;
        if (o1Var != null) {
            return o1Var;
        }
        a(8);
        throw null;
    }

    public boolean h() {
        return this.f8980b.f();
    }

    public h0 i(h0 h0Var, x1 x1Var) {
        if (h0Var == null) {
            a(9);
            throw null;
        }
        if (h()) {
            return h0Var;
        }
        try {
            h0 type = m(new n1(x1Var, h0Var), null, 0).getType();
            if (type != null) {
                return type;
            }
            a(12);
            throw null;
        } catch (a e2) {
            return j.c(i.UNABLE_TO_SUBSTITUTE_TYPE, e2.getMessage());
        }
    }

    public h0 k(h0 h0Var, x1 x1Var) {
        n1 n1Var;
        if (h0Var == null) {
            a(14);
            throw null;
        }
        if (x1Var == null) {
            a(15);
            throw null;
        }
        l1 l1VarL = l(new n1(x1Var, g().g(h0Var, x1Var)));
        if (this.f8980b.a() || this.f8980b.b()) {
            boolean zB = this.f8980b.b();
            if (l1VarL == null) {
                l1VarL = null;
            } else if (!l1VarL.c()) {
                h0 type = l1VarL.getType();
                o.e(type, "typeProjection.type");
                if (u1.c(type, b.f8905f)) {
                    x1 x1VarB = l1VarL.b();
                    o.e(x1VarB, "typeProjection.projectionKind");
                    if (x1VarB == x1.OUT_VARIANCE) {
                        n1Var = new n1(x1VarB, c.i(type).f8904b);
                    } else if (zB) {
                        n1Var = new n1(x1VarB, c.i(type).a);
                    } else {
                        r1 r1VarE = e(new kotlin.reflect.w.internal.y0.n.d2.c());
                        o.e(r1VarE, "create(object : TypeCons…ojection\n        }\n    })");
                        l1VarL = r1VarE.l(l1VarL);
                    }
                    l1VarL = n1Var;
                }
            }
        }
        if (l1VarL == null) {
            return null;
        }
        return l1VarL.getType();
    }

    public l1 l(l1 l1Var) {
        if (l1Var == null) {
            a(17);
            throw null;
        }
        if (h()) {
            return l1Var;
        }
        try {
            return m(l1Var, null, 0);
        } catch (a unused) {
            return null;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public final l1 m(l1 l1Var, b1 b1Var, int i2) throws a {
        r1 r1Var;
        int i3 = i2;
        h0 h0VarK = null;
        if (l1Var == null) {
            a(18);
            throw null;
        }
        o1 o1Var = this.f8980b;
        if (i3 > 100) {
            StringBuilder sbF = g.a.a.a.a.F("Recursion too deep. Most likely infinite loop while substituting ");
            sbF.append(j(l1Var));
            sbF.append("; substitution: ");
            sbF.append(j(o1Var));
            throw new IllegalStateException(sbF.toString());
        }
        if (l1Var.c()) {
            return l1Var;
        }
        h0 type = l1Var.getType();
        if (type instanceof v1) {
            v1 v1Var = (v1) type;
            w1 w1VarD0 = v1Var.D0();
            h0 h0VarF = v1Var.F();
            l1 l1VarM = m(new n1(l1Var.b(), w1VarD0), b1Var, i3 + 1);
            return l1VarM.c() ? l1VarM : new n1(l1VarM.b(), g.h.a.i.Z3(l1VarM.getType().O0(), k(h0VarF, l1Var.b())));
        }
        if (!g.h.a.i.k2(type) && !(type.O0() instanceof n0)) {
            l1 l1VarE = this.f8980b.e(type);
            if (l1VarE == null) {
                l1VarE = null;
            } else if (type.getAnnotations().m(i.a.A)) {
                e1 e1VarL0 = l1VarE.getType().L0();
                if (e1VarL0 instanceof h) {
                    l1 l1Var2 = ((h) e1VarL0).a;
                    x1 x1VarB = l1Var2.b();
                    if (c(l1Var.b(), x1VarB) == 3) {
                        l1VarE = new n1(l1Var2.getType());
                    } else if (b1Var != null && c(b1Var.n(), x1VarB) == 3) {
                        l1VarE = new n1(l1Var2.getType());
                    }
                }
            }
            x1 x1VarB2 = l1Var.b();
            int i4 = 0;
            if (l1VarE == null && g.h.a.i.q2(type)) {
                o.f(type, "<this>");
                kotlin.reflect.w.internal.y0.d.l1.a aVarO0 = type.O0();
                r rVar = aVarO0 instanceof r ? (r) aVarO0 : null;
                if (!(rVar != null ? rVar.y0() : false)) {
                    b0 b0VarR = g.h.a.i.r(type);
                    int i5 = i3 + 1;
                    l1 l1VarM2 = m(new n1(x1VarB2, b0VarR.f8878m), b1Var, i5);
                    l1 l1VarM3 = m(new n1(x1VarB2, b0VarR.f8879n), b1Var, i5);
                    return (l1VarM2.getType() == b0VarR.f8878m && l1VarM3.getType() == b0VarR.f8879n) ? l1Var : new n1(l1VarM2.b(), i0.c(s0.a(l1VarM2.getType()), s0.a(l1VarM3.getType())));
                }
            }
            if (!f.H(type) && !g.h.a.i.o2(type)) {
                if (l1VarE != null) {
                    int iC = c(x1VarB2, l1VarE.b());
                    if (!g.h.a.i.j2(type)) {
                        int iA = g.a(iC);
                        if (iA == 1) {
                            return new n1(x1.OUT_VARIANCE, type.L0().o().q());
                        }
                        if (iA == 2) {
                            throw new a("Out-projection in in-position");
                        }
                    }
                    o.f(type, "<this>");
                    kotlin.reflect.w.internal.y0.d.l1.a aVarO02 = type.O0();
                    r rVar2 = aVarO02 instanceof r ? (r) aVarO02 : null;
                    if (rVar2 == null || !rVar2.y0()) {
                        rVar2 = null;
                    }
                    if (l1VarE.c()) {
                        return l1VarE;
                    }
                    h0 h0VarJ = rVar2 != null ? rVar2.J(l1VarE.getType()) : u1.k(l1VarE.getType(), type.M0());
                    if (!type.getAnnotations().isEmpty()) {
                        kotlin.reflect.w.internal.y0.d.l1.h hVarD = this.f8980b.d(type.getAnnotations());
                        if (hVarD == null) {
                            a(33);
                            throw null;
                        }
                        if (hVarD.m(i.a.A)) {
                            hVarD = new l(hVarD, new q1());
                        }
                        h0VarJ = c.v0(h0VarJ, new k(h0VarJ.getAnnotations(), hVarD));
                    }
                    if (iC == 1) {
                        x1VarB2 = b(x1VarB2, l1VarE.b());
                    }
                    return new n1(x1VarB2, h0VarJ);
                }
                x1 x1Var = x1.INVARIANT;
                h0 type2 = l1Var.getType();
                x1 x1VarB3 = l1Var.b();
                if (type2.L0().c() instanceof b1) {
                    return l1Var;
                }
                o.f(type2, "<this>");
                o.f(type2, "<this>");
                w1 w1VarO0 = type2.O0();
                kotlin.reflect.w.internal.y0.n.a aVar = w1VarO0 instanceof kotlin.reflect.w.internal.y0.n.a ? (kotlin.reflect.w.internal.y0.n.a) w1VarO0 : null;
                o0 o0Var = aVar != null ? aVar.f8822n : null;
                if (o0Var != null) {
                    o1 o1Var2 = this.f8980b;
                    if ((o1Var2 instanceof e0) && o1Var2.b()) {
                        e0 e0Var = (e0) this.f8980b;
                        r1Var = new r1(new e0(e0Var.f8911b, e0Var.f8912c, false));
                    } else {
                        r1Var = this;
                    }
                    h0VarK = r1Var.k(o0Var, x1Var);
                }
                List<b1> parameters = type2.L0().getParameters();
                List<l1> listJ0 = type2.J0();
                ArrayList arrayList = new ArrayList(parameters.size());
                boolean z2 = false;
                while (i4 < parameters.size()) {
                    b1 b1Var2 = parameters.get(i4);
                    l1 l1Var3 = listJ0.get(i4);
                    l1 l1VarM4 = m(l1Var3, b1Var2, i3 + 1);
                    int iA2 = g.a(c(b1Var2.n(), l1VarM4.b()));
                    if (iA2 != 0) {
                        if (iA2 == 1 || iA2 == 2) {
                            l1VarM4 = u1.m(b1Var2);
                        }
                    } else if (b1Var2.n() != x1Var && !l1VarM4.c()) {
                        l1VarM4 = new n1(x1Var, l1VarM4.getType());
                    }
                    if (l1VarM4 != l1Var3) {
                        z2 = true;
                    }
                    arrayList.add(l1VarM4);
                    i4++;
                    i3 = i2;
                }
                if (z2) {
                    listJ0 = arrayList;
                }
                kotlin.reflect.w.internal.y0.d.l1.h hVarD2 = this.f8980b.d(type2.getAnnotations());
                o.f(type2, "<this>");
                o.f(listJ0, "newArguments");
                o.f(hVarD2, "newAnnotations");
                h0 h0VarG = s0.g(type2, listJ0, hVarD2, null, 4);
                if ((h0VarG instanceof o0) && (h0VarK instanceof o0)) {
                    h0VarG = s0.k((o0) h0VarG, (o0) h0VarK);
                }
                return new n1(x1VarB3, h0VarG);
            }
        }
        return l1Var;
    }
}
