// File: /workspace/github_c_makefile_star2_O1/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 0x42b2
movl %ebx, %edi
callq 0x3f89
movl %ebx, %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0x34e0
movl %eax, %r15d
testl %eax, %eax
jns 0x43e5
callq 0x3060
cmpl $0x73, (%rax)
jne 0x43e5
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 0x3360
movl %eax, %r15d
testl %eax, %eax
jns 0x436f
cmpl $0x4, (%r14)
je 0x4351
testl %r15d, %r15d
je 0x43c5
movl 0x4(%rsp), %ebp
js 0x43da
movb $0x1, %cl
cmpl $0x1, %r15d
jne 0x43dc
leaq 0xc(%rsp), %r8
movl $0x4, (%r8)
movl $0x1, %r15d
leaq 0x8(%rsp), %rcx
movl %ebx, %edi
movl $0x1, %esi
movl $0x4, %edx
callq 0x32b0
cmpl $-0x1, %eax
setne %cl
je 0x43dc
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x4405
movl %eax, (%r14)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x43dc
movl $0x6e, (%r14)
movb $0x1, %cl
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl 0x4(%rsp), %ebp
jmp 0x43dc
xorl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
je 0x43f3
testl %ebp, %ebp
je 0x43f0
movl %ebx, %edi
callq 0x3fc3
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
jmp 0x43dc