// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/deps/hiredis/net.c
// Function: redisContextConnectTcp
int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout) {
    int s, rv;
    char _port[6];  /* strlen("65535"); */
    struct addrinfo hints, *servinfo, *p;
    int blocking = (c->flags & REDIS_BLOCK);

    snprintf(_port, 6, "%d", port);
    memset(&hints,0,sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;

    /* Try with IPv6 if no IPv4 address was found. We do it in this order since
     * in a Redis client you can't afford to test if you have IPv6 connectivity
     * as this would add latency to every connect. Otherwise a more sensible
     * route could be: Use IPv6 if both addresses are available and there is IPv6
     * connectivity. */
    if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
         hints.ai_family = AF_INET6;
         if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
            __redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv));
            return REDIS_ERR;
        }
    }
    for (p = servinfo; p != NULL; p = p->ai_next) {
        if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
            continue;

        if (redisSetBlocking(c,s,0) != REDIS_OK)
            goto error;
        if (connect(s,p->ai_addr,p->ai_addrlen) == -1) {
            if (errno == EHOSTUNREACH) {
                close(s);
                continue;
            } else if (errno == EINPROGRESS && !blocking) {
                /* This is ok. */
            } else {
                if (redisContextWaitReady(c,s,timeout) != REDIS_OK)
                    goto error;
            }
        }
        if (blocking && redisSetBlocking(c,s,1) != REDIS_OK)
            goto error;
        if (redisSetTcpNoDelay(c,s) != REDIS_OK)
            goto error;

        c->fd = s;
        c->flags |= REDIS_CONNECTED;
        rv = REDIS_OK;
        goto end;
    }
    if (p == NULL) {
        char buf[128];
        snprintf(buf,sizeof(buf),"Can't create socket: %s",strerror(errno));
        __redisSetError(c,REDIS_ERR_OTHER,buf);
        goto error;
    }

error:
    rv = REDIS_ERR;
end:
    freeaddrinfo(servinfo);
    return rv;  // Need to return REDIS_OK if alright
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, %rbp
movl %edx, %ecx
movq %rsi, %r15
movq %rdi, %rbx
movl 0x88(%rdi), %r14d
leaq 0x32d32(%rip), %rdx     # 0x91471
leaq 0xa(%rsp), %r13
pushq $0x6
popq %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x1f120
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x4(%rdx)
movq %rsp, %r12
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rcx
callq 0x1f2d0
testl %eax, %eax
je 0x5e7c4
leaq 0x10(%rsp), %rdx
movl $0xa, 0x4(%rdx)
leaq 0xa(%rsp), %rsi
movq %rsp, %rcx
movq %r15, %rdi
callq 0x1f2d0
testl %eax, %eax
je 0x5e7c4
movl %eax, %edi
callq 0x1fb00
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x5faf9
pushq $-0x1
popq %rbp
jmp 0x5e8fc
movq %rbp, %r13
pushq $-0x1
popq %rbp
movq (%r12), %r12
testq %r12, %r12
je 0x5e834
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
callq 0x1f7a0
cmpl $-0x1, %eax
je 0x5e82e
movl %eax, %r15d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x5e910
testl %eax, %eax
jne 0x5e8f3
movq 0x18(%r12), %rsi
movl 0x10(%r12), %edx
movl %r15d, %edi
callq 0x1f720
cmpl $-0x1, %eax
jne 0x5e890
callq 0x1f810
movl (%rax), %eax
cmpl $0x71, %eax
jne 0x5e871
movl %r15d, %edi
callq 0x1f170
addq $0x28, %r12
jmp 0x5e7ca
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x37d76(%rip), %rdx     # 0x965bd
leaq 0x40(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x1f120
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x5faf9
jmp 0x5e8f3
xorl $0x73, %eax
movl %r14d, %ecx
andl $0x1, %ecx
orl %eax, %ecx
je 0x5e8a8
movq %rbx, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x5e984
testl %eax, %eax
jne 0x5e8f3
testb $0x1, %r14b
je 0x5e8a8
pushq $0x1
popq %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5e910
testl %eax, %eax
jne 0x5e8f3
leaq 0x40(%rsp), %rcx
movl $0x1, (%rcx)
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
pushq $0x4
popq %r8
movl %r15d, %edi
callq 0x1f3f0
cmpl $-0x1, %eax
je 0x5e8dc
movl %r15d, 0x84(%rbx)
orb $0x2, 0x88(%rbx)
xorl %ebp, %ebp
jmp 0x5e8f3
leaq 0x37d1d(%rip), %rsi     # 0x96600
movq %rbx, %rdi
callq 0x5e643
movl %r15d, %edi
callq 0x1f170
movq (%rsp), %rdi
callq 0x1f4c0
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq