// File: /workspace/github_c_makefile_star2_O0/andyfighting[P]hiredis_timer_cmpt/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, n;
    char _port[6];  /* strlen("65535"); */
    struct addrinfo hints, *servinfo, *bservinfo, *p, *b;
    int blocking = (c->flags & REDIS_BLOCK);
    int reuseaddr = (c->flags & REDIS_REUSEADDR);
    int reuses = 0;

    c->connection_type = REDIS_CONN_TCP;
    c->tcp.port = port;

    /* We need to take possession of the passed parameters
     * to make them reusable for a reconnect.
     * We also carefully check we don't free data we already own,
     * as in the case of the reconnect method.
     *
     * This is a bit ugly, but atleast it works and doesn't leak memory.
     **/
    if (c->tcp.host != addr) {
        if (c->tcp.host)
            free(c->tcp.host);

        c->tcp.host = strdup(addr);
    }

    if (timeout) {
        if (c->timeout != timeout) {
            if (c->timeout == NULL)
                c->timeout = malloc(sizeof(struct timeval));

            memcpy(c->timeout, timeout, sizeof(struct timeval));
        }
    } else {
        if (c->timeout)
            free(c->timeout);
        c->timeout = NULL;
    }

    if (source_addr == NULL) {
        free(c->tcp.source_addr);
        c->tcp.source_addr = NULL;
    } else if (c->tcp.source_addr != source_addr) {
        free(c->tcp.source_addr);
        c->tcp.source_addr = strdup(source_addr);
    }

    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(c->tcp.host,_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) {
addrretry:
        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 (c->tcp.source_addr) {
            int bound = 0;
            /* Using getaddrinfo saves us from self-determining IPv4 vs IPv6 */
            if ((rv = getaddrinfo(c->tcp.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;
            }

            if (reuseaddr) {
                n = 1;
                if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*) &n,
                               sizeof(n)) < 0) {
                    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 (errno == EADDRNOTAVAIL && reuseaddr) {
                if (++reuses >= REDIS_CONNECT_RETRIES) {
                    goto error;
                } else {
                    goto addrretry;
                }
            } else {
                if (redisContextWaitReady(c,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 $0x250, %rsp            # imm = 0x250
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, -0x9c(%rbp)
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
andl $0x80, %eax
movl %eax, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0xa0(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc0(%rax)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x3b11
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
je 0x3afa
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rdi
callq 0x3040
movq -0x18(%rbp), %rdi
callq 0x34d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb0(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x3b6e
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
cmpq -0x28(%rbp), %rax
je 0x3b6c
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
jne 0x3b4f
movl $0x10, %edi
callq 0x3350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x3b9b
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
je 0x3b8c
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rdi
callq 0x3040
movq -0x10(%rbp), %rax
movq $0x0, 0xa8(%rax)
cmpq $0x0, -0x30(%rbp)
jne 0x3bc3
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x3040
movq -0x10(%rbp), %rax
movq $0x0, 0xb8(%rax)
jmp 0x3bfd
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
cmpq -0x30(%rbp), %rax
je 0x3bfb
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x3040
movq -0x30(%rbp), %rdi
callq 0x34d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb8(%rax)
jmp 0x3bfd
leaq -0x42(%rbp), %rdi
movl -0x1c(%rbp), %ecx
movl $0x6, %esi
leaq 0x943a(%rip), %rdx      # 0xd04a
movb $0x0, %al
callq 0x3190
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x3200
movl $0x2, -0x74(%rbp)
movl $0x1, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rdi
leaq -0x42(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0x34b0
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
je 0x3cb2
movl $0xa, -0x74(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x42(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0x34b0
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
je 0x3cb0
movq -0x10(%rbp), %rax
movq %rax, -0x238(%rbp)
movl -0x38(%rbp), %edi
callq 0x31a0
movq -0x238(%rbp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x32a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x402c
jmp 0x3cb2
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x3fbc
jmp 0x3ccd
movq -0x90(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x90(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x90(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x3550
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
jne 0x3cfd
jmp 0x3fa5
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x42f0
cmpl $0x0, %eax
je 0x3d1f
jmp 0x4016
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb8(%rax)
je 0x3eab
movl $0x0, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x78(%rbp), %rdx
leaq -0x88(%rbp), %rcx
callq 0x34b0
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
je 0x3daf
leaq -0x130(%rbp), %rax
movq %rax, -0x240(%rbp)
movl -0x38(%rbp), %edi
callq 0x31a0
movq -0x240(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x92bf(%rip), %rdx      # 0xd04d
movb $0x0, %al
callq 0x3190
movq -0x10(%rbp), %rdi
leaq -0x130(%rbp), %rdx
movl $0x2, %esi
callq 0x32a0
jmp 0x4016
cmpl $0x0, -0xa0(%rbp)
je 0x3de7
movl $0x1, -0x3c(%rbp)
movl -0x34(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x3c(%rbp), %rcx
movl $0x4, %r8d
callq 0x30e0
cmpl $0x0, %eax
jge 0x3de5
jmp 0x4016
jmp 0x3de7
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x3e43
movl -0x34(%rbp), %edi
movq -0x98(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x98(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x33e0
cmpl $-0x1, %eax
je 0x3e2d
movl $0x1, -0xa8(%rbp)
jmp 0x3e43
jmp 0x3e2f
movq -0x98(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0x3df5
movq -0x88(%rbp), %rdi
callq 0x3540
cmpl $0x0, -0xa8(%rbp)
jne 0x3ea9
leaq -0x1b0(%rbp), %rax
movq %rax, -0x248(%rbp)
callq 0x3070
movl (%rax), %edi
callq 0x34e0
movq -0x248(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x91d8(%rip), %rdx      # 0xd060
movb $0x0, %al
callq 0x3190
movq -0x10(%rbp), %rdi
leaq -0x1b0(%rbp), %rdx
movl $0x2, %esi
callq 0x32a0
jmp 0x4016
jmp 0x3eab
movl -0x34(%rbp), %edi
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x90(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x3480
cmpl $-0x1, %eax
jne 0x3f55
callq 0x3070
cmpl $0x71, (%rax)
jne 0x3ee9
movq -0x10(%rbp), %rdi
callq 0x4570
jmp 0x3fa5
callq 0x3070
cmpl $0x73, (%rax)
jne 0x3efe
cmpl $0x0, -0x9c(%rbp)
jne 0x3efe
jmp 0x3f51
callq 0x3070
cmpl $0x63, (%rax)
jne 0x3f2f
cmpl $0x0, -0xa0(%rbp)
je 0x3f2f
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
cmpl $0xa, %eax
jl 0x3f2a
jmp 0x4016
jmp 0x3ccd
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rsi
callq 0x43c0
cmpl $0x0, %eax
je 0x3f4d
jmp 0x4016
jmp 0x3f4f
jmp 0x3f51
jmp 0x3f53
jmp 0x3f55
cmpl $0x0, -0x9c(%rbp)
je 0x3f76
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x42f0
cmpl $0x0, %eax
je 0x3f76
jmp 0x4016
movq -0x10(%rbp), %rdi
callq 0x45c0
cmpl $0x0, %eax
je 0x3f89
jmp 0x4016
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x88(%rax)
movl $0x0, -0x38(%rbp)
jmp 0x401d
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x3cbd
cmpq $0x0, -0x90(%rbp)
jne 0x4014
leaq -0x230(%rbp), %rax
movq %rax, -0x250(%rbp)
callq 0x3070
movl (%rax), %edi
callq 0x34e0
movq -0x250(%rbp), %rdi
movq %rax, %rcx
movl $0x80, %esi
leaq 0x9080(%rip), %rdx      # 0xd076
movb $0x0, %al
callq 0x3190
movq -0x10(%rbp), %rdi
leaq -0x230(%rbp), %rdx
movl $0x2, %esi
callq 0x32a0
jmp 0x4016
jmp 0x4016
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movq -0x80(%rbp), %rdi
callq 0x3540
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopl (%rax,%rax)