// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %ebp
movq %rcx, %r12
movl %edx, %r15d
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x25ba5(%rip), %rdx     # 0x3917a
leaq 0x2a(%rsp), %r14
movl $0x6, %esi
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0xb1d0
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movl $0x1, 0x8(%rdx)
leaq 0x20(%rsp), %rcx
movq %r13, %rdi
movq %r14, %rsi
callq 0xb540
testl %eax, %eax
je 0x13640
movl %eax, %edi
callq 0xb1f0
leaq 0x25a10(%rip), %rsi     # 0x39038
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1315d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x13807
movq %r13, 0x10(%rsp)
movq 0x20(%rsp), %r14
testq %r14, %r14
je 0x13792
movl %r15d, 0xc(%rsp)
movl 0x4(%r14), %edi
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
callq 0xb600
cmpl $-0x1, %eax
je 0x13785
movl %eax, %r13d
movq %rbx, %rdi
movl %eax, %esi
callq 0x14099
cmpl $-0x1, %eax
je 0x137b8
testb $0x1, %bpl
je 0x136a6
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x130d4
testl %eax, %eax
jne 0x137b8
testq %r12, %r12
je 0x13758
movq %r12, %rdi
xorl %esi, %esi
leaq 0x30(%rsp), %rdx
leaq 0x18(%rsp), %rcx
callq 0xb540
testl %eax, %eax
je 0x136e9
movl %eax, %edi
callq 0xb1f0
movq %rbx, %rdi
leaq 0x25960(%rip), %rsi     # 0x39038
movq %rax, %rdx
xorl %eax, %eax
callq 0x1315d
movl $0x5, %eax
jmp 0x13750
movq 0x18(%rsp), %r15
testq %r15, %r15
je 0x1370e
movq 0x18(%r15), %rsi
movl 0x10(%r15), %edx
movl %r13d, %edi
callq 0xb420
cmpl $-0x1, %eax
jne 0x1373f
movq 0x28(%r15), %r15
jmp 0x136ee
movq 0x18(%rsp), %rdi
callq 0xb5f0
callq 0xb080
movl (%rax), %edi
callq 0xb560
movq %rbx, %rdi
leaq 0x259f5(%rip), %rsi     # 0x39123
movq %rax, %rdx
xorl %eax, %eax
callq 0x1315d
movl $0x5, %eax
jmp 0x1374b
movq 0x18(%rsp), %rdi
callq 0xb5f0
xorl %eax, %eax
movl 0xc(%rsp), %r15d
testl %eax, %eax
jne 0x13819
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movl %r13d, %edi
callq 0xb510
cmpl $-0x1, %eax
jne 0x137ce
callq 0xb080
testb $0x1, %bpl
je 0x1377d
cmpl $0x73, (%rax)
je 0x137ce
movl %r13d, %edi
callq 0xb240
movq 0x28(%r14), %r14
testq %r14, %r14
jne 0x13658
callq 0xb080
movl (%rax), %edi
callq 0xb560
leaq 0x25987(%rip), %rsi     # 0x3912c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1315d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r13d
je 0x137d1
movl %r13d, %edi
callq 0xb240
jmp 0x137d1
movl %r13d, %r14d
movq 0x10(%rsp), %r13
movq 0x20(%rsp), %rdi
callq 0xb5f0
testb $0x2, %bpl
je 0x13807
testq %r12, %r12
je 0x13807
cmpl $-0x1, %r14d
jne 0x13807
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x135b1
movl %eax, %r14d
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x5, %eax
je 0x137b8
jmp 0x13807