// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/ev.c
// Function: janet_thread_chan_cb
static void janet_thread_chan_cb(JanetEVGenericMessage msg) {
    uint32_t sched_id = (uint32_t) msg.argi;
    JanetFiber *fiber = msg.fiber;
    int mode = msg.tag;
    JanetChannel *channel = (JanetChannel *) msg.argp;
    Janet x = msg.argj;
    janet_chan_lock(channel);
    if (fiber->sched_id == sched_id) {
        if (mode == JANET_CP_MODE_CHOICE_READ) {
            janet_assert(!janet_chan_unpack(channel, &x, 0), "packing error");
            janet_schedule(fiber, make_read_result(channel, x));
        } else if (mode == JANET_CP_MODE_CHOICE_WRITE) {
            janet_schedule(fiber, make_write_result(channel));
        } else if (mode == JANET_CP_MODE_READ) {
            janet_assert(!janet_chan_unpack(channel, &x, 0), "packing error");
            janet_schedule(fiber, x);
        } else if (mode == JANET_CP_MODE_WRITE) {
            janet_schedule(fiber, janet_wrap_channel(channel));
        } else { /* (mode == JANET_CP_MODE_CLOSE) */
            janet_schedule(fiber, janet_wrap_nil());
        }
    } else if (mode != JANET_CP_MODE_CLOSE) {
        /* Fiber has already been cancelled or resumed. */
        /* Resend event to another waiting thread, depending on mode */
        int is_read = (mode == JANET_CP_MODE_CHOICE_READ) || (mode == JANET_CP_MODE_READ);
        if (is_read) {
            JanetChannelPending reader;
            if (!janet_q_pop(&channel->read_pending, &reader, sizeof(reader))) {
                JanetVM *vm = reader.thread;
                JanetEVGenericMessage msg;
                msg.tag = reader.mode;
                msg.fiber = reader.fiber;
                msg.argi = (int32_t) reader.sched_id;
                msg.argp = channel;
                msg.argj = x;
                janet_ev_post_event(vm, janet_thread_chan_cb, msg);
            }
        } else {
            JanetChannelPending writer;
            if (!janet_q_pop(&channel->write_pending, &writer, sizeof(writer))) {
                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);
            }
        }
    }
    janet_chan_unlock(channel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
leaq 0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movl %ecx, -0x4(%rbp)
movq 0x18(%rax), %rcx
movq %rcx, -0x10(%rbp)
movl (%rax), %ecx
movl %ecx, -0x14(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2c6f0
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
cmpl -0x4(%rbp), %eax
jne 0x2d9d7
cmpl $0x2, -0x14(%rbp)
jne 0x2d8dc
jmp 0x2d863
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x326b0
cmpl $0x0, %eax
je 0x2d8a9
jmp 0x2d879
movq 0x82770(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x5378a(%rip), %rsi     # 0x81014
movl $0x389, %edx            # imm = 0x389
leaq 0x59fe2(%rip), %rcx     # 0x87878
leaq 0x5a47c(%rip), %r8      # 0x87d19
movb $0x0, %al
callq 0x125f0
callq 0x12100
jmp 0x2d8ab
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2cf20
movq -0xe0(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
callq 0x2b160
jmp 0x2d9d2
cmpl $0x3, -0x14(%rbp)
jne 0x2d90f
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2cba0
movq -0xe8(%rbp), %rdi
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
callq 0x2b160
jmp 0x2d9d0
cmpl $0x0, -0x14(%rbp)
jne 0x2d96e
jmp 0x2d917
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x326b0
cmpl $0x0, %eax
je 0x2d95d
jmp 0x2d92d
movq 0x826bc(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x536d6(%rip), %rsi     # 0x81014
movl $0x38e, %edx            # imm = 0x38E
leaq 0x59f2e(%rip), %rcx     # 0x87878
leaq 0x5a3c8(%rip), %r8      # 0x87d19
movb $0x0, %al
callq 0x125f0
callq 0x12100
jmp 0x2d95f
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2b160
jmp 0x2d9ce
cmpl $0x1, -0x14(%rbp)
jne 0x2d99e
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x32540
movq -0xf0(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
callq 0x2b160
jmp 0x2d9cc
movq -0x10(%rbp), %rax
movq %rax, -0xf8(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0xf8(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
callq 0x2b160
jmp 0x2d9ce
jmp 0x2d9d0
jmp 0x2d9d2
jmp 0x2db69
cmpl $0x4, -0x14(%rbp)
je 0x2db67
movb $0x1, %al
cmpl $0x2, -0x14(%rbp)
movb %al, -0xf9(%rbp)
je 0x2d9fc
cmpl $0x0, -0x14(%rbp)
sete %al
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x2daa2
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
leaq -0x68(%rbp), %rsi
movl $0x18, %edx
callq 0x2d630
cmpl $0x0, %eax
jne 0x2da9d
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
leaq -0x25f(%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 0x2db65
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
leaq -0xa8(%rbp), %rsi
movl $0x18, %edx
callq 0x2d630
cmpl $0x0, %eax
jne 0x2db63
movq -0xa8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0xd0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rdi
leaq -0x325(%rip), %rsi      # 0x2d810
leaq -0xd0(%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 0x2db65
jmp 0x2db67
jmp 0x2db69
movq -0x20(%rbp), %rdi
callq 0x2c720
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax,%rax)