// File: /workspace/github_c_makefile_star2_O2/winton[P]redis_parse/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;

    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 0x495e(%rip), %rdx      # 0x7045
leaq 0xa(%rsp), %r13
pushq $0x6
popq %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2180
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 0x2410
testl %eax, %eax
je 0x274c
movl %eax, %edi
callq 0x2190
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x2280
pushq $-0x1
popq %rbp
jmp 0x2884
movq %rbp, %r13
pushq $-0x1
popq %rbp
movq (%r12), %r12
testq %r12, %r12
je 0x27bc
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
callq 0x2490
cmpl $-0x1, %eax
je 0x27b6
movl %eax, %r15d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x2898
testl %eax, %eax
jne 0x287b
movq 0x18(%r12), %rsi
movl 0x10(%r12), %edx
movl %r15d, %edi
callq 0x23f0
cmpl $-0x1, %eax
jne 0x2818
callq 0x2080
movl (%rax), %eax
cmpl $0x71, %eax
jne 0x27f9
movl %r15d, %edi
callq 0x21e0
addq $0x28, %r12
jmp 0x2752
callq 0x2080
movl (%rax), %edi
callq 0x2430
leaq 0x4879(%rip), %rdx      # 0x7048
leaq 0x40(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x2180
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2280
jmp 0x287b
xorl $0x73, %eax
movl %r14d, %ecx
andl $0x1, %ecx
orl %eax, %ecx
je 0x2830
movq %rbx, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x290c
testl %eax, %eax
jne 0x287b
testb $0x1, %r14b
je 0x2830
pushq $0x1
popq %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2898
testl %eax, %eax
jne 0x287b
leaq 0x40(%rsp), %rcx
movl $0x1, (%rcx)
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
pushq $0x4
popq %r8
movl %r15d, %edi
callq 0x20d0
cmpl $-0x1, %eax
je 0x2864
movl %r15d, 0x84(%rbx)
orb $0x2, 0x88(%rbx)
xorl %ebp, %ebp
jmp 0x287b
leaq 0x4822(%rip), %rsi      # 0x708d
movq %rbx, %rdi
callq 0x25eb
movl %r15d, %edi
callq 0x21e0
movq (%rsp), %rdi
callq 0x2480
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq