// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: slaveofCommand
void slaveofCommand(redisClient *c) {
    /* SLAVEOF is not allowed in cluster mode as replication is automatically
     * configured using the current address of the master node. */
    // 不允许在集群模式中使用
    if (server.cluster_enabled) {
        addReplyError(c,"SLAVEOF not allowed in cluster mode.");
        return;
    }

    /* The special host/port combination "NO" "ONE" turns the instance
     * into a master. Otherwise the new master address is set. */
    // SLAVEOF NO ONE 让从服务器转为主服务器
    if (!strcasecmp(c->argv[1]->ptr,"no") &&
        !strcasecmp(c->argv[2]->ptr,"one")) {
        if (server.masterhost) {
            // 让服务器取消复制，成为主服务器
            replicationUnsetMaster();
            redisLog(REDIS_NOTICE,"MASTER MODE enabled (user request)");
        }
    } else {
        long port;

        // 获取端口参数
        if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != REDIS_OK))
            return;

        /* Check if we are already attached to the specified slave */
        // 检查输入的 host 和 port 是否服务器目前的主服务器
        // 如果是的话，向客户端返回 +OK ，不做其他动作
        if (server.masterhost && !strcasecmp(server.masterhost,c->argv[1]->ptr)
            && server.masterport == port) {
            redisLog(REDIS_NOTICE,"SLAVE OF would result into synchronization with the master we are already connected with. No operation performed.");
            addReplySds(c,sdsnew("+OK Already connected to specified master\r\n"));
            return;
        }

        /* There was no previous master or the user specified a different one,
         * we can continue. */
        // 没有前任主服务器，或者客户端指定了新的主服务器
        // 开始执行复制操作
        replicationSetMaster(c->argv[1]->ptr, port);
        redisLog(REDIS_NOTICE,"SLAVE OF %s:%d enabled (user request)",
            server.masterhost, server.masterport);
    }
    addReply(c,shared.ok);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
leaq 0xd1765(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x7bc(%rax)
je 0x421b1
movq -0x8(%rbp), %rdi
leaq 0xa0542(%rip), %rsi     # 0xe26e9
callq 0x35d40
jmp 0x42327
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa0546(%rip), %rsi     # 0xe270e
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x42221
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa7461(%rip), %rsi     # 0xe964a
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x42221
leaq 0xd16fe(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x650(%rax)
je 0x4221c
callq 0x420c0
movl $0x2, %edi
leaq 0xa04fc(%rip), %rsi     # 0xe2711
movb $0x0, %al
callq 0x24fb0
jmp 0x42313
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x42248
jmp 0x42327
leaq 0xd16a9(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x650(%rax)
je 0x422ca
leaq 0xd1698(%rip), %rax     # 0x1138f8
movq 0x650(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x422ca
leaq 0xd1670(%rip), %rax     # 0x1138f8
movslq 0x658(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x422ca
movl $0x2, %edi
leaq 0xa0493(%rip), %rsi     # 0xe2734
movb $0x0, %al
callq 0x24fb0
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq 0xa04ef(%rip), %rdi     # 0xe27a6
callq 0x2c0e0
movq -0x18(%rbp), %rdi
movq %rax, %rsi
callq 0x35c00
jmp 0x42327
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movl %eax, %esi
callq 0x42000
leaq 0xd160c(%rip), %rax     # 0x1138f8
movq 0x650(%rax), %rdx
leaq 0xd15fe(%rip), %rax     # 0x1138f8
movl 0x658(%rax), %ecx
movl $0x2, %edi
leaq 0xa04c6(%rip), %rsi     # 0xe27d2
movb $0x0, %al
callq 0x24fb0
movq -0x8(%rbp), %rdi
leaq 0xd1e32(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)