// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/ev.c
// Function: janet_channel_pop_with_lock
static int janet_channel_pop_with_lock(JanetChannel *channel, Janet *item, int is_choice) {
    JanetChannelPending writer;
    if (channel->closed) {
        janet_chan_unlock(channel);
        *item = janet_wrap_nil();
        return 1;
    }
    int is_threaded = janet_chan_is_threaded(channel);
    if (janet_q_pop(&channel->items, item, sizeof(Janet))) {
        /* Queue empty */
        if (is_choice == 2) return 0; // Skip pending read
        JanetChannelPending pending;
        pending.thread = &janet_vm;
        pending.fiber = janet_vm.root_fiber,
        pending.sched_id = janet_vm.root_fiber->sched_id;
        pending.mode = is_choice ? JANET_CP_MODE_CHOICE_READ : JANET_CP_MODE_READ;
        janet_q_push(&channel->read_pending, &pending, sizeof(pending));
        janet_chan_unlock(channel);
        if (is_threaded) {
            janet_gcroot(janet_wrap_fiber(pending.fiber));
        }
        return 0;
    }
    janet_assert(!janet_chan_unpack(channel, item, 0), "bad channel packing");
    if (!janet_q_pop(&channel->write_pending, &writer, sizeof(writer))) {
        /* Pending writer */
        if (is_threaded) {
            JanetVM *vm = writer.thread;
            JanetEVGenericMessage msg;
            msg.tag = writer.mode;
            msg.fiber = writer.fiber;
            msg.argi = (int32_t) writer.sched_id;
            msg.argp = channel;
            msg.argj = janet_wrap_nil();
            janet_ev_post_event(vm, janet_thread_chan_cb, msg);
        } else {
            if (writer.mode == JANET_CP_MODE_CHOICE_WRITE) {
                janet_schedule(writer.fiber, make_write_result(channel));
            } else {
                janet_schedule(writer.fiber, janet_wrap_abstract(channel));
            }
        }
    }
    janet_chan_unlock(channel);
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpl $0x0, 0x4c(%rdi)
je 0x219c2
movq %rbx, %rdi
callq 0x21593
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
movq %rax, (%r14)
pushq $0x1
popq %r14
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %r15d
movl 0x50(%rbx), %r13d
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21fc7
testl %eax, %eax
je 0x21a54
xorl %r14d, %r14d
cmpl $0x2, %r15d
je 0x219b0
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
leaq -0x60(%rbp), %rsi
movq %rax, (%rsi)
movq 0x28(%rax), %r12
movq %r12, 0x8(%rsi)
movl 0x48(%r12), %eax
movl %eax, 0x10(%rsi)
xorl %eax, %eax
testl %r15d, %r15d
setne %al
addl %eax, %eax
movl %eax, 0x14(%rsi)
leaq 0x18(%rbx), %rdi
pushq $0x18
popq %rdx
callq 0x24c37
movq %rbx, %rdi
callq 0x21593
testl %r13d, %r13d
je 0x219b0
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
movq %r12, %rdi
callq 0x4b3ab
movq %rax, %rdi
callq 0x28c2a
jmp 0x219b0
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x24d89
testl %eax, %eax
jne 0x21b15
leaq 0x30(%rbx), %rdi
leaq -0x40(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x21fc7
testl %eax, %eax
jne 0x21b08
testl %r13d, %r13d
je 0x21ad7
movq -0x40(%rbp), %r14
movq -0x30(%rbp), %rax
rolq $0x20, %rax
movq -0x38(%rbp), %rcx
movq %rax, -0x60(%rbp)
movq %rcx, -0x48(%rbp)
movq %rbx, -0x58(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
movq %rax, -0x50(%rbp)
movups -0x60(%rbp), %xmm0
movups -0x50(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x609(%rip), %rsi       # 0x220d6
movq %r14, %rdi
callq 0x22006
jmp 0x21b08
cmpl $0x3, -0x2c(%rbp)
movq -0x38(%rbp), %r14
jne 0x21aeb
movq %rbx, %rdi
callq 0x21915
jmp 0x21afd
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
movq %rbx, %rdi
callq 0x4b3ab
movq %r14, %rdi
movq %rax, %rsi
callq 0x209ca
movq %rbx, %rdi
callq 0x21593
jmp 0x219ac
movq 0x5e4d4(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x2e4ea(%rip), %rsi     # 0x50010
leaq 0x34d3b(%rip), %rcx     # 0x56868
leaq 0x3519c(%rip), %r8      # 0x56cd0
movl $0x41c, %edx            # imm = 0x41C
xorl %eax, %eax
callq 0x125e0
callq 0x12100