// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/sentinel.c
// Function: sentinelSendSlaveOf
int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) {
    char portstr[32];
    int retval;

    ll2string(portstr,sizeof(portstr),port);

    /* If host is NULL we send SLAVEOF NO ONE that will turn the instance
     * into a master. */
    if (host == NULL) {
        host = "NO";
        memcpy(portstr,"ONE",4);
    }

    /* In order to send SLAVEOF in a safe way, we send a transaction performing
     * the following tasks:
     * 1) Reconfigure the instance according to the specified host/port params.
     * 2) Rewrite the configuraiton.
     * 3) Disconnect all clients (but this one sending the commnad) in order
     *    to trigger the ask-master-on-reconnection protocol for connected
     *    clients.
     *
     * Note that we don't check the replies returned by commands, since we
     * will observe instead the effects in the next INFO output. */
    retval = redisAsyncCommand(ri->link->cc,
        sentinelDiscardReplyCallback, ri, "MULTI");
    if (retval == C_ERR) return retval;
    ri->link->pending_commands++;

    retval = redisAsyncCommand(ri->link->cc,
        sentinelDiscardReplyCallback, ri, "SLAVEOF %s %s", host, portstr);
    if (retval == C_ERR) return retval;
    ri->link->pending_commands++;

    retval = redisAsyncCommand(ri->link->cc,
        sentinelDiscardReplyCallback, ri, "CONFIG REWRITE");
    if (retval == C_ERR) return retval;
    ri->link->pending_commands++;

    /* CLIENT KILL TYPE <type> is only supported starting from Redis 2.8.12,
     * however sending it to an instance not understanding this command is not
     * an issue because CLIENT is variadic command, so Redis will not
     * recognized as a syntax error, and the transaction will not fail (but
     * only the unsupported command will fail). */
    retval = redisAsyncCommand(ri->link->cc,
        sentinelDiscardReplyCallback, ri, "CLIENT KILL TYPE normal");
    if (retval == C_ERR) return retval;
    ri->link->pending_commands++;

    retval = redisAsyncCommand(ri->link->cc,
        sentinelDiscardReplyCallback, ri, "EXEC");
    if (retval == C_ERR) return retval;
    ri->link->pending_commands++;

    return C_OK;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movslq %edx, %rdx
movq %rsp, %rdi
pushq $0x20
popq %rsi
callq 0x39796
testq %r14, %r14
jne 0x6d41c
movl $0x454e4f, (%rsp)       # imm = 0x454E4F
leaq 0x50d45(%rip), %r14     # 0xbe161
movq 0x28(%rbx), %rax
movq 0x10(%rax), %rdi
leaq -0x2180(%rip), %rsi     # 0x6b2ab
leaq 0x49cf7(%rip), %rcx     # 0xb7129
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7597e
pushq $-0x1
popq %rbp
cmpl $-0x1, %eax
je 0x6d4fb
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x21af(%rip), %rsi     # 0x6b2ab
leaq 0x50d03(%rip), %rcx     # 0xbe164
movq %rsp, %r9
movq %rbx, %rdx
movq %r14, %r8
xorl %eax, %eax
callq 0x7597e
cmpl $-0x1, %eax
je 0x6d4fb
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x21e1(%rip), %rsi     # 0x6b2ab
leaq 0x48bcf(%rip), %rcx     # 0xb6062
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7597e
cmpl $-0x1, %eax
je 0x6d4fb
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x2209(%rip), %rsi     # 0x6b2ab
leaq 0x50cb7(%rip), %rcx     # 0xbe172
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7597e
cmpl $-0x1, %eax
je 0x6d4fb
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x2231(%rip), %rsi     # 0x6b2ab
leaq 0x4dd71(%rip), %rcx     # 0xbb254
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7597e
cmpl $-0x1, %eax
je 0x6d4fb
movq 0x28(%rbx), %rax
incl 0x8(%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq