// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/net.c
// Function: net_callback_accept
void net_callback_accept(JanetFiber *fiber, JanetAsyncEvent event) {
    JanetStream *stream = fiber->ev_stream;
    NetStateAccept *state = (NetStateAccept *)fiber->ev_state;
    switch (event) {
        default:
            break;
        case JANET_ASYNC_EVENT_MARK: {
            if (state->function) janet_mark(janet_wrap_function(state->function));
            break;
        }
        case JANET_ASYNC_EVENT_CLOSE:
            janet_schedule(fiber, janet_wrap_nil());
            janet_async_end(fiber);
            return;
        case JANET_ASYNC_EVENT_INIT:
        case JANET_ASYNC_EVENT_READ: {
#if defined(JANET_LINUX)
            JSock connfd = accept4(stream->handle, NULL, NULL, SOCK_CLOEXEC);
#else
            /* On BSDs, CLOEXEC should be inherited from server socket */
            JSock connfd = accept(stream->handle, NULL, NULL);
#endif
            if (JSOCKVALID(connfd)) {
                janet_net_socknoblock(connfd);
                JanetStream *stream = make_stream(connfd, JANET_STREAM_READABLE | JANET_STREAM_WRITABLE);
                Janet streamv = janet_wrap_abstract(stream);
                if (state->function) {
                    JanetFiber *sub_fiber = janet_fiber(state->function, 64, 1, &streamv);
                    sub_fiber->supervisor_channel = fiber->supervisor_channel;
                    janet_schedule(sub_fiber, janet_wrap_nil());
                } else {
                    janet_schedule(fiber, streamv);
                    janet_async_end(fiber);
                    return;
                }
            }
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x6, %esi
ja 0x310e9
movq %rdi, %rbx
movq 0x60(%rdi), %r15
movl %esi, %eax
leaq 0x2c183(%rip), %rcx     # 0x5d170
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x58(%rbx), %rax
movl (%rax), %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0x80000, %ecx          # imm = 0x80000
callq 0x12330
testl %eax, %eax
js 0x310e9
movl %eax, %r14d
movl %eax, %edi
callq 0x310f4
movl %r14d, %edi
movl $0x600, %esi            # imm = 0x600
callq 0x31121
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
movq %rax, %rdi
callq 0x4b3ab
movq %rax, -0x20(%rbp)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x310d6
pushq $0x40
popq %rsi
pushq $0x1
popq %rdx
leaq -0x20(%rbp), %rcx
callq 0x271c9
movq %rax, %r14
movq 0x68(%rbx), %rax
movq %rax, 0x68(%r14)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
movq %r14, %rdi
movq %rax, %rsi
callq 0x209ca
jmp 0x310e9
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
movq %rbx, %rdi
movq %rax, %rsi
callq 0x209ca
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x203ec
movq (%r15), %rdi
testq %rdi, %rdi
je 0x310e9
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
callq 0x4b3ab
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x28843
movq %rbx, %rdi
movq %rax, %rsi
callq 0x209ca
movq %rbx, %rdi
callq 0x203ec
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq