// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/net.c
// Function: net_callback_connect
void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
    JanetStream *stream = fiber->ev_stream;
    switch (event) {
        default:
            break;
#ifndef JANET_WINDOWS
        /* Wait until we have an actual event before checking.
         * Windows doesn't support async connect with this, just try immediately.*/
        case JANET_ASYNC_EVENT_INIT:
#endif
        case JANET_ASYNC_EVENT_DEINIT:
            return;
        case JANET_ASYNC_EVENT_CLOSE:
            janet_cancel(fiber, janet_cstringv("stream closed"));
            janet_async_end(fiber);
            return;
    }
#ifdef JANET_WINDOWS
    int res = 0;
    int size = sizeof(res);
    int r = getsockopt((SOCKET)stream->handle, SOL_SOCKET, SO_ERROR, (char *)&res, &size);
#else
    int res = 0;
    socklen_t size = sizeof res;
    int r = getsockopt(stream->handle, SOL_SOCKET, SO_ERROR, &res, &size);
#endif
    if (r == 0) {
        if (res == 0) {
            janet_schedule(fiber, janet_wrap_abstract(stream));
        } else {
            janet_cancel(fiber, janet_cstringv(janet_strerror(res)));
            stream->flags |= JANET_STREAM_TOCLOSE;
        }
    } else {
        janet_cancel(fiber, janet_ev_lasterr());
        stream->flags |= JANET_STREAM_TOCLOSE;
    }
    janet_async_end(fiber);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x47a5d
jmp 0x47a47
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x47a5d
jmp 0x47a51
movl -0x4c(%rbp), %eax
subl $0x3, %eax
je 0x47a62
jmp 0x47a5b
jmp 0x47aa7
jmp 0x47b97
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq 0x3ffa8(%rip), %rdi     # 0x87a19
callq 0x64a70
movq %rax, %rdi
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
callq 0x7b550
movq -0x58(%rbp), %rdi
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
callq 0x2b130
movq -0x8(%rbp), %rdi
callq 0x2a730
jmp 0x47b97
movl $0x0, -0x24(%rbp)
movl $0x4, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %edi
movl $0x1, %esi
movl $0x4, %edx
leaq -0x24(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0x12560
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x47b60
cmpl $0x0, -0x24(%rbp)
jne 0x47b13
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
callq 0x7b610
movq -0x60(%rbp), %rdi
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
callq 0x2b160
jmp 0x47b5e
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x24(%rbp), %edi
callq 0x6dd40
movq %rax, %rdi
callq 0x64a70
movq %rax, %rdi
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
callq 0x7b550
movq -0x68(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
callq 0x2b130
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x10000, %ecx          # imm = 0x10000
movl %ecx, 0x4(%rax)
jmp 0x47b8e
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x2f7c0
movq -0x70(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
callq 0x2b130
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x10000, %ecx          # imm = 0x10000
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
callq 0x2a730
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)