// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/deps/hiredis/net.c
// Function: redisContextConnectTcp
static int _redisContextConnectTcp(redisContext *c, const char *addr, int port,
                                   const struct timeval *timeout,
                                   const char *source_addr) {
    int s, rv;
    char _port[6];  /* strlen("65535"); */
    struct addrinfo hints, *servinfo, *bservinfo, *p, *b;
    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;

        c->fd = s;
        if (redisSetBlocking(c,0) != REDIS_OK)
            goto error;
        if (source_addr) {
            int bound = 0;
            /* Using getaddrinfo saves us from self-determining IPv4 vs IPv6 */
            if ((rv = getaddrinfo(source_addr, NULL, &hints, &bservinfo)) != 0) {
                char buf[128];
                snprintf(buf,sizeof(buf),"Can't get addr: %s",gai_strerror(rv));
                __redisSetError(c,REDIS_ERR_OTHER,buf);
                goto error;
            }
            for (b = bservinfo; b != NULL; b = b->ai_next) {
                if (bind(s,b->ai_addr,b->ai_addrlen) != -1) {
                    bound = 1;
                    break;
                }
            }
            freeaddrinfo(bservinfo);
            if (!bound) {
                char buf[128];
                snprintf(buf,sizeof(buf),"Can't bind socket: %s",strerror(errno));
                __redisSetError(c,REDIS_ERR_OTHER,buf);
                goto error;
            }
        }
        if (connect(s,p->ai_addr,p->ai_addrlen) == -1) {
            if (errno == EHOSTUNREACH) {
                redisContextCloseFd(c);
                continue;
            } else if (errno == EINPROGRESS && !blocking) {
                /* This is ok. */
            } else {
                if (redisContextWaitReady(c,timeout) != REDIS_OK)
                    goto error;
            }
        }
        if (blocking && redisSetBlocking(c,1) != REDIS_OK)
            goto error;
        if (redisSetTcpNoDelay(c) != REDIS_OK)
            goto error;

        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 $0xe8, %rsp
movq %r8, %r15
movq %rcx, 0x28(%rsp)
movl %edx, %ecx
movq %rsi, %r14
movq %rdi, %rbx
movl 0x88(%rdi), %ebp
leaq 0x209e9(%rip), %rdx     # 0x3b174
leaq 0x22(%rsp), %r13
pushq $0x6
popq %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x10200
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x4(%rdx)
leaq 0x18(%rsp), %r12
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rcx
callq 0x10670
testl %eax, %eax
je 0x1a814
leaq 0x30(%rsp), %rdx
movl $0xa, 0x4(%rdx)
leaq 0x22(%rsp), %rsi
leaq 0x18(%rsp), %rcx
movq %r14, %rdi
callq 0x10670
testl %eax, %eax
je 0x1a814
movl %eax, %edi
callq 0x10220
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x18192
pushq $-0x1
popq %rbx
jmp 0x1a95e
movl %ebp, 0x4(%rsp)
leaq 0x30(%rsp), %r14
leaq 0x10(%rsp), %rbp
movq %rbx, 0x8(%rsp)
movq (%r12), %r12
testq %r12, %r12
je 0x1a972
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
callq 0x10740
cmpl $-0x1, %eax
je 0x1a904
movl %eax, %r13d
movl %eax, 0x84(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1ab19
testl %eax, %eax
jne 0x1a951
testq %r15, %r15
je 0x1a8d1
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x10670
testl %eax, %eax
jne 0x1a9ef
movq %r15, %rbx
movq %rbp, %rax
movq %r14, %rbp
movq %rax, %r15
movq %rax, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x1a90d
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movl %r13d, %edi
callq 0x10500
addq $0x28, %r14
cmpl $-0x1, %eax
je 0x1a898
movq 0x10(%rsp), %rdi
callq 0x10730
movq %rbp, %r14
movq %r15, %rbp
movq %rbx, %r15
movq 0x8(%rsp), %rbx
movq 0x18(%r12), %rsi
movl 0x10(%r12), %edx
movl %r13d, %edi
callq 0x10640
cmpl $-0x1, %eax
jne 0x1a9a6
callq 0x100a0
movl (%rax), %eax
cmpl $0x71, %eax
jne 0x1a987
movq %rbx, %rdi
callq 0x1ac64
addq $0x28, %r12
jmp 0x1a827
movq 0x10(%rsp), %rdi
callq 0x10730
callq 0x100a0
movl (%rax), %edi
callq 0x10690
leaq 0x275e4(%rip), %rdx     # 0x41f0e
leaq 0x60(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x10200
pushq $0x2
popq %rsi
movq 0x8(%rsp), %rdi
movq %r14, %rdx
callq 0x18192
pushq $-0x1
popq %rbx
movq 0x18(%rsp), %rdi
callq 0x10730
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x100a0
movl (%rax), %edi
callq 0x10690
leaq 0x2759f(%rip), %rdx     # 0x41f24
jmp 0x1a9fd
xorl $0x73, %eax
movl 0x4(%rsp), %ecx
andl $0x1, %ecx
orl %eax, %ecx
je 0x1a9bc
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x1ab8b
testl %eax, %eax
jne 0x1a951
testb $0x1, 0x4(%rsp)
je 0x1a9bc
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1ab19
testl %eax, %eax
jne 0x1a951
leaq 0x60(%rsp), %rcx
movl $0x1, (%rcx)
movl 0x84(%rbx), %edi
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
pushq $0x4
popq %r8
callq 0x10120
cmpl $-0x1, %eax
je 0x1aa1f
orb $0x2, 0x88(%rbx)
xorl %ebx, %ebx
jmp 0x1a954
movl %eax, %edi
callq 0x10220
leaq 0x274fe(%rip), %rdx     # 0x41efb
leaq 0x60(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x10200
pushq $0x2
popq %rsi
movq %rbx, %rdi
jmp 0x1a949
leaq 0x27516(%rip), %rsi     # 0x41f3c
movq %rbx, %rdi
callq 0x1a65c
movq %rbx, %rdi
callq 0x1ac64
jmp 0x1a951