// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
andl $0x1, %eax
movl %eax, -0x7c(%rbp)
leaq -0x36(%rbp), %rdi
movl -0x1c(%rbp), %ecx
movl $0x6, %esi
leaq 0x5dccc(%rip), %rdx     # 0xe5509
movb $0x0, %al
callq 0x1f120
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x1f110
movl $0x2, -0x64(%rbp)
movl $0x1, -0x60(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x36(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x1f2e0
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
je 0x878d8
movl $0xa, -0x64(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x36(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x1f2e0
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
je 0x878d6
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movl -0x30(%rbp), %edi
callq 0x1fb20
movq -0x108(%rbp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x89660
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x87a6d
jmp 0x878d8
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x87a00
movq -0x78(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x78(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x78(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x1f7b0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
jne 0x87912
jmp 0x879ef
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x87a80
cmpl $0x0, %eax
je 0x8792a
jmp 0x87a57
movl -0x2c(%rbp), %edi
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x78(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x1f710
cmpl $-0x1, %eax
jne 0x8798f
callq 0x1f820
cmpl $0x71, (%rax)
jne 0x8795d
movl -0x2c(%rbp), %edi
callq 0x1f170
jmp 0x879ef
callq 0x1f820
cmpl $0x73, (%rax)
jne 0x8796f
cmpl $0x0, -0x7c(%rbp)
jne 0x8796f
jmp 0x8798b
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x87b40
cmpl $0x0, %eax
je 0x87989
jmp 0x87a57
jmp 0x8798b
jmp 0x8798d
jmp 0x8798f
cmpl $0x0, -0x7c(%rbp)
je 0x879b0
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl $0x1, %edx
callq 0x87a80
cmpl $0x0, %eax
je 0x879b0
jmp 0x87a57
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x87cd0
cmpl $0x0, %eax
je 0x879c6
jmp 0x87a57
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x88(%rax)
movl $0x0, -0x30(%rbp)
jmp 0x87a5e
movq -0x78(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x878e0
cmpq $0x0, -0x78(%rbp)
jne 0x87a55
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
callq 0x1f820
movl (%rax), %edi
callq 0x1f630
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x62d1b(%rip), %rdx     # 0xea752
movb $0x0, %al
callq 0x1f120
movq -0x10(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movl $0x2, %esi
callq 0x89660
jmp 0x87a57
jmp 0x87a57
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movq -0x70(%rbp), %rdi
callq 0x1f4a0
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)