package kotlinx.coroutines.channels;

import java.util.concurrent.atomic.AtomicReferenceArray;
import kotlinx.coroutines.internal.UndeliveredElementException;
import kotlinx.coroutines.internal.s;
import kotlinx.coroutines.v1;

/* JADX INFO: loaded from: classes.dex */
public final class i extends s {

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ AtomicReferenceArray f29340f;

    public i(long j10, i iVar, b bVar, int i10) {
        super(j10, iVar, i10);
        this.f29339e = bVar;
        this.f29340f = new AtomicReferenceArray(c.f29317b * 2);
    }

    @Override // kotlinx.coroutines.internal.s
    public final int f() {
        return c.f29317b;
    }

    /* JADX WARN: Code restructure failed: missing block: B:35:0x005b, code lost:
    
        m(r7, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x005e, code lost:
    
        if (r1 == false) goto L69;
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0060, code lost:
    
        nb.g.f(r5);
        r7 = r5.f29315b;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x0065, code lost:
    
        if (r7 == null) goto L70;
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x0067, code lost:
    
        r7 = kotlinx.coroutines.internal.a.b(r7, r0, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x006b, code lost:
    
        if (r7 == null) goto L71;
     */
    /* JADX WARN: Code restructure failed: missing block: B:41:0x006d, code lost:
    
        hb.a.g0(r8, r7);
     */
    /* JADX WARN: Code restructure failed: missing block: B:42:0x0070, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:69:?, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:70:?, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:71:?, code lost:
    
        return;
     */
    @Override // kotlinx.coroutines.internal.s
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void g(int i10, kotlin.coroutines.h hVar) {
        UndeliveredElementException undeliveredElementExceptionB;
        int i11 = c.f29317b;
        boolean z10 = i10 >= i11;
        if (z10) {
            i10 -= i11;
        }
        Object obj = this.f29340f.get(i10 * 2);
        while (true) {
            Object objK = k(i10);
            boolean z11 = objK instanceof v1;
            b bVar = this.f29339e;
            if (z11 || (objK instanceof o)) {
                if (j(i10, objK, z10 ? c.f29325j : c.f29326k)) {
                    m(i10, null);
                    l(i10, !z10);
                    if (z10) {
                        nb.g.f(bVar);
                        sd.l lVar = bVar.f29315b;
                        if (lVar == null || (undeliveredElementExceptionB = kotlinx.coroutines.internal.a.b(lVar, obj, null)) == null) {
                            return;
                        }
                        hb.a.g0(hVar, undeliveredElementExceptionB);
                        return;
                    }
                    return;
                }
            } else {
                if (objK == c.f29325j || objK == c.f29326k) {
                    break;
                }
                if (objK != c.f29322g && objK != c.f29321f) {
                    if (objK == c.f29324i || objK == c.f29319d || objK == c.f29327l) {
                        return;
                    }
                    throw new IllegalStateException(("unexpected state: " + objK).toString());
                }
            }
        }
    }

    public final boolean j(int i10, Object obj, Object obj2) {
        AtomicReferenceArray atomicReferenceArray = this.f29340f;
        int i11 = (i10 * 2) + 1;
        while (!atomicReferenceArray.compareAndSet(i11, obj, obj2)) {
            if (atomicReferenceArray.get(i11) != obj) {
                return false;
            }
        }
        return true;
    }

    public final Object k(int i10) {
        return this.f29340f.get((i10 * 2) + 1);
    }

    public final void l(int i10, boolean z10) {
        if (z10) {
            b bVar = this.f29339e;
            nb.g.f(bVar);
            bVar.G((this.f29487c * ((long) c.f29317b)) + ((long) i10));
        }
        h();
    }

    public final void m(int i10, Object obj) {
        this.f29340f.set(i10 * 2, obj);
    }

    public final void n(int i10, la.e eVar) {
        this.f29340f.set((i10 * 2) + 1, eVar);
    }
}
