// File: /workspace/github_c_makefile_star2_O1/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 0x37741(%rip), %rdx     # 0x9b471
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 0x63db8
leaq 0x10(%rsp), %rdx
movl $0xa, 0x4(%rdx)
leaq 0xa(%rsp), %rsi
movq %rsp, %rcx
movq %r15, %rdi
callq 0x1f2d0
testl %eax, %eax
je 0x63db8
movl %eax, %edi
callq 0x1fb00
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0x6525c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x63e73
movq (%rsp), %r12
testq %r12, %r12
je 0x63e2b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
callq 0x1f7a0
cmpl $-0x1, %eax
je 0x63e21
movl %eax, %r15d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x63f19
testl %eax, %eax
jne 0x63e6a
movq 0x18(%r12), %rsi
movl 0x10(%r12), %edx
movl %r15d, %edi
callq 0x1f720
cmpl $-0x1, %eax
jne 0x63ea6
callq 0x1f810
movl (%rax), %eax
cmpl $0x71, %eax
jne 0x63e87
movl %r15d, %edi
callq 0x1f170
movq 0x28(%r12), %r12
testq %r12, %r12
jne 0x63dc6
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x3c782(%rip), %rdx     # 0xa05c0
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 0x6525c
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 0x63ea6
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x63f93
testl %eax, %eax
jne 0x63e6a
testb $0x1, %r13b
je 0x63ec0
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x63f19
testl %eax, %eax
jne 0x63e6a
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 0x63efd
movl %r15d, 0x84(%rbx)
orb $0x2, 0x88(%rbx)
xorl %ebp, %ebp
jmp 0x63e6a
leaq 0x3c6ff(%rip), %rsi     # 0xa0603
movq %rbx, %rdi
callq 0x63c24
movl %r15d, %edi
callq 0x1f170
jmp 0x63e6a