// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x10, -0x1c(%rbp)
cmpl $0x0, -0x14(%rbp)
jbe 0x441a
movl -0x8(%rbp), %edi
callq 0x3ef0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x34f0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x45db
callq 0x3050
cmpl $0x73, (%rax)
jne 0x45db
jmp 0x4446
leaq -0xa0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpq $0x10, %rax
jae 0x4490
movq -0xc0(%rbp), %rax
movl -0xb4(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x445e
jmp 0x4492
movl -0x8(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x8(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xa0(%rbp,%rax,8), %rcx
movq %rcx, -0xa0(%rbp,%rax,8)
movl -0x14(%rbp), %eax
movq %rax, -0xb0(%rbp)
movq $0x0, -0xa8(%rbp)
movl -0x8(%rbp), %edi
addl $0x1, %edi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xa0(%rbp), %rdx
leaq -0xb0(%rbp), %r8
movq %rcx, %rsi
callq 0x3370
movl %eax, -0x18(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x18(%rbp)
movb %al, -0xcd(%rbp)
jge 0x4520
callq 0x3050
cmpl $0x4, (%rax)
sete %al
movb %al, -0xcd(%rbp)
movb -0xcd(%rbp), %al
testb $0x1, %al
jne 0x44de
cmpl $0x0, -0x18(%rbp)
jne 0x4547
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
callq 0x3050
movl $0x6e, (%rax)
jmp 0x45d9
cmpl $0x0, -0x18(%rbp)
jge 0x4559
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45ef
cmpl $0x1, -0x18(%rbp)
jne 0x45d5
movl $0x4, -0xc8(%rbp)
movl -0x8(%rbp), %edi
movl $0x1, %esi
movl $0x4, %edx
leaq -0xc4(%rbp), %rcx
leaq -0xc8(%rbp), %r8
callq 0x32c0
movl %eax, -0xcc(%rbp)
cmpl $-0x1, -0xcc(%rbp)
jne 0x45a1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45ef
cmpl $0x0, -0xc4(%rbp)
jne 0x45b3
movl $0x0, -0x18(%rbp)
jmp 0x45d3
movl -0xc4(%rbp), %eax
movl %eax, -0xd4(%rbp)
callq 0x3050
movl -0xd4(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
jmp 0x45d5
jmp 0x45d7
jmp 0x45d9
jmp 0x45db
cmpl $0x0, -0x14(%rbp)
jbe 0x45e9
movl -0x8(%rbp), %edi
callq 0x3f70
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)