package a.i.b.a.c.e.b.a;

import a.f.a.b;
import a.f.b.j;
import a.f.b.z;
import a.i.b.a.c.e.a.a;
import a.i.b.a.c.e.a.d;
import a.i.b.a.c.e.a.w;
import a.i.b.a.c.e.b.a.c;
import a.i.b.a.c.g.o;
import a.v;
import a.y;
import com.tencent.matrix.trace.core.AppMethodBeat;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class k$a {
    private k$a() {
    }

    public /* synthetic */ k$a(byte b) {
        this();
    }

    public static k a(byte[] bArr, String str, b<? super g, y> bVar) {
        AppMethodBeat.i(121339);
        j.p(str, "debugName");
        j.p(bVar, "reportIncompatibleVersionError");
        k kVar;
        if (bArr == null) {
            kVar = k.ByH;
            AppMethodBeat.o(121339);
            return kVar;
        }
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bArr));
        try {
            int readInt = dataInputStream.readInt();
            int[] iArr = new int[readInt];
            for (int i = 0; i < readInt; i++) {
                iArr[i] = dataInputStream.readInt();
            }
            g gVar = new g(Arrays.copyOf(iArr, readInt));
            if (gVar.ehy()) {
                g gVar2 = new g(iArr, ((a.i.b.a.c.e.a.j.a((a) gVar) ? dataInputStream.readInt() : 0) & 1) != 0);
                if (gVar2.ehy()) {
                    a.i.b.a.c.e.b.a.a Q = a.i.b.a.c.e.b.a.a.Q(dataInputStream);
                    if (Q == null) {
                        kVar = k.ByH;
                        AppMethodBeat.o(121339);
                        return kVar;
                    }
                    Map map;
                    m mVar;
                    String str2;
                    o oVar;
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    for (c cVar : Q.Bxl) {
                        List list;
                        Integer num;
                        j.o(cVar, "proto");
                        String egA = cVar.egA();
                        map = linkedHashMap;
                        j.o(egA, "packageFqName");
                        m mVar2 = map.get(egA);
                        if (mVar2 == null) {
                            mVar2 = new m(egA);
                            map.put(egA, mVar2);
                            mVar = mVar2;
                        } else {
                            mVar = mVar2;
                        }
                        m mVar3 = mVar;
                        o oVar2 = cVar.Bxs;
                        j.o(oVar2, "proto.shortClassNameList");
                        int i2 = 0;
                        for (String str3 : (Iterable) oVar2) {
                            list = cVar.Bxt;
                            j.o(list, "proto.multifileFacadeShortNameIdList");
                            num = (Integer) a.a.j.x(list, i2);
                            num = num != null ? Integer.valueOf(num.intValue() - 1) : null;
                            if (num != null) {
                                o oVar3 = cVar.Bxv;
                                j.o(oVar3, "proto.multifileFacadeShortNameList");
                                str2 = (String) a.a.j.x((List) oVar3, num.intValue());
                            } else {
                                str2 = null;
                            }
                            str2 = str2 != null ? l.iX(egA, str2) : null;
                            j.o(str3, "partShortName");
                            mVar3.iY(l.iX(egA, str3), str2);
                            i2++;
                        }
                        oVar2 = cVar.Bxw;
                        j.o(oVar2, "proto.classWithJvmPackageNameShortNameList");
                        readInt = 0;
                        for (String str32 : (Iterable) oVar2) {
                            list = cVar.Bxx;
                            j.o(list, "proto.classWithJvmPackageNamePackageIdList");
                            num = (Integer) a.a.j.x(list, readInt);
                            if (num == null) {
                                list = cVar.Bxx;
                                j.o(list, "proto.classWithJvmPackageNamePackageIdList");
                                num = (Integer) a.a.j.fM(list);
                            }
                            if (num != null) {
                                int intValue = num.intValue();
                                oVar = Q.Bxn;
                                j.o(oVar, "moduleProto.jvmPackageNameList");
                                str2 = (String) a.a.j.x((List) oVar, intValue);
                                if (str2 != null) {
                                    j.o(str32, "partShortName");
                                    mVar3.iY(l.iX(str2, str32), null);
                                }
                            }
                            readInt++;
                        }
                    }
                    for (c cVar2 : Q.Bxm) {
                        map = linkedHashMap;
                        j.o(cVar2, "proto");
                        String egA2 = cVar2.egA();
                        j.o(egA2, "proto.packageFqName");
                        m mVar4 = map.get(egA2);
                        if (mVar4 == null) {
                            String egA3 = cVar2.egA();
                            j.o(egA3, "proto.packageFqName");
                            mVar4 = new m(egA3);
                            map.put(egA2, mVar4);
                            mVar = mVar4;
                        } else {
                            mVar = mVar4;
                        }
                        mVar = mVar;
                        oVar = cVar2.Bxs;
                        j.o(oVar, "proto.shortClassNameList");
                        for (String str22 : (Iterable) oVar) {
                            j.p(str22, "shortName");
                            Set set = mVar.ByL;
                            if (set == null) {
                                v vVar = new v("null cannot be cast to non-null type kotlin.collections.MutableSet<kotlin.String>");
                                AppMethodBeat.o(121339);
                                throw vVar;
                            }
                            z.dr(set).add(str22);
                        }
                    }
                    a.i.b.a.c.e.a.y yVar = Q.Bxo;
                    j.o(yVar, "moduleProto.stringTable");
                    w wVar = Q.Bxp;
                    j.o(wVar, "moduleProto.qualifiedNameTable");
                    d dVar = new d(yVar, wVar);
                    List list2 = Q.BvA;
                    j.o(list2, "moduleProto.annotationList");
                    Iterable<a.i.b.a.c.e.a.a> iterable = list2;
                    Collection arrayList = new ArrayList(a.a.j.d(iterable));
                    for (a.i.b.a.c.e.a.a aVar : iterable) {
                        j.o(aVar, "proto");
                        arrayList.add(dVar.Uh(aVar.BsE));
                    }
                    kVar = new k(linkedHashMap, new a((List) arrayList), str, (byte) 0);
                    AppMethodBeat.o(121339);
                    return kVar;
                }
                bVar.am(gVar2);
                kVar = k.ByH;
                AppMethodBeat.o(121339);
                return kVar;
            }
            bVar.am(gVar);
            kVar = k.ByH;
            AppMethodBeat.o(121339);
            return kVar;
        } catch (IOException e) {
            kVar = k.ByI;
            AppMethodBeat.o(121339);
            return kVar;
        }
    }
}
