// File: /workspace/github_c_makefile_star2_O3/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, %r14
movl %edx, %ecx
movq %rsi, %r15
movq %rdi, %rbx
movl 0x88(%rdi), %r13d
leaq 0x37c9d(%rip), %rdx     # 0x9b4b1
leaq 0xa(%rsp), %r12
movl $0x6, %esi
movq %r12, %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, %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x1f2d0
testl %eax, %eax
je 0x6389c
leaq 0x10(%rsp), %rdx
movl $0xa, 0x4(%rdx)
leaq 0xa(%rsp), %rsi
movq %rsp, %rcx
movq %r15, %rdi
callq 0x1f2d0
testl %eax, %eax
je 0x6389c
movl %eax, %edi
callq 0x1fb00
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0x64cc5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x63957
movq (%rsp), %r12
testq %r12, %r12
je 0x6390f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
callq 0x1f7a0
cmpl $-0x1, %eax
je 0x63905
movl %eax, %r15d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x639fd
testl %eax, %eax
jne 0x6394e
movq 0x18(%r12), %rsi
movl 0x10(%r12), %edx
movl %r15d, %edi
callq 0x1f720
cmpl $-0x1, %eax
jne 0x6398a
callq 0x1f810
movl (%rax), %eax
cmpl $0x71, %eax
jne 0x6396b
movl %r15d, %edi
callq 0x1f170
movq 0x28(%r12), %r12
testq %r12, %r12
jne 0x638aa
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x3cd1e(%rip), %rdx     # 0xa0640
leaq 0x40(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x1f120
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0x64cc5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%rsp), %rdi
callq 0x1f4c0
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl $0x73, %eax
movl %r13d, %ecx
andl $0x1, %ecx
orl %eax, %ecx
je 0x639a4
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x63a77
testl %eax, %eax
jne 0x6394e
testb $0x1, %r13b
je 0x639a4
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x639fd
testl %eax, %eax
jne 0x6394e
leaq 0x40(%rsp), %rcx
movl $0x1, (%rcx)
movl %r15d, %edi
movl $0x6, %esi
movl $0x1, %edx
movl $0x4, %r8d
callq 0x1f3f0
cmpl $-0x1, %eax
je 0x639e1
movl %r15d, 0x84(%rbx)
orb $0x2, 0x88(%rbx)
xorl %ebp, %ebp
jmp 0x6394e
leaq 0x3cc9b(%rip), %rsi     # 0xa0683
movq %rbx, %rdi
callq 0x63708
movl %r15d, %edi
callq 0x1f170
jmp 0x6394e