package kotlinx.coroutines.channels; import java.util.concurrent.atomic.AtomicReferenceArray; import kotlin.jvm.internal.Intrinsics; import kotlinx.coroutines.internal.Segment; /* loaded from: classes5.dex */ public final class ChannelSegment extends Segment { public final BufferedChannel _channel; public final AtomicReferenceArray data; public ChannelSegment(long j, ChannelSegment channelSegment, BufferedChannel bufferedChannel, int i) { super(j, channelSegment, i); this._channel = bufferedChannel; this.data = new AtomicReferenceArray(BufferedChannelKt.SEGMENT_SIZE * 2); } public final BufferedChannel getChannel() { BufferedChannel bufferedChannel = this._channel; Intrinsics.checkNotNull(bufferedChannel); return bufferedChannel; } @Override // kotlinx.coroutines.internal.Segment public int getNumberOfSlots() { return BufferedChannelKt.SEGMENT_SIZE; } public final void storeElement$kotlinx_coroutines_core(int i, Object obj) { setElementLazy(i, obj); } public final Object getElement$kotlinx_coroutines_core(int i) { return this.data.get(i * 2); } public final Object retrieveElement$kotlinx_coroutines_core(int i) { Object element$kotlinx_coroutines_core = getElement$kotlinx_coroutines_core(i); cleanElement$kotlinx_coroutines_core(i); return element$kotlinx_coroutines_core; } public final void cleanElement$kotlinx_coroutines_core(int i) { setElementLazy(i, null); } public final void setElementLazy(int i, Object obj) { this.data.lazySet(i * 2, obj); } public final Object getState$kotlinx_coroutines_core(int i) { return this.data.get((i * 2) + 1); } public final void setState$kotlinx_coroutines_core(int i, Object obj) { this.data.set((i * 2) + 1, obj); } public final boolean casState$kotlinx_coroutines_core(int i, Object obj, Object obj2) { return ChannelSegment$$ExternalSyntheticBackportWithForwarding0.m(this.data, (i * 2) + 1, obj, obj2); } public final Object getAndSetState$kotlinx_coroutines_core(int i, Object obj) { return this.data.getAndSet((i * 2) + 1, obj); } /* JADX WARN: Code restructure failed: missing block: B:54:0x0063, code lost: cleanElement$kotlinx_coroutines_core(r4); */ /* JADX WARN: Code restructure failed: missing block: B:55:0x0066, code lost: if (r0 == false) goto L65; */ /* JADX WARN: Code restructure failed: missing block: B:56:0x0068, code lost: r4 = getChannel().onUndeliveredElement; */ /* JADX WARN: Code restructure failed: missing block: B:57:0x006e, code lost: if (r4 == null) goto L66; */ /* JADX WARN: Code restructure failed: missing block: B:58:0x0070, code lost: kotlinx.coroutines.internal.OnUndeliveredElementKt.callUndeliveredElement(r4, r5, r6); */ /* JADX WARN: Code restructure failed: missing block: B:59:0x0073, code lost: return; */ /* JADX WARN: Code restructure failed: missing block: B:60:?, code lost: return; */ /* JADX WARN: Code restructure failed: missing block: B:61:?, code lost: return; */ @Override // kotlinx.coroutines.internal.Segment /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public void onCancellation(int r4, java.lang.Throwable r5, kotlin.coroutines.CoroutineContext r6) { /* r3 = this; int r5 = kotlinx.coroutines.channels.BufferedChannelKt.SEGMENT_SIZE if (r4 < r5) goto L6 r0 = 1 goto L7 L6: r0 = 0 L7: if (r0 == 0) goto La int r4 = r4 - r5 La: java.lang.Object r5 = r3.getElement$kotlinx_coroutines_core(r4) Le: java.lang.Object r1 = r3.getState$kotlinx_coroutines_core(r4) boolean r2 = r1 instanceof kotlinx.coroutines.Waiter if (r2 != 0) goto L74 boolean r2 = r1 instanceof kotlinx.coroutines.channels.WaiterEB if (r2 == 0) goto L1b goto L74 L1b: kotlinx.coroutines.internal.Symbol r2 = kotlinx.coroutines.channels.BufferedChannelKt.access$getINTERRUPTED_SEND$p() if (r1 == r2) goto L63 kotlinx.coroutines.internal.Symbol r2 = kotlinx.coroutines.channels.BufferedChannelKt.access$getINTERRUPTED_RCV$p() if (r1 != r2) goto L28 goto L63 L28: kotlinx.coroutines.internal.Symbol r2 = kotlinx.coroutines.channels.BufferedChannelKt.access$getRESUMING_BY_EB$p() if (r1 == r2) goto Le kotlinx.coroutines.internal.Symbol r2 = kotlinx.coroutines.channels.BufferedChannelKt.access$getRESUMING_BY_RCV$p() if (r1 != r2) goto L35 goto Le L35: kotlinx.coroutines.internal.Symbol r4 = kotlinx.coroutines.channels.BufferedChannelKt.access$getDONE_RCV$p() if (r1 == r4) goto L62 kotlinx.coroutines.internal.Symbol r4 = kotlinx.coroutines.channels.BufferedChannelKt.BUFFERED if (r1 != r4) goto L40 goto L62 L40: kotlinx.coroutines.internal.Symbol r4 = kotlinx.coroutines.channels.BufferedChannelKt.getCHANNEL_CLOSED() if (r1 != r4) goto L47 return L47: java.lang.IllegalStateException r4 = new java.lang.IllegalStateException java.lang.StringBuilder r5 = new java.lang.StringBuilder r5.() java.lang.String r6 = "unexpected state: " r5.append(r6) r5.append(r1) java.lang.String r5 = r5.toString() java.lang.String r5 = r5.toString() r4.(r5) throw r4 L62: return L63: r3.cleanElement$kotlinx_coroutines_core(r4) if (r0 == 0) goto L73 kotlinx.coroutines.channels.BufferedChannel r4 = r3.getChannel() kotlin.jvm.functions.Function1 r4 = r4.onUndeliveredElement if (r4 == 0) goto L73 kotlinx.coroutines.internal.OnUndeliveredElementKt.callUndeliveredElement(r4, r5, r6) L73: return L74: if (r0 == 0) goto L7b kotlinx.coroutines.internal.Symbol r2 = kotlinx.coroutines.channels.BufferedChannelKt.access$getINTERRUPTED_SEND$p() goto L7f L7b: kotlinx.coroutines.internal.Symbol r2 = kotlinx.coroutines.channels.BufferedChannelKt.access$getINTERRUPTED_RCV$p() L7f: boolean r1 = r3.casState$kotlinx_coroutines_core(r4, r1, r2) if (r1 == 0) goto Le r3.cleanElement$kotlinx_coroutines_core(r4) r1 = r0 ^ 1 r3.onCancelledRequest(r4, r1) if (r0 == 0) goto L9a kotlinx.coroutines.channels.BufferedChannel r4 = r3.getChannel() kotlin.jvm.functions.Function1 r4 = r4.onUndeliveredElement if (r4 == 0) goto L9a kotlinx.coroutines.internal.OnUndeliveredElementKt.callUndeliveredElement(r4, r5, r6) L9a: return */ throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.channels.ChannelSegment.onCancellation(int, java.lang.Throwable, kotlin.coroutines.CoroutineContext):void"); } public final void onCancelledRequest(int i, boolean z) { if (z) { getChannel().waitExpandBufferCompletion$kotlinx_coroutines_core((this.id * BufferedChannelKt.SEGMENT_SIZE) + i); } onSlotCleaned(); } }