// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/cluster.c
// Function: migrateGetSocket
migrateCachedSocket* migrateGetSocket(client *c, robj *host, robj *port, long timeout) {
    int fd;
    sds name = sdsempty();
    migrateCachedSocket *cs;

    /* Check if we have an already cached socket for this ip:port pair. */
    name = sdscatlen(name,host->ptr,sdslen(host->ptr));
    name = sdscatlen(name,":",1);
    name = sdscatlen(name,port->ptr,sdslen(port->ptr));
    cs = dictFetchValue(server.migrate_cached_sockets,name);
    if (cs) {
        sdsfree(name);
        cs->last_use_time = server.unixtime;
        return cs;
    }

    /* No cached socket, create one. */
    if (dictSize(server.migrate_cached_sockets) == MIGRATE_SOCKET_CACHE_ITEMS) {
        /* Too many items, drop one at random. */
        dictEntry *de = dictGetRandomKey(server.migrate_cached_sockets);
        cs = dictGetVal(de);
        close(cs->fd);
        zfree(cs);
        dictDelete(server.migrate_cached_sockets,dictGetKey(de));
    }

    /* Create the socket */
    fd = anetTcpNonBlockConnect(server.neterr,c->argv[1]->ptr,
                                atoi(c->argv[2]->ptr));
    if (fd == -1) {
        sdsfree(name);
        addReplyErrorFormat(c,"Can't connect to target node: %s",
            server.neterr);
        return NULL;
    }
    anetEnableTcpNoDelay(server.neterr,fd);

    /* Check if it connects within the specified timeout. */
    if ((aeWait(fd,AE_WRITABLE,timeout) & AE_WRITABLE) == 0) {
        sdsfree(name);
        addReplySds(c,
            sdsnew("-IOERR error or timeout connecting to the client\r\n"));
        close(fd);
        return NULL;
    }

    /* Add to the cache and return it to the caller. */
    cs = zmalloc(sizeof(*cs));
    cs->fd = fd;
    cs->last_dbid = -1;
    cs->last_use_time = server.unixtime;
    dictAdd(server.migrate_cached_sockets,name,cs);
    return cs;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
callq 0x3114c
movq %rax, %r13
movq 0x8(%r12), %r12
movq %r12, %rdi
callq 0x5b5fd
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x31758
leaq 0x616f2(%rip), %rsi     # 0xc2438
pushq $0x1
popq %rdx
movq %rax, %rdi
callq 0x31758
movq %rax, %r12
movq 0x8(%r15), %r15
movq %r15, %rdi
callq 0x5b5fd
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x31758
movq %rax, %r15
leaq 0x98b30(%rip), %r14     # 0xf98a8
movq 0x308(%r14), %rdi
movq %rax, %rsi
callq 0x2a900
testq %rax, %rax
je 0x60db5
movq %rax, %r12
movq %r15, %rdi
callq 0x311c8
movq 0x978(%r14), %rax
movq %rax, 0x10(%r12)
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, (%rsp)
movq 0x308(%r14), %rdi
movq 0x48(%rdi), %rax
addq 0x28(%rdi), %rax
cmpq $0x40, %rax
jne 0x60dfb
callq 0x2aaf6
movq %rax, %r12
movq 0x8(%rax), %r13
movl (%r13), %edi
callq 0x26180
movq %r13, %rdi
callq 0x328f9
movq 0x308(%r14), %rdi
movq (%r12), %rsi
callq 0x2a6dc
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movq 0x8(%rcx), %r12
movq 0x8(%rax), %rdi
callq 0x26760
movl $0x208, %r13d           # imm = 0x208
addq 0x94197(%rip), %r13     # 0xf4fb8
movq %r13, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x29856
cmpl $-0x1, %eax
je 0x60e7f
movl %eax, %ebp
movq %r13, %rdi
movl %eax, %esi
callq 0x2939b
pushq $0x2
popq %rsi
movl %ebp, %edi
movq (%rsp), %rdx
callq 0x290e1
testb $0x2, %al
jne 0x60ea3
movq %r15, %rdi
callq 0x311c8
leaq 0x5917e(%rip), %rdi     # 0xb9fde
callq 0x3115a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x36a9d
movl %ebp, %edi
callq 0x26180
xorl %r12d, %r12d
jmp 0x60da3
movq %r15, %rdi
callq 0x311c8
leaq 0x5912f(%rip), %rsi     # 0xb9fbd
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x36b96
jmp 0x60da3
pushq $0x18
popq %rdi
callq 0x327b9
movq %rax, %r12
movl %ebp, (%rax)
orq $-0x1, 0x8(%rax)
movq 0x978(%r14), %rax
movq %rax, 0x10(%r12)
movq 0x308(%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2a3ed
jmp 0x60da3