// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
movl $0x20, %esi
callq 0x477e0
cmpq $0x0, -0x18(%rbp)
jne 0x99000
leaq 0xae22e(%rip), %rax     # 0x147221
movq %rax, -0x18(%rbp)
movl 0xaaf5e(%rip), %eax     # 0x143f5b
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x3537(%rip), %rsi     # 0x95ae0
leaq 0xa721b(%rip), %rcx     # 0x140239
movb $0x0, %al
callq 0xa6e80
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x99039
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9917b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %r8
leaq -0x40(%rbp), %r9
leaq -0x3589(%rip), %rsi     # 0x95ae0
leaq 0xae1b4(%rip), %rcx     # 0x147224
movb $0x0, %al
callq 0xa6e80
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x9908b
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9917b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x35d3(%rip), %rsi     # 0x95ae0
leaq 0xa60a0(%rip), %rcx     # 0x13f15a
movb $0x0, %al
callq 0xa6e80
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x990d5
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9917b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x361d(%rip), %rsi     # 0x95ae0
leaq 0xae12e(%rip), %rcx     # 0x147232
movb $0x0, %al
callq 0xa6e80
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x9911c
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9917b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x3664(%rip), %rsi     # 0x95ae0
leaq 0xab1f9(%rip), %rcx     # 0x144344
movb $0x0, %al
callq 0xa6e80
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x99163
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9917b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)