// File: /workspace/github_c_makefile_star2_O3/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, %r14
movl %edx, %ecx
movq %rsi, %r12
movq %rdi, %rbx
movl 0x88(%rdi), %ebp
leaq 0x2052b(%rip), %rdx     # 0x40174
leaq 0x22(%rsp), %r13
movl $0x6, %esi
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), %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0x10670
testl %eax, %eax
je 0x1fcd5
leaq 0x30(%rsp), %rdx
movl $0xa, 0x4(%rdx)
leaq 0x22(%rsp), %rsi
leaq 0x18(%rsp), %rcx
movq %r12, %rdi
callq 0x10670
testl %eax, %eax
je 0x1fcd5
movl %eax, %edi
callq 0x10220
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0x1c97a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1fe70
movq %r14, 0x28(%rsp)
movl %ebp, 0xc(%rsp)
movq 0x18(%rsp), %r14
testq %r14, %r14
je 0x1fdee
leaq 0x30(%rsp), %r12
movl 0x4(%r14), %edi
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
callq 0x10740
cmpl $-0x1, %eax
je 0x1fde1
movl %eax, %r13d
movl %eax, 0x84(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20053
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x1fe66
testq %r15, %r15
je 0x1fd9f
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x10(%rsp), %rcx
callq 0x10670
testl %eax, %eax
jne 0x1fef4
movq %rbx, %rbp
movq %r15, %rbx
movq %r12, %r15
movq 0x10(%rsp), %r12
testq %r12, %r12
je 0x1ff2e
movq 0x18(%r12), %rsi
movl 0x10(%r12), %edx
movl %r13d, %edi
callq 0x10500
cmpl $-0x1, %eax
jne 0x1fd87
movq 0x28(%r12), %r12
testq %r12, %r12
jne 0x1fd61
jmp 0x1fe1d
movq 0x10(%rsp), %rdi
callq 0x10730
movq %r15, %r12
movq %rbx, %r15
movq %rbp, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movl %r13d, %edi
callq 0x10640
cmpl $-0x1, %eax
jne 0x1fea3
callq 0x100a0
movl (%rax), %eax
cmpl $0x71, %eax
jne 0x1fe84
movl 0x84(%rbx), %edi
testl %edi, %edi
js 0x1fde1
callq 0x102a0
movl $0xffffffff, 0x84(%rbx) # imm = 0xFFFFFFFF
movq 0x28(%r14), %r14
testq %r14, %r14
jne 0x1fcf1
callq 0x100a0
movl (%rax), %edi
callq 0x10690
leaq 0x275ca(%rip), %rdx     # 0x473cb
leaq 0x60(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x10200
movq %rbx, %rdi
jmp 0x1fe54
movq 0x10(%rsp), %rdi
callq 0x10730
callq 0x100a0
movl (%rax), %edi
callq 0x10690
leaq 0x2757b(%rip), %rdx     # 0x473b5
leaq 0x60(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x10200
movq %rbp, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0x1c97a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rdi
callq 0x10730
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl $0x73, %eax
movl 0xc(%rsp), %ecx
andl $0x1, %ecx
orl %eax, %ecx
je 0x1febb
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x200dc
testl %eax, %eax
jne 0x1fe66
testb $0x1, 0xc(%rsp)
je 0x1febb
movq %rbx, %rdi
movl $0x1, %esi
callq 0x20053
testl %eax, %eax
jne 0x1fe66
leaq 0x60(%rsp), %rcx
movl $0x1, (%rcx)
movl 0x84(%rbx), %edi
movl $0x6, %esi
movl $0x1, %edx
movl $0x4, %r8d
callq 0x10120
cmpl $-0x1, %eax
je 0x1ff35
orb $0x2, 0x88(%rbx)
xorl %ebp, %ebp
jmp 0x1fe66
movl %eax, %edi
callq 0x10220
leaq 0x274a0(%rip), %rdx     # 0x473a2
leaq 0x60(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x10200
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0x1c97a
jmp 0x1fe66
xorl %edi, %edi
jmp 0x1fe22
leaq 0x274a7(%rip), %rsi     # 0x473e3
movq %rbx, %rdi
callq 0x1fb0c
movl 0x84(%rbx), %edi
testl %edi, %edi
js 0x1fe66
callq 0x102a0
movl $0xffffffff, 0x84(%rbx) # imm = 0xFFFFFFFF
jmp 0x1fe66