// File: /workspace/github_c_makefile_star2_O0/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
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x2cca4
movq -0x10(%rbp), %rdi
callq 0x2c720
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2cf05
movq -0x10(%rbp), %rdi
callq 0x32520
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x8, %edx
callq 0x2d630
cmpl $0x0, %eax
je 0x2cd87
cmpl $0x2, -0x1c(%rbp)
jne 0x2ccdd
movl $0x0, -0x4(%rbp)
jmp 0x2cf05
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, -0x60(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x58(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x28(%rax), %rax
movl 0x48(%rax), %eax
movl %eax, -0x50(%rbp)
movl -0x1c(%rbp), %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x60(%rbp), %rsi
movl $0x18, %edx
callq 0x32320
movq -0x10(%rbp), %rdi
callq 0x2c720
cmpl $0x0, -0x44(%rbp)
je 0x2cd7b
movq -0x58(%rbp), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x7b610
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x39200
movl $0x0, -0x4(%rbp)
jmp 0x2cf05
jmp 0x2cd89
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x326b0
cmpl $0x0, %eax
je 0x2cdcf
jmp 0x2cd9f
movq 0x8324a(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x54264(%rip), %rsi     # 0x81014
movl $0x41b, %edx            # imm = 0x41B
leaq 0x5aabc(%rip), %rcx     # 0x87878
leaq 0x5af42(%rip), %r8      # 0x87d05
movb $0x0, %al
callq 0x125f0
callq 0x12100
jmp 0x2cdd1
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
leaq -0x38(%rbp), %rsi
movl $0x18, %edx
callq 0x2d630
cmpl $0x0, %eax
jne 0x2cef5
cmpl $0x0, -0x44(%rbp)
je 0x2ce83
movq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
leaq 0x9bd(%rip), %rsi       # 0x2d810
leaq -0x90(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x2d6d0
jmp 0x2cef3
cmpl $0x3, -0x24(%rbp)
jne 0x2ceb9
movq -0x30(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2cba0
movq -0xb8(%rbp), %rdi
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rsi
callq 0x2b160
jmp 0x2cef1
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
callq 0x7b610
movq -0xc0(%rbp), %rdi
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rsi
callq 0x2b160
jmp 0x2cef3
jmp 0x2cef5
movq -0x10(%rbp), %rdi
callq 0x2c720
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)