package h.b;

import g.h0.c.b0;
import g.o;
import h.b.o.g1;
import h.b.o.l0;
import h.b.o.o1;
import h.b.o.q0;
import h.b.o.x0;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/* JADX INFO: compiled from: SerializersJvm.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final /* synthetic */ class k {
    public static final Class<?> a(Type type) {
        if (type instanceof Class) {
            return (Class) type;
        }
        if (type instanceof ParameterizedType) {
            Type rawType = ((ParameterizedType) type).getRawType();
            g.h0.c.l.e(rawType, "it.rawType");
            return a(rawType);
        }
        if (type instanceof WildcardType) {
            Type[] upperBounds = ((WildcardType) type).getUpperBounds();
            g.h0.c.l.e(upperBounds, "it.upperBounds");
            Object objY = f.a.y.a.Y(upperBounds);
            g.h0.c.l.e(objY, "it.upperBounds.first()");
            return a((Type) objY);
        }
        if (type instanceof GenericArrayType) {
            Type genericComponentType = ((GenericArrayType) type).getGenericComponentType();
            g.h0.c.l.e(genericComponentType, "it.genericComponentType");
            return a(genericComponentType);
        }
        throw new IllegalArgumentException("typeToken should be an instance of Class<?>, GenericArray, ParametrizedType or WildcardType, but actual type is " + type + ' ' + b0.a(type.getClass()));
    }

    /* JADX WARN: Code restructure failed: missing block: B:73:0x0142, code lost:
    
        r13 = null;
     */
    /* JADX WARN: Removed duplicated region for block: B:102:0x01a3 A[PHI: r2
      0x01a3: PHI (r2v2 int) = (r2v0 int), (r2v7 int), (r2v7 int) binds: [B:74:0x0143, B:97:0x0193, B:100:0x019e] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:120:0x01de  */
    /* JADX WARN: Removed duplicated region for block: B:12:0x005f  */
    /* JADX WARN: Removed duplicated region for block: B:150:0x01a8 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00fb  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00fe A[PHI: r3
      0x00fe: PHI (r3v36 h.b.b<T>) = (r3v13 h.b.b<T>), (r3v16 h.b.b<T>), (r3v18 h.b.b<T>) binds: [B:54:0x00fc, B:103:0x01a4, B:127:0x01e9] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0101  */
    /* JADX WARN: Removed duplicated region for block: B:88:0x0182  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static final <T> h.b.b<T> b(h.b.q.c r16, java.lang.Class<T> r17, java.util.List<? extends h.b.b<java.lang.Object>> r18) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException {
        /*
            Method dump skipped, instruction units count: 573
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: h.b.k.b(h.b.q.c, java.lang.Class, java.util.List):h.b.b");
    }

    public static final b<Object> c(h.b.q.c cVar, Type type, boolean z) {
        ArrayList<b> arrayList;
        b<Object> bVarQ0;
        b<Object> bVarQ02;
        g.k0.c cVarE0;
        if (type instanceof GenericArrayType) {
            Type genericComponentType = ((GenericArrayType) type).getGenericComponentType();
            if (genericComponentType instanceof WildcardType) {
                Type[] upperBounds = ((WildcardType) genericComponentType).getUpperBounds();
                g.h0.c.l.e(upperBounds, "it.upperBounds");
                genericComponentType = (Type) f.a.y.a.Y(upperBounds);
            }
            g.h0.c.l.e(genericComponentType, "eType");
            if (z) {
                bVarQ02 = f.a.y.a.P0(cVar, genericComponentType);
            } else {
                bVarQ02 = f.a.y.a.Q0(cVar, genericComponentType);
                if (bVarQ02 == null) {
                    return null;
                }
            }
            if (genericComponentType instanceof ParameterizedType) {
                Type rawType = ((ParameterizedType) genericComponentType).getRawType();
                g.h0.c.l.d(rawType, "null cannot be cast to non-null type java.lang.Class<*>");
                cVarE0 = f.a.y.a.e0((Class) rawType);
            } else {
                if (!(genericComponentType instanceof g.k0.c)) {
                    StringBuilder sbB = d.b.a.a.a.B("unsupported type in GenericArray: ");
                    sbB.append(b0.a(genericComponentType.getClass()));
                    throw new IllegalStateException(sbB.toString());
                }
                cVarE0 = (g.k0.c) genericComponentType;
            }
            g.h0.c.l.d(cVarE0, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
            g.h0.c.l.f(cVarE0, "kClass");
            g.h0.c.l.f(bVarQ02, "elementSerializer");
            g1 g1Var = new g1(cVarE0, bVarQ02);
            g.h0.c.l.d(g1Var, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return g1Var;
        }
        if (type instanceof Class) {
            Class cls = (Class) type;
            if (!cls.isArray() || cls.getComponentType().isPrimitive()) {
                g.h0.c.l.d(cls, "null cannot be cast to non-null type java.lang.Class<kotlin.Any>");
                return b(cVar, cls, g.c0.l.f4067b);
            }
            Class<?> componentType = cls.getComponentType();
            g.h0.c.l.e(componentType, "type.componentType");
            if (z) {
                bVarQ0 = f.a.y.a.P0(cVar, componentType);
            } else {
                bVarQ0 = f.a.y.a.Q0(cVar, componentType);
                if (bVarQ0 == null) {
                    return null;
                }
            }
            g.k0.c cVarE02 = f.a.y.a.e0(componentType);
            g.h0.c.l.d(cVarE02, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
            g.h0.c.l.f(cVarE02, "kClass");
            g.h0.c.l.f(bVarQ0, "elementSerializer");
            g1 g1Var2 = new g1(cVarE02, bVarQ0);
            g.h0.c.l.d(g1Var2, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return g1Var2;
        }
        if (!(type instanceof ParameterizedType)) {
            if (type instanceof WildcardType) {
                Type[] upperBounds2 = ((WildcardType) type).getUpperBounds();
                g.h0.c.l.e(upperBounds2, "type.upperBounds");
                Object objY = f.a.y.a.Y(upperBounds2);
                g.h0.c.l.e(objY, "type.upperBounds.first()");
                return c(cVar, (Type) objY, true);
            }
            throw new IllegalArgumentException("typeToken should be an instance of Class<?>, GenericArray, ParametrizedType or WildcardType, but actual type is " + type + ' ' + b0.a(type.getClass()));
        }
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type rawType2 = parameterizedType.getRawType();
        g.h0.c.l.d(rawType2, "null cannot be cast to non-null type java.lang.Class<*>");
        Class cls2 = (Class) rawType2;
        Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
        g.h0.c.l.e(actualTypeArguments, "args");
        if (z) {
            arrayList = new ArrayList(actualTypeArguments.length);
            for (Type type2 : actualTypeArguments) {
                g.h0.c.l.e(type2, "it");
                arrayList.add(f.a.y.a.P0(cVar, type2));
            }
        } else {
            arrayList = new ArrayList(actualTypeArguments.length);
            for (Type type3 : actualTypeArguments) {
                g.h0.c.l.e(type3, "it");
                b<Object> bVarQ03 = f.a.y.a.Q0(cVar, type3);
                if (bVarQ03 == null) {
                    return null;
                }
                arrayList.add(bVarQ03);
            }
        }
        if (Set.class.isAssignableFrom(cls2)) {
            b bVar = (b) arrayList.get(0);
            g.h0.c.l.f(bVar, "elementSerializer");
            l0 l0Var = new l0(bVar);
            g.h0.c.l.d(l0Var, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return l0Var;
        }
        if (List.class.isAssignableFrom(cls2) || Collection.class.isAssignableFrom(cls2)) {
            b<Object> bVarH = f.a.y.a.h((b) arrayList.get(0));
            g.h0.c.l.d(bVarH, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return bVarH;
        }
        if (Map.class.isAssignableFrom(cls2)) {
            b<Object> bVarI = f.a.y.a.i((b) arrayList.get(0), (b) arrayList.get(1));
            g.h0.c.l.d(bVarI, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return bVarI;
        }
        if (Map.Entry.class.isAssignableFrom(cls2)) {
            b bVar2 = (b) arrayList.get(0);
            b bVar3 = (b) arrayList.get(1);
            g.h0.c.l.f(bVar2, "keySerializer");
            g.h0.c.l.f(bVar3, "valueSerializer");
            q0 q0Var = new q0(bVar2, bVar3);
            g.h0.c.l.d(q0Var, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return q0Var;
        }
        if (g.k.class.isAssignableFrom(cls2)) {
            b bVar4 = (b) arrayList.get(0);
            b bVar5 = (b) arrayList.get(1);
            g.h0.c.l.f(bVar4, "keySerializer");
            g.h0.c.l.f(bVar5, "valueSerializer");
            x0 x0Var = new x0(bVar4, bVar5);
            g.h0.c.l.d(x0Var, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
            return x0Var;
        }
        if (!o.class.isAssignableFrom(cls2)) {
            ArrayList arrayList2 = new ArrayList(f.a.y.a.C(arrayList, 10));
            for (b bVar6 : arrayList) {
                g.h0.c.l.d(bVar6, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any?>");
                arrayList2.add(bVar6);
            }
            return b(cVar, cls2, arrayList2);
        }
        b bVar7 = (b) arrayList.get(0);
        b bVar8 = (b) arrayList.get(1);
        b bVar9 = (b) arrayList.get(2);
        g.h0.c.l.f(bVar7, "aSerializer");
        g.h0.c.l.f(bVar8, "bSerializer");
        g.h0.c.l.f(bVar9, "cSerializer");
        o1 o1Var = new o1(bVar7, bVar8, bVar9);
        g.h0.c.l.d(o1Var, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
        return o1Var;
    }
}
