// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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
movl $0x20, %esi
callq 0x433e5
testq %r14, %r14
jne 0x7d6ff
movl $0x454e4f, (%rsp)       # imm = 0x454E4F
leaq 0x52d16(%rip), %r14     # 0xd0415
movq 0x28(%rbx), %rax
movq 0x10(%rax), %rdi
leaq -0x25ef(%rip), %rsi     # 0x7b11f
leaq 0x4b6e0(%rip), %rcx     # 0xc8df5
movq %rbx, %rdx
xorl %eax, %eax
callq 0x867a1
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x7d7e0
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x2620(%rip), %rsi     # 0x7b11f
leaq 0x52cd2(%rip), %rcx     # 0xd0418
movq %rsp, %r9
movq %rbx, %rdx
movq %r14, %r8
xorl %eax, %eax
callq 0x867a1
cmpl $-0x1, %eax
je 0x7d7e0
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x2652(%rip), %rsi     # 0x7b11f
leaq 0x4a4ca(%rip), %rcx     # 0xc7c42
movq %rbx, %rdx
xorl %eax, %eax
callq 0x867a1
cmpl $-0x1, %eax
je 0x7d7e0
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x267a(%rip), %rsi     # 0x7b11f
leaq 0x52c86(%rip), %rcx     # 0xd0426
movq %rbx, %rdx
xorl %eax, %eax
callq 0x867a1
cmpl $-0x1, %eax
je 0x7d7e0
movq 0x28(%rbx), %rax
incl 0x8(%rax)
movq 0x10(%rax), %rdi
leaq -0x26a2(%rip), %rsi     # 0x7b11f
leaq 0x4fbc4(%rip), %rcx     # 0xcd38c
movq %rbx, %rdx
xorl %eax, %eax
callq 0x867a1
cmpl $-0x1, %eax
je 0x7d7e0
movq 0x28(%rbx), %rax
incl 0x8(%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq