package com.google.android.gms.internal.ads;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;

/* JADX INFO: loaded from: classes2.dex */
public final class lj1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final kotlinx.coroutines.internal.e f13731a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final kotlinx.coroutines.sync.c f13732b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final kotlinx.coroutines.sync.c f13733c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final kotlinx.coroutines.sync.c f13734d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f13735e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public zi1 f13736f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f13737g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final androidx.datastore.core.h f13738h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final iq0 f13739i;

    public lj1(androidx.datastore.core.h hVar, ij1 ij1Var, iq0 iq0Var, w80 w80Var) {
        nb.g.i(hVar, "adQualityDataStore");
        nb.g.i(iq0Var, "dataPinger");
        this.f13739i = iq0Var;
        this.f13731a = kotlinx.coroutines.y.b(new kotlinx.coroutines.s0(ij1Var.f12540a));
        this.f13732b = kotlinx.coroutines.sync.d.a();
        this.f13733c = kotlinx.coroutines.sync.d.a();
        this.f13734d = kotlinx.coroutines.sync.d.a();
        this.f13738h = hVar;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0091  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX WARN: Type inference failed for: r18v0, types: [com.google.android.gms.internal.ads.lj1] */
    /* JADX WARN: Type inference failed for: r4v0, types: [int] */
    /* JADX WARN: Type inference failed for: r4v1, types: [kotlinx.coroutines.sync.a] */
    /* JADX WARN: Type inference failed for: r4v21 */
    /* JADX WARN: Type inference failed for: r4v22 */
    /* JADX WARN: Type inference failed for: r4v5, types: [kotlinx.coroutines.sync.a] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object a(Continuation continuation) {
        zzfzz zzfzzVar;
        kotlinx.coroutines.sync.a aVar;
        dj1 dj1Var;
        if (continuation instanceof zzfzz) {
            zzfzzVar = (zzfzz) continuation;
            int i10 = zzfzzVar.zzd;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzzVar.zzd = i10 - Integer.MIN_VALUE;
            } else {
                zzfzzVar = new zzfzz(this, continuation);
            }
        }
        Object objG = zzfzzVar.zzb;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        ?? r42 = zzfzzVar.zzd;
        kd.e eVar = kd.e.f29109a;
        try {
            if (r42 == 0) {
                kotlin.a.d(objG);
                kotlinx.coroutines.sync.c cVar = this.f13734d;
                zzfzzVar.zza = cVar;
                zzfzzVar.zzd = 1;
                if (cVar.e(zzfzzVar) != coroutineSingletons) {
                    aVar = cVar;
                }
                return coroutineSingletons;
            }
            if (r42 != 1) {
                if (r42 != 2) {
                    if (r42 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    kotlin.a.d(objG);
                    return eVar;
                }
                kotlinx.coroutines.sync.a aVar2 = (kotlinx.coroutines.sync.a) zzfzzVar.zza;
                kotlin.a.d(objG);
                r42 = aVar2;
                dj1Var = (dj1) objG;
                if (dj1Var != null && dj1Var.B() != 0) {
                    for (Map.Entry entry : dj1Var.C().entrySet()) {
                        zi1 zi1Var = (zi1) ((aj1) entry.getValue()).s();
                        Object value = entry.getValue();
                        nb.g.h(value, "<get-value>(...)");
                        aj1 aj1Var = (aj1) value;
                        ib2 ib2VarN = aj1Var.N();
                        Long l10 = ib2VarN != null ? (Long) (ib2VarN.isEmpty() ? null : ib2VarN.get(ib2VarN.size() - 1)) : null;
                        boolean z10 = false;
                        boolean z11 = aj1Var.O() > aj1Var.P() && !aj1Var.H();
                        if (l10 != null) {
                            if (aj1Var.L() - l10.longValue() > 5000) {
                                z10 = true;
                            }
                        }
                        if (z11 || z10) {
                            zi1Var.c();
                            ((aj1) zi1Var.f8617b).X(true);
                        }
                        this.f13739i.a((aj1) zi1Var.e());
                    }
                    zzfzzVar.zza = null;
                    zzfzzVar.zzd = 3;
                    if (i(zzfzzVar) != coroutineSingletons) {
                        return coroutineSingletons;
                    }
                }
                return eVar;
            }
            kotlinx.coroutines.sync.a aVar3 = (kotlinx.coroutines.sync.a) zzfzzVar.zza;
            kotlin.a.d(objG);
            aVar = aVar3;
            kotlinx.coroutines.flow.f data = this.f13738h.getData();
            zzfzzVar.zza = aVar;
            zzfzzVar.zzd = 2;
            objG = kotlinx.coroutines.flow.h.g(data, zzfzzVar);
            r42 = aVar;
            if (objG != coroutineSingletons) {
                dj1Var = (dj1) objG;
                if (dj1Var != null) {
                    while (r0.hasNext()) {
                    }
                    zzfzzVar.zza = null;
                    zzfzzVar.zzd = 3;
                    if (i(zzfzzVar) != coroutineSingletons) {
                    }
                }
                return eVar;
            }
            return coroutineSingletons;
        } finally {
            r42.g(null);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(String str, Continuation continuation) {
        zzfzt zzfztVar;
        String str2;
        kotlinx.coroutines.sync.a aVar;
        long j10;
        if (continuation instanceof zzfzt) {
            zzfztVar = (zzfzt) continuation;
            int i10 = zzfztVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfztVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfztVar = new zzfzt(this, continuation);
            }
        }
        Object obj = zzfztVar.zzc;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzfztVar.zze;
        if (i11 == 0) {
            kotlin.a.d(obj);
            long jCurrentTimeMillis = System.currentTimeMillis();
            zzfztVar.zzf = str;
            kotlinx.coroutines.sync.c cVar = this.f13732b;
            zzfztVar.zza = cVar;
            zzfztVar.zzb = jCurrentTimeMillis;
            zzfztVar.zze = 1;
            if (cVar.e(zzfztVar) == coroutineSingletons) {
                return coroutineSingletons;
            }
            str2 = str;
            aVar = cVar;
            j10 = jCurrentTimeMillis;
        } else {
            if (i11 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            j10 = zzfztVar.zzb;
            aVar = (kotlinx.coroutines.sync.a) zzfztVar.zza;
            str2 = zzfztVar.zzf;
            kotlin.a.d(obj);
        }
        try {
            boolean z10 = this.f13735e;
            kd.e eVar = kd.e.f29109a;
            if (z10) {
                return eVar;
            }
            this.f13735e = true;
            zi1 zi1Var = (zi1) aj1.S().s();
            this.f13736f = zi1Var;
            zi1Var.c();
            ((aj1) zi1Var.f8617b).T(str2);
            zi1Var.c();
            ((aj1) zi1Var.f8617b).Z(j10);
            return eVar;
        } finally {
            aVar.g(null);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x0085 A[Catch: all -> 0x00ac, TRY_LEAVE, TryCatch #1 {all -> 0x00ac, blocks: (B:30:0x0081, B:32:0x0085, B:39:0x00a6, B:40:0x00ab), top: B:50:0x0081 }] */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00a5 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00a6 A[Catch: all -> 0x00ac, TRY_ENTER, TryCatch #1 {all -> 0x00ac, blocks: (B:30:0x0081, B:32:0x0085, B:39:0x00a6, B:40:0x00ab), top: B:50:0x0081 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object c(Continuation continuation) {
        zzfzp zzfzpVar;
        kotlinx.coroutines.sync.a aVar;
        kotlinx.coroutines.sync.a aVar2;
        long j10;
        zi1 zi1Var;
        if (continuation instanceof zzfzp) {
            zzfzpVar = (zzfzp) continuation;
            int i10 = zzfzpVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzpVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfzpVar = new zzfzp(this, continuation);
            }
        }
        Object obj = zzfzpVar.zzc;
        Object obj2 = CoroutineSingletons.f29226a;
        int i11 = zzfzpVar.zze;
        kd.e eVar = kd.e.f29109a;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                aVar = this.f13733c;
                zzfzpVar.zza = aVar;
                zzfzpVar.zze = 1;
                if (aVar.e(zzfzpVar) != obj2) {
                }
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    if (i11 != 3) {
                        if (i11 == 4) {
                            kotlin.a.d(obj);
                        }
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    kotlin.a.d(obj);
                    zzfzpVar.zze = 4;
                    return k(zzfzpVar) != obj2 ? obj2 : eVar;
                }
                j10 = zzfzpVar.zzb;
                aVar2 = (kotlinx.coroutines.sync.a) zzfzpVar.zza;
                kotlin.a.d(obj);
                try {
                    zi1Var = this.f13736f;
                    if (zi1Var != null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    zi1Var.c();
                    ((aj1) zi1Var.f8617b).c0(j10);
                    aVar.g(null);
                    zzfzpVar.zza = null;
                    zzfzpVar.zze = 3;
                    if (j(j10, zzfzpVar) != obj2) {
                        zzfzpVar.zze = 4;
                        if (k(zzfzpVar) != obj2) {
                        }
                    }
                } finally {
                }
            }
            aVar = (kotlinx.coroutines.sync.a) zzfzpVar.zza;
            kotlin.a.d(obj);
            if (this.f13737g) {
                return eVar;
            }
            this.f13737g = true;
            aVar.g(null);
            long jCurrentTimeMillis = System.currentTimeMillis();
            aVar2 = this.f13732b;
            zzfzpVar.zza = aVar2;
            zzfzpVar.zzb = jCurrentTimeMillis;
            zzfzpVar.zze = 2;
            if (aVar2.e(zzfzpVar) != obj2) {
                j10 = jCurrentTimeMillis;
                zi1Var = this.f13736f;
                if (zi1Var != null) {
                }
            }
        } finally {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x007a A[Catch: all -> 0x00da, TRY_ENTER, TRY_LEAVE, TryCatch #1 {all -> 0x00da, blocks: (B:27:0x0074, B:30:0x007a, B:33:0x0086, B:35:0x008a, B:37:0x00ae, B:39:0x00be, B:41:0x00c2, B:42:0x00d6, B:43:0x00d9, B:46:0x00dd, B:47:0x00e0, B:48:0x00e1, B:49:0x00e4, B:50:0x00e5, B:52:0x00e9, B:54:0x00f3, B:56:0x00f7, B:58:0x011b, B:59:0x012f, B:60:0x0132, B:61:0x0133, B:62:0x0136, B:63:0x0137, B:65:0x013b, B:68:0x0149, B:69:0x014c, B:70:0x014d, B:71:0x0150, B:72:0x0151, B:73:0x0154), top: B:82:0x0074 }] */
    /* JADX WARN: Removed duplicated region for block: B:72:0x0151 A[Catch: all -> 0x00da, TryCatch #1 {all -> 0x00da, blocks: (B:27:0x0074, B:30:0x007a, B:33:0x0086, B:35:0x008a, B:37:0x00ae, B:39:0x00be, B:41:0x00c2, B:42:0x00d6, B:43:0x00d9, B:46:0x00dd, B:47:0x00e0, B:48:0x00e1, B:49:0x00e4, B:50:0x00e5, B:52:0x00e9, B:54:0x00f3, B:56:0x00f7, B:58:0x011b, B:59:0x012f, B:60:0x0132, B:61:0x0133, B:62:0x0136, B:63:0x0137, B:65:0x013b, B:68:0x0149, B:69:0x014c, B:70:0x014d, B:71:0x0150, B:72:0x0151, B:73:0x0154), top: B:82:0x0074 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object d(Continuation continuation) {
        zzgad zzgadVar;
        kotlinx.coroutines.sync.a aVar;
        kotlinx.coroutines.sync.a aVar2;
        long j10;
        zi1 zi1Var;
        if (continuation instanceof zzgad) {
            zzgadVar = (zzgad) continuation;
            int i10 = zzgadVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzgadVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzgadVar = new zzgad(this, continuation);
            }
        }
        Object obj = zzgadVar.zzc;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzgadVar.zze;
        kd.e eVar = kd.e.f29109a;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                aVar = this.f13733c;
                zzgadVar.zza = aVar;
                zzgadVar.zze = 1;
                if (aVar.e(zzgadVar) != coroutineSingletons) {
                }
                return coroutineSingletons;
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                j10 = zzgadVar.zzb;
                aVar2 = (kotlinx.coroutines.sync.a) zzgadVar.zza;
                kotlin.a.d(obj);
                try {
                    zi1Var = this.f13736f;
                    if (zi1Var != null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    if (((aj1) zi1Var.f8617b).R() > 0) {
                        zi1 zi1Var2 = this.f13736f;
                        if (zi1Var2 == null) {
                            nb.g.U("adQualityDataBuilder");
                            throw null;
                        }
                        List listUnmodifiableList = Collections.unmodifiableList(((aj1) zi1Var2.f8617b).Q());
                        nb.g.h(listUnmodifiableList, "getAdClickTimestampsMsList(...)");
                        Object objK1 = kotlin.collections.n.k1(listUnmodifiableList);
                        nb.g.h(objK1, "last(...)");
                        long jLongValue = j10 - ((Number) objK1).longValue();
                        zi1 zi1Var3 = this.f13736f;
                        if (zi1Var3 == null) {
                            nb.g.U("adQualityDataBuilder");
                            throw null;
                        }
                        zi1Var3.c();
                        ((aj1) zi1Var3.f8617b).D();
                        if (jLongValue < 5000) {
                            zi1 zi1Var4 = this.f13736f;
                            if (zi1Var4 == null) {
                                nb.g.U("adQualityDataBuilder");
                                throw null;
                            }
                            int iG = ((aj1) zi1Var4.f8617b).G() + 1;
                            zi1Var4.c();
                            ((aj1) zi1Var4.f8617b).V(iG);
                        }
                    }
                    zi1 zi1Var5 = this.f13736f;
                    if (zi1Var5 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    if (((aj1) zi1Var5.f8617b).O() > 0) {
                        zi1 zi1Var6 = this.f13736f;
                        if (zi1Var6 == null) {
                            nb.g.U("adQualityDataBuilder");
                            throw null;
                        }
                        List listUnmodifiableList2 = Collections.unmodifiableList(((aj1) zi1Var6.f8617b).N());
                        nb.g.h(listUnmodifiableList2, "getAppBackgroundTimestampsMsList(...)");
                        Object objK12 = kotlin.collections.n.k1(listUnmodifiableList2);
                        nb.g.h(objK12, "last(...)");
                        long jLongValue2 = j10 - ((Number) objK12).longValue();
                        zi1 zi1Var7 = this.f13736f;
                        if (zi1Var7 == null) {
                            nb.g.U("adQualityDataBuilder");
                            throw null;
                        }
                        long J = ((aj1) zi1Var7.f8617b).J() + jLongValue2;
                        zi1Var7.c();
                        ((aj1) zi1Var7.f8617b).Y(J);
                    }
                    zi1 zi1Var8 = this.f13736f;
                    if (zi1Var8 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    zi1Var8.c();
                    ((aj1) zi1Var8.f8617b).B(j10);
                    return eVar;
                } catch (Throwable th) {
                    throw th;
                }
            }
            aVar = (kotlinx.coroutines.sync.a) zzgadVar.zza;
            kotlin.a.d(obj);
            if (!this.f13737g) {
                return eVar;
            }
            this.f13737g = false;
            aVar.g(null);
            long jCurrentTimeMillis = System.currentTimeMillis();
            kotlinx.coroutines.sync.c cVar = this.f13732b;
            zzgadVar.zza = cVar;
            zzgadVar.zzb = jCurrentTimeMillis;
            zzgadVar.zze = 2;
            if (cVar.e(zzgadVar) != coroutineSingletons) {
                aVar2 = cVar;
                j10 = jCurrentTimeMillis;
                zi1Var = this.f13736f;
                if (zi1Var != null) {
                }
            }
            return coroutineSingletons;
        } finally {
            aVar.g(null);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x008d A[Catch: all -> 0x00f1, TRY_ENTER, TryCatch #0 {all -> 0x00f1, blocks: (B:32:0x0087, B:35:0x008d, B:37:0x009b, B:39:0x00b2, B:41:0x00c0, B:52:0x00f3, B:53:0x00f6, B:54:0x00f7, B:55:0x00fa, B:56:0x00fb, B:57:0x00fe, B:58:0x00ff, B:59:0x0102), top: B:66:0x0087 }] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x00dc  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00ff A[Catch: all -> 0x00f1, TryCatch #0 {all -> 0x00f1, blocks: (B:32:0x0087, B:35:0x008d, B:37:0x009b, B:39:0x00b2, B:41:0x00c0, B:52:0x00f3, B:53:0x00f6, B:54:0x00f7, B:55:0x00fa, B:56:0x00fb, B:57:0x00fe, B:58:0x00ff, B:59:0x0102), top: B:66:0x0087 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object e(Continuation continuation) {
        zzfzx zzfzxVar;
        kotlinx.coroutines.sync.a aVar;
        long j10;
        zi1 zi1Var;
        aj1 aj1Var;
        if (continuation instanceof zzfzx) {
            zzfzxVar = (zzfzx) continuation;
            int i10 = zzfzxVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzxVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfzxVar = new zzfzx(this, continuation);
            }
        }
        Object obj = zzfzxVar.zzc;
        Object obj2 = CoroutineSingletons.f29226a;
        int i11 = zzfzxVar.zze;
        kd.e eVar = kd.e.f29109a;
        kotlinx.coroutines.sync.a aVar2 = this.f13732b;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                zzfzxVar.zza = aVar2;
                zzfzxVar.zze = 1;
                if (aVar2.e(zzfzxVar) != obj2) {
                    aVar = aVar2;
                }
                return obj2;
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    if (i11 != 3) {
                        if (i11 != 4) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        kotlin.a.d(obj);
                        return eVar;
                    }
                    aj1Var = (aj1) zzfzxVar.zza;
                    kotlin.a.d(obj);
                    if (this.f13739i.a(aj1Var)) {
                        String strE = aj1Var.E();
                        nb.g.h(strE, "getGwsQueryId(...)");
                        zzfzxVar.zza = null;
                        zzfzxVar.zze = 4;
                        if (h(strE, zzfzxVar) == obj2) {
                            return obj2;
                        }
                    }
                    return eVar;
                }
                j10 = zzfzxVar.zzb;
                aVar2 = (kotlinx.coroutines.sync.a) zzfzxVar.zza;
                kotlin.a.d(obj);
                try {
                    zi1Var = this.f13736f;
                    if (zi1Var != null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    long jK = j10 - ((aj1) zi1Var.f8617b).K();
                    zi1 zi1Var2 = this.f13736f;
                    if (zi1Var2 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    long J = jK - ((aj1) zi1Var2.f8617b).J();
                    zi1Var.c();
                    ((aj1) zi1Var.f8617b).U(J);
                    zi1 zi1Var3 = this.f13736f;
                    if (zi1Var3 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    zi1Var3.c();
                    ((aj1) zi1Var3.f8617b).b0(j10);
                    zi1 zi1Var4 = this.f13736f;
                    if (zi1Var4 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    aj1Var = (aj1) zi1Var4.e();
                    aVar2.g(null);
                    zzfzxVar.zza = aj1Var;
                    zzfzxVar.zze = 3;
                    if (k(zzfzxVar) != obj2) {
                        if (this.f13739i.a(aj1Var)) {
                        }
                        return eVar;
                    }
                    return obj2;
                } finally {
                }
            }
            aVar = (kotlinx.coroutines.sync.a) zzfzxVar.zza;
            kotlin.a.d(obj);
            if (!this.f13735e) {
                return eVar;
            }
            this.f13735e = false;
            aVar2.g(null);
            long jCurrentTimeMillis = System.currentTimeMillis();
            zzfzxVar.zza = aVar2;
            zzfzxVar.zzb = jCurrentTimeMillis;
            zzfzxVar.zze = 2;
            if (aVar2.e(zzfzxVar) != obj2) {
                j10 = jCurrentTimeMillis;
                zi1Var = this.f13736f;
                if (zi1Var != null) {
                }
            }
            return obj2;
        } finally {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x008d A[Catch: all -> 0x00ff, TRY_ENTER, TryCatch #1 {all -> 0x00ff, blocks: (B:32:0x0087, B:35:0x008d, B:37:0x009b, B:39:0x00b2, B:41:0x00c0, B:43:0x00ce, B:54:0x0101, B:55:0x0104, B:56:0x0105, B:57:0x0108, B:58:0x0109, B:59:0x010c, B:60:0x010d, B:61:0x0110, B:62:0x0111, B:63:0x0114), top: B:72:0x0087 }] */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00ea  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x0111 A[Catch: all -> 0x00ff, TryCatch #1 {all -> 0x00ff, blocks: (B:32:0x0087, B:35:0x008d, B:37:0x009b, B:39:0x00b2, B:41:0x00c0, B:43:0x00ce, B:54:0x0101, B:55:0x0104, B:56:0x0105, B:57:0x0108, B:58:0x0109, B:59:0x010c, B:60:0x010d, B:61:0x0110, B:62:0x0111, B:63:0x0114), top: B:72:0x0087 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object f(Continuation continuation) {
        zzgab zzgabVar;
        kotlinx.coroutines.sync.a aVar;
        long j10;
        zi1 zi1Var;
        aj1 aj1Var;
        if (continuation instanceof zzgab) {
            zzgabVar = (zzgab) continuation;
            int i10 = zzgabVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzgabVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzgabVar = new zzgab(this, continuation);
            }
        }
        Object obj = zzgabVar.zzc;
        Object obj2 = CoroutineSingletons.f29226a;
        int i11 = zzgabVar.zze;
        kd.e eVar = kd.e.f29109a;
        kotlinx.coroutines.sync.a aVar2 = this.f13732b;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                zzgabVar.zza = aVar2;
                zzgabVar.zze = 1;
                if (aVar2.e(zzgabVar) != obj2) {
                    aVar = aVar2;
                }
                return obj2;
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    if (i11 != 3) {
                        if (i11 != 4) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        kotlin.a.d(obj);
                        return eVar;
                    }
                    aj1Var = (aj1) zzgabVar.zza;
                    kotlin.a.d(obj);
                    if (this.f13739i.a(aj1Var)) {
                        String strE = aj1Var.E();
                        nb.g.h(strE, "getGwsQueryId(...)");
                        zzgabVar.zza = null;
                        zzgabVar.zze = 4;
                        if (h(strE, zzgabVar) == obj2) {
                            return obj2;
                        }
                    }
                    return eVar;
                }
                j10 = zzgabVar.zzb;
                aVar2 = (kotlinx.coroutines.sync.a) zzgabVar.zza;
                kotlin.a.d(obj);
                try {
                    zi1Var = this.f13736f;
                    if (zi1Var != null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    long jK = j10 - ((aj1) zi1Var.f8617b).K();
                    zi1 zi1Var2 = this.f13736f;
                    if (zi1Var2 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    long J = jK - ((aj1) zi1Var2.f8617b).J();
                    zi1Var.c();
                    ((aj1) zi1Var.f8617b).U(J);
                    zi1 zi1Var3 = this.f13736f;
                    if (zi1Var3 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    zi1Var3.c();
                    ((aj1) zi1Var3.f8617b).a0(j10);
                    zi1 zi1Var4 = this.f13736f;
                    if (zi1Var4 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    zi1Var4.c();
                    ((aj1) zi1Var4.f8617b).W();
                    zi1 zi1Var5 = this.f13736f;
                    if (zi1Var5 == null) {
                        nb.g.U("adQualityDataBuilder");
                        throw null;
                    }
                    aj1Var = (aj1) zi1Var5.e();
                    aVar.g(null);
                    zzgabVar.zza = aj1Var;
                    zzgabVar.zze = 3;
                    if (k(zzgabVar) != obj2) {
                        if (this.f13739i.a(aj1Var)) {
                        }
                        return eVar;
                    }
                    return obj2;
                } finally {
                }
            }
            aVar = (kotlinx.coroutines.sync.a) zzgabVar.zza;
            kotlin.a.d(obj);
            if (!this.f13735e) {
                return eVar;
            }
            this.f13735e = false;
            aVar.g(null);
            long jCurrentTimeMillis = System.currentTimeMillis();
            zzgabVar.zza = aVar2;
            zzgabVar.zzb = jCurrentTimeMillis;
            zzgabVar.zze = 2;
            if (aVar2.e(zzgabVar) != obj2) {
                j10 = jCurrentTimeMillis;
                zi1Var = this.f13736f;
                if (zi1Var != null) {
                }
            }
            return obj2;
        } finally {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object g(Continuation continuation) {
        zzfzv zzfzvVar;
        kotlinx.coroutines.sync.a aVar;
        long j10;
        if (continuation instanceof zzfzv) {
            zzfzvVar = (zzfzv) continuation;
            int i10 = zzfzvVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzvVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfzvVar = new zzfzv(this, continuation);
            }
        }
        Object obj = zzfzvVar.zzc;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzfzvVar.zze;
        if (i11 == 0) {
            kotlin.a.d(obj);
            long jCurrentTimeMillis = System.currentTimeMillis();
            kotlinx.coroutines.sync.c cVar = this.f13732b;
            zzfzvVar.zzb = cVar;
            zzfzvVar.zza = jCurrentTimeMillis;
            zzfzvVar.zze = 1;
            if (cVar.e(zzfzvVar) == coroutineSingletons) {
                return coroutineSingletons;
            }
            aVar = cVar;
            j10 = jCurrentTimeMillis;
        } else {
            if (i11 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            j10 = zzfzvVar.zza;
            aVar = (kotlinx.coroutines.sync.a) zzfzvVar.zzb;
            kotlin.a.d(obj);
        }
        try {
            zi1 zi1Var = this.f13736f;
            if (zi1Var == null) {
                nb.g.U("adQualityDataBuilder");
                throw null;
            }
            zi1Var.c();
            ((aj1) zi1Var.f8617b).C(j10);
            aVar.g(null);
            return kd.e.f29109a;
        } catch (Throwable th) {
            aVar.g(null);
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object h(String str, Continuation continuation) throws Throwable {
        zzfzk zzfzkVar;
        kotlinx.coroutines.sync.a aVar;
        Throwable th;
        kotlinx.coroutines.sync.a aVar2;
        if (continuation instanceof zzfzk) {
            zzfzkVar = (zzfzk) continuation;
            int i10 = zzfzkVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzkVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfzkVar = new zzfzk(this, continuation);
            }
        }
        Object obj = zzfzkVar.zzc;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzfzkVar.zze;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                zzfzkVar.zza = str;
                aVar = this.f13734d;
                zzfzkVar.zzb = aVar;
                zzfzkVar.zze = 1;
                if (aVar.e(zzfzkVar) != coroutineSingletons) {
                }
                return coroutineSingletons;
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                aVar2 = (kotlinx.coroutines.sync.a) zzfzkVar.zza;
                try {
                    kotlin.a.d(obj);
                    aVar2.g(null);
                    return kd.e.f29109a;
                } catch (Throwable th2) {
                    th = th2;
                    aVar2.g(null);
                    throw th;
                }
            }
            kotlinx.coroutines.sync.a aVar3 = (kotlinx.coroutines.sync.a) zzfzkVar.zzb;
            String str2 = (String) zzfzkVar.zza;
            kotlin.a.d(obj);
            aVar = aVar3;
            str = str2;
            androidx.datastore.core.h hVar = this.f13738h;
            zzfzl zzfzlVar = new zzfzl(str, null);
            zzfzkVar.zza = aVar;
            zzfzkVar.zzb = null;
            zzfzkVar.zze = 2;
            Object objA = hVar.a(zzfzlVar, zzfzkVar);
            if (objA != coroutineSingletons) {
                kotlinx.coroutines.sync.a aVar4 = aVar;
                obj = objA;
                aVar2 = aVar4;
                aVar2.g(null);
                return kd.e.f29109a;
            }
            return coroutineSingletons;
        } catch (Throwable th3) {
            kotlinx.coroutines.sync.a aVar5 = aVar;
            th = th3;
            aVar2 = aVar5;
            aVar2.g(null);
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object i(Continuation continuation) throws Throwable {
        zzfzn zzfznVar;
        kotlinx.coroutines.sync.a aVar;
        kotlinx.coroutines.sync.a aVar2;
        Throwable th;
        if (continuation instanceof zzfzn) {
            zzfznVar = (zzfzn) continuation;
            int i10 = zzfznVar.zzd;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfznVar.zzd = i10 - Integer.MIN_VALUE;
            } else {
                zzfznVar = new zzfzn(this, continuation);
            }
        }
        Object obj = zzfznVar.zzb;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzfznVar.zzd;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                aVar = this.f13734d;
                zzfznVar.zza = aVar;
                zzfznVar.zzd = 1;
                if (aVar.e(zzfznVar) != coroutineSingletons) {
                }
                return coroutineSingletons;
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                aVar2 = (kotlinx.coroutines.sync.a) zzfznVar.zza;
                try {
                    kotlin.a.d(obj);
                    aVar2.g(null);
                    return kd.e.f29109a;
                } catch (Throwable th2) {
                    th = th2;
                    aVar2.g(null);
                    throw th;
                }
            }
            kotlinx.coroutines.sync.a aVar3 = (kotlinx.coroutines.sync.a) zzfznVar.zza;
            kotlin.a.d(obj);
            aVar = aVar3;
            androidx.datastore.core.h hVar = this.f13738h;
            zzfzo zzfzoVar = new zzfzo(2, null);
            zzfznVar.zza = aVar;
            zzfznVar.zzd = 2;
            Object objA = hVar.a(zzfzoVar, zzfznVar);
            if (objA != coroutineSingletons) {
                aVar2 = aVar;
                obj = objA;
                aVar2.g(null);
                return kd.e.f29109a;
            }
            return coroutineSingletons;
        } catch (Throwable th3) {
            aVar2 = aVar;
            th = th3;
            aVar2.g(null);
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object j(long j10, Continuation continuation) {
        zzfzm zzfzmVar;
        kotlinx.coroutines.sync.a aVar;
        if (continuation instanceof zzfzm) {
            zzfzmVar = (zzfzm) continuation;
            int i10 = zzfzmVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzmVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfzmVar = new zzfzm(this, continuation);
            }
        }
        Object obj = zzfzmVar.zzc;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzfzmVar.zze;
        if (i11 == 0) {
            kotlin.a.d(obj);
            kotlinx.coroutines.sync.c cVar = this.f13732b;
            zzfzmVar.zzb = cVar;
            zzfzmVar.zza = j10;
            zzfzmVar.zze = 1;
            if (cVar.e(zzfzmVar) == coroutineSingletons) {
                return coroutineSingletons;
            }
            aVar = cVar;
        } else {
            if (i11 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            j10 = zzfzmVar.zza;
            aVar = (kotlinx.coroutines.sync.a) zzfzmVar.zzb;
            kotlin.a.d(obj);
        }
        try {
            zi1 zi1Var = this.f13736f;
            if (zi1Var == null) {
                nb.g.U("adQualityDataBuilder");
                throw null;
            }
            long jK = j10 - ((aj1) zi1Var.f8617b).K();
            zi1 zi1Var2 = this.f13736f;
            if (zi1Var2 == null) {
                nb.g.U("adQualityDataBuilder");
                throw null;
            }
            long J = jK - ((aj1) zi1Var2.f8617b).J();
            zi1Var.c();
            ((aj1) zi1Var.f8617b).U(J);
            aVar.g(null);
            return kd.e.f29109a;
        } catch (Throwable th) {
            aVar.g(null);
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x008e  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object k(Continuation continuation) throws Throwable {
        zzfzr zzfzrVar;
        kotlinx.coroutines.sync.a aVar;
        kotlinx.coroutines.sync.a aVar2;
        aj1 aj1Var;
        kotlinx.coroutines.sync.a aVar3;
        if (continuation instanceof zzfzr) {
            zzfzrVar = (zzfzr) continuation;
            int i10 = zzfzrVar.zze;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                zzfzrVar.zze = i10 - Integer.MIN_VALUE;
            } else {
                zzfzrVar = new zzfzr(this, continuation);
            }
        }
        Object objA = zzfzrVar.zzc;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = zzfzrVar.zze;
        try {
            if (i11 == 0) {
                kotlin.a.d(objA);
                aVar = this.f13732b;
                zzfzrVar.zza = aVar;
                zzfzrVar.zze = 1;
                if (aVar.e(zzfzrVar) != coroutineSingletons) {
                }
                return coroutineSingletons;
            }
            if (i11 != 1) {
                if (i11 != 2) {
                    if (i11 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    aVar3 = (kotlinx.coroutines.sync.a) zzfzrVar.zza;
                    try {
                        kotlin.a.d(objA);
                        aVar3.g(null);
                        return kd.e.f29109a;
                    } catch (Throwable th) {
                        th = th;
                        throw th;
                    }
                }
                aVar2 = (kotlinx.coroutines.sync.a) zzfzrVar.zzb;
                aj1Var = (aj1) zzfzrVar.zza;
                kotlin.a.d(objA);
                try {
                    androidx.datastore.core.h hVar = this.f13738h;
                    zzfzs zzfzsVar = new zzfzs(aj1Var, null);
                    zzfzrVar.zza = aVar2;
                    zzfzrVar.zzb = null;
                    zzfzrVar.zze = 3;
                    objA = hVar.a(zzfzsVar, zzfzrVar);
                    if (objA != coroutineSingletons) {
                        aVar3 = aVar2;
                        aVar3.g(null);
                        return kd.e.f29109a;
                    }
                    return coroutineSingletons;
                } catch (Throwable th2) {
                    th = th2;
                    aVar3 = aVar2;
                    throw th;
                }
            }
            aVar = (kotlinx.coroutines.sync.a) zzfzrVar.zza;
            kotlin.a.d(objA);
            zi1 zi1Var = this.f13736f;
            if (zi1Var == null) {
                nb.g.U("adQualityDataBuilder");
                throw null;
            }
            aj1 aj1Var2 = (aj1) zi1Var.e();
            aVar.g(null);
            zzfzrVar.zza = aj1Var2;
            aVar2 = this.f13734d;
            zzfzrVar.zzb = aVar2;
            zzfzrVar.zze = 2;
            if (aVar2.e(zzfzrVar) != coroutineSingletons) {
                aj1Var = aj1Var2;
                androidx.datastore.core.h hVar2 = this.f13738h;
                zzfzs zzfzsVar2 = new zzfzs(aj1Var, null);
                zzfzrVar.zza = aVar2;
                zzfzrVar.zzb = null;
                zzfzrVar.zze = 3;
                objA = hVar2.a(zzfzsVar2, zzfzrVar);
                if (objA != coroutineSingletons) {
                }
            }
            return coroutineSingletons;
        } finally {
            aVar.g(null);
        }
    }
}
