// File: /workspace/github_c_makefile_star2_O3/icysunlight[P]miniftpd/sysutil.c
// Function: connect_timeout
int connect_timeout(int fd, struct sockaddr_in *addr, unsigned int wait_seconds)
{
    int ret;
    socklen_t addrlen = sizeof(struct sockaddr_in);

    if (wait_seconds > 0)
        activate_nonblock(fd);

    ret = connect(fd, (struct sockaddr*)addr, addrlen);
    if (ret < 0 && errno == EINPROGRESS)
    {
        //printf("AAAAA\n");
        fd_set connect_fdset;
        struct timeval timeout;
        FD_ZERO(&connect_fdset);
        FD_SET(fd, &connect_fdset);
        timeout.tv_sec = wait_seconds;
        timeout.tv_usec = 0;
        do
        {
            /* ????????????? */
            ret = select(fd + 1, NULL, &connect_fdset, NULL, &timeout);
        } while (ret < 0 && errno == EINTR);
        if (ret == 0)
        {
            ret = -1;
            errno = ETIMEDOUT;
        }
        else if (ret < 0)
            return -1;
        else if (ret == 1)
        {
            //printf("BBBBB\n");
            /* ret???1??????????????????????????????*/
            /* ???????????errno???????????getsockopt???? */
            int err;
            socklen_t socklen = sizeof(err);
            int sockoptret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &socklen);
            if (sockoptret == -1)
            {
                return -1;
            }
            if (err == 0)
            {
                //printf("DDDDDDD\n");
                ret = 0;
            }
            else
            {
                //printf("CCCCCC\n");
                errno = err;
                ret = -1;
            }
        }
    }
    if (wait_seconds > 0)
    {
        deactivate_nonblock(fd);
    }
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebp
movq %rsi, %r14
movl %edi, %ebx
testl %edx, %edx
je 0x42ce
movl %ebx, %edi
callq 0x3fa5
movl %ebx, %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0x34f0
movl %eax, %r15d
testl %eax, %eax
jns 0x43e6
callq 0x3060
cmpl $0x73, (%rax)
jne 0x43e6
movq %rax, %r14
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x50(%r12)
leal 0x3f(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %ebx, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movaps %xmm0, 0x60(%r12)
movaps %xmm0, 0x70(%r12)
sarl $0x6, %eax
cltq
orq %rdx, 0x20(%rsp,%rax,8)
movl %ebp, 0x4(%rsp)
movl %ebp, %eax
leaq 0x10(%rsp), %r13
movq %rax, (%r13)
movq $0x0, 0x8(%r13)
leal 0x1(%rbx), %ebp
movl %ebp, %edi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0x3370
testl %eax, %eax
jns 0x4390
cmpl $0x4, (%r14)
je 0x436d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x43f1
movl %eax, %r15d
cmpl $0x1, %eax
je 0x43aa
testl %r15d, %r15d
movl 0x4(%rsp), %ebp
jne 0x43e6
movl $0x6e, (%r14)
jmp 0x43e0
leaq 0xc(%rsp), %r8
movl $0x4, (%r8)
leaq 0x8(%rsp), %rcx
movl %ebx, %edi
movl $0x1, %esi
movl $0x4, %edx
callq 0x32b0
cmpl $-0x1, %eax
movl 0x4(%rsp), %ebp
je 0x4388
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x4406
movl %eax, (%r14)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %ebp, %ebp
je 0x43f1
movl %ebx, %edi
callq 0x3fdf
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
jmp 0x43e6