// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/anet.c
// Function: anetTcpGenericConnect
static int anetTcpGenericConnect(char *err, char *addr, int port,
                                 char *source_addr, int flags)
{
    int s = ANET_ERR, rv;
    char portstr[6];  /* strlen("65535") + 1; */
    struct addrinfo hints, *servinfo, *bservinfo, *p, *b;

    snprintf(portstr,sizeof(portstr),"%d",port);
    memset(&hints,0,sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    if ((rv = getaddrinfo(addr,portstr,&hints,&servinfo)) != 0) {
        anetSetError(err, "%s", gai_strerror(rv));
        return ANET_ERR;
    }
    for (p = servinfo; p != NULL; p = p->ai_next) {
        /* Try to create the socket and to connect it.
         * If we fail in the socket() call, or on connect(), we retry with
         * the next entry in servinfo. */
        if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
            continue;
        if (anetSetReuseAddr(err,s) == ANET_ERR) goto error;
        if (flags & ANET_CONNECT_NONBLOCK && anetNonBlock(err,s) != ANET_OK)
            goto error;
        if (source_addr) {
            int bound = 0;
            /* Using getaddrinfo saves us from self-determining IPv4 vs IPv6 */
            if ((rv = getaddrinfo(source_addr, NULL, &hints, &bservinfo)) != 0)
            {
                anetSetError(err, "%s", gai_strerror(rv));
                goto error;
            }
            for (b = bservinfo; b != NULL; b = b->ai_next) {
                if (bind(s,b->ai_addr,b->ai_addrlen) != -1) {
                    bound = 1;
                    break;
                }
            }
            freeaddrinfo(bservinfo);
            if (!bound) {
                anetSetError(err, "bind: %s", strerror(errno));
                goto error;
            }
        }
        if (connect(s,p->ai_addr,p->ai_addrlen) == -1) {
            /* If the socket is non-blocking, it is ok for connect() to
             * return an EINPROGRESS error here. */
            if (errno == EINPROGRESS && flags & ANET_CONNECT_NONBLOCK)
                goto end;
            close(s);
            s = ANET_ERR;
            continue;
        }

        /* If we ended an iteration of the for loop without errors, we
         * have a connected socket. Let's return to the caller. */
        goto end;
    }
    if (p == NULL)
        anetSetError(err, "creating socket: %s", strerror(errno));

error:
    if (s != ANET_ERR) {
        close(s);
        s = ANET_ERR;
    }

end:
    freeaddrinfo(servinfo);

    /* Handle best effort binding: if a binding address was used, but it is
     * not possible to create a socket, try again without a binding address. */
    if (s == ANET_ERR && source_addr && (flags & ANET_CONNECT_BE_BINDING)) {
        return anetTcpGenericConnect(err,addr,port,NULL,flags);
    } else {
        return s;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
leaq -0x3a(%rbp), %rdi
movl -0x1c(%rbp), %ecx
movl $0x6, %esi
leaq 0x7612c(%rip), %rdx     # 0x87174
movb $0x0, %al
callq 0x101e0
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x10250
movl $0x0, -0x6c(%rbp)
movl $0x1, -0x68(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x3a(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0x78(%rbp), %rcx
callq 0x10640
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x110c1
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x34(%rbp), %edi
callq 0x10200
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0x75f84(%rip), %rsi     # 0x87032
movb $0x0, %al
callq 0x10900
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11359
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x112c3
movq -0x88(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x88(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x88(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x10710
movl %eax, -0x30(%rbp)
cmpl $-0x1, %eax
jne 0x1110a
jmp 0x112ac
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x12170
cmpl $-0x1, %eax
jne 0x11120
jmp 0x112fe
movl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x11141
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x109b0
cmpl $0x0, %eax
je 0x11141
jmp 0x112fe
cmpq $0x0, -0x28(%rbp)
je 0x11252
movl $0x0, -0x94(%rbp)
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0x10640
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x111a3
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x34(%rbp), %edi
callq 0x10200
movq -0xb8(%rbp), %rdi
movq %rax, %rdx
leaq 0x75e9b(%rip), %rsi     # 0x87032
movb $0x0, %al
callq 0x10900
jmp 0x112fe
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x1120a
movl -0x30(%rbp), %edi
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
movl 0x10(%rax), %edx
movq -0xa0(%rbp), %rsi
callq 0x104c0
cmpl $-0x1, %eax
je 0x111f4
movl $0x1, -0x94(%rbp)
jmp 0x1120a
jmp 0x111f6
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x111ae
movq -0x80(%rbp), %rdi
callq 0x10700
cmpl $0x0, -0x94(%rbp)
jne 0x11250
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
leaq 0x75ed9(%rip), %rsi     # 0x8711d
movb $0x0, %al
callq 0x10900
jmp 0x112fe
jmp 0x11252
movl -0x30(%rbp), %edi
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x88(%rbp), %rax
movl 0x10(%rax), %edx
movq -0xa8(%rbp), %rsi
callq 0x10610
cmpl $-0x1, %eax
jne 0x112aa
callq 0x10080
cmpl $0x73, (%rax)
jne 0x11299
movl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x11299
jmp 0x11315
movl -0x30(%rbp), %edi
callq 0x10280
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x112ac
jmp 0x11315
movq -0x88(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0x110cc
cmpq $0x0, -0x88(%rbp)
jne 0x112fc
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0xc8(%rbp), %rdi
movq %rax, %rdx
leaq 0x75e31(%rip), %rsi     # 0x87126
movb $0x0, %al
callq 0x10900
jmp 0x112fe
cmpl $-0x1, -0x30(%rbp)
je 0x11313
movl -0x30(%rbp), %edi
callq 0x10280
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x11315
movq -0x78(%rbp), %rdi
callq 0x10700
cmpl $-0x1, -0x30(%rbp)
jne 0x11353
cmpq $0x0, -0x28(%rbp)
je 0x11353
movl -0x2c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x11353
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x11010
movl %eax, -0x4(%rbp)
jmp 0x11359
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)