// File: /workspace/github_c_makefile_star2_O3/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 0x33ed6
movq %rdi, %rbx
movq 0x60(%rdi), %r15
movl %esi, %eax
leaq 0x2d3b0(%rip), %rcx     # 0x61160
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 0x33ed6
movl %eax, %r14d
movl %eax, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x12910
orl $0x800, %eax            # imm = 0x800
movl %r14d, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x12910
leaq 0x4e87b(%rip), %rdx     # 0x82680
movl %r14d, %edi
movl $0x602, %esi            # imm = 0x602
callq 0x225ac
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
movq %rax, %rdi
callq 0x4ed7e
movq %rax, -0x20(%rbp)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x33ec3
leaq -0x20(%rbp), %rcx
movl $0x40, %esi
movl $0x1, %edx
callq 0x295e4
movq %rax, %r14
movq 0x68(%rbx), %rax
movq %rax, 0x68(%r14)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %r14, %rdi
movq %rax, %rsi
callq 0x2298f
jmp 0x33ed6
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2298f
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22350
movq (%r15), %rdi
testq %rdi, %rdi
je 0x33ed6
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
callq 0x4ed7e
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2aca7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2298f
movq %rbx, %rdi
callq 0x22350
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq