// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
andl $0x1, %eax
movl %eax, -0x94(%rbp)
leaq -0x3e(%rbp), %rdi
movl -0x1c(%rbp), %ecx
movl $0x6, %esi
leaq 0x65840(%rip), %rdx     # 0x87174
movb $0x0, %al
callq 0x101e0
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x10250
movl $0x2, -0x6c(%rbp)
movl $0x1, -0x68(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x3e(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0x78(%rbp), %rcx
callq 0x10640
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
je 0x219cf
movl $0xa, -0x6c(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x3e(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0x78(%rbp), %rcx
callq 0x10640
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
je 0x219cd
movq -0x10(%rbp), %rax
movq %rax, -0x228(%rbp)
movl -0x38(%rbp), %edi
callq 0x10200
movq -0x228(%rbp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x1cad0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21cba
jmp 0x219cf
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x21c4a
movq -0x88(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x88(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x88(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x10710
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
jne 0x21a18
jmp 0x21c33
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x21eb0
cmpl $0x0, %eax
je 0x21a3a
jmp 0x21ca4
cmpq $0x0, -0x30(%rbp)
je 0x21b77
movl $0x0, -0x98(%rbp)
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0x10640
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
je 0x21ab9
leaq -0x120(%rbp), %rax
movq %rax, -0x230(%rbp)
movl -0x38(%rbp), %edi
callq 0x10200
movq -0x230(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x6c4cf(%rip), %rdx     # 0x8df67
movb $0x0, %al
callq 0x101e0
movq -0x10(%rbp), %rdi
leaq -0x120(%rbp), %rdx
movl $0x2, %esi
callq 0x1cad0
jmp 0x21ca4
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x21b12
movl -0x34(%rbp), %edi
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x90(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x104c0
cmpl $-0x1, %eax
je 0x21afc
movl $0x1, -0x98(%rbp)
jmp 0x21b12
jmp 0x21afe
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x21ac4
movq -0x80(%rbp), %rdi
callq 0x10700
cmpl $0x0, -0x98(%rbp)
jne 0x21b75
leaq -0x1a0(%rbp), %rax
movq %rax, -0x238(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x238(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x6c426(%rip), %rdx     # 0x8df7a
movb $0x0, %al
callq 0x101e0
movq -0x10(%rbp), %rdi
leaq -0x1a0(%rbp), %rdx
movl $0x2, %esi
callq 0x1cad0
jmp 0x21ca4
jmp 0x21b77
movl -0x34(%rbp), %edi
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x88(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x10610
cmpl $-0x1, %eax
jne 0x21be3
callq 0x10080
cmpl $0x71, (%rax)
jne 0x21bb1
movq -0x10(%rbp), %rdi
callq 0x22130
jmp 0x21c33
callq 0x10080
cmpl $0x73, (%rax)
jne 0x21bc6
cmpl $0x0, -0x94(%rbp)
jne 0x21bc6
jmp 0x21bdf
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x21f80
cmpl $0x0, %eax
je 0x21bdd
jmp 0x21ca4
jmp 0x21bdf
jmp 0x21be1
jmp 0x21be3
cmpl $0x0, -0x94(%rbp)
je 0x21c04
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x21eb0
cmpl $0x0, %eax
je 0x21c04
jmp 0x21ca4
movq -0x10(%rbp), %rdi
callq 0x22180
cmpl $0x0, %eax
je 0x21c17
jmp 0x21ca4
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x88(%rax)
movl $0x0, -0x38(%rbp)
jmp 0x21cab
movq -0x88(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0x219da
cmpq $0x0, -0x88(%rbp)
jne 0x21ca2
leaq -0x220(%rbp), %rax
movq %rax, -0x240(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x240(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x6c30c(%rip), %rdx     # 0x8df90
movb $0x0, %al
callq 0x101e0
movq -0x10(%rbp), %rdi
leaq -0x220(%rbp), %rdx
movl $0x2, %esi
callq 0x1cad0
jmp 0x21ca4
jmp 0x21ca4
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movq -0x78(%rbp), %rdi
callq 0x10700
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
nopw %cs:(%rax,%rax)