// File: /workspace/github_c_makefile_star2_O1/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 0x34396
movq %rdi, %rbx
movq 0x60(%rdi), %r15
movl %esi, %eax
leaq 0x2df00(%rip), %rcx     # 0x62170
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 0x34396
movl %eax, %r14d
movl %eax, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x12920
orl $0x800, %eax            # imm = 0x800
movl %r14d, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x12920
leaq 0x4f3bb(%rip), %rdx     # 0x83680
movl %r14d, %edi
movl $0x602, %esi            # imm = 0x602
callq 0x22910
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
movq %rax, %rdi
callq 0x4f9f2
movq %rax, -0x20(%rbp)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x34383
leaq -0x20(%rbp), %rcx
movl $0x40, %esi
movl $0x1, %edx
callq 0x29abc
movq %rax, %r14
movq 0x68(%rbx), %rax
movq %rax, 0x68(%r14)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %r14, %rdi
movq %rax, %rsi
callq 0x22cf0
jmp 0x34396
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x22cf0
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x226b4
movq (%r15), %rdi
testq %rdi, %rdi
je 0x34396
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
callq 0x4f9f2
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2b15b
movq %rbx, %rdi
movq %rax, %rsi
callq 0x22cf0
movq %rbx, %rdi
callq 0x226b4
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq