// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/replication.c
// Function: roleCommand
void roleCommand(client *c) {
    if (server.masterhost == NULL) {
        listIter li;
        listNode *ln;
        void *mbcount;
        int slaves = 0;

        addReplyMultiBulkLen(c,3);
        addReplyBulkCBuffer(c,"master",6);
        addReplyLongLong(c,server.master_repl_offset);
        mbcount = addDeferredMultiBulkLength(c);
        listRewind(server.slaves,&li);
        while((ln = listNext(&li))) {
            client *slave = ln->value;
            char ip[NET_IP_STR_LEN], *slaveip = slave->slave_ip;

            if (slaveip[0] == '\0') {
                if (anetPeerToString(slave->fd,ip,sizeof(ip),NULL) == -1)
                    continue;
                slaveip = ip;
            }
            if (slave->replstate != SLAVE_STATE_ONLINE) continue;
            addReplyMultiBulkLen(c,3);
            addReplyBulkCString(c,slaveip);
            addReplyBulkLongLong(c,slave->slave_listening_port);
            addReplyBulkLongLong(c,slave->repl_ack_off);
            slaves++;
        }
        setDeferredMultiBulkLength(c,mbcount,slaves);
    } else {
        char *slavestate = NULL;

        addReplyMultiBulkLen(c,5);
        addReplyBulkCBuffer(c,"slave",5);
        addReplyBulkCString(c,server.masterhost);
        addReplyLongLong(c,server.masterport);
        if (slaveIsInHandshakeState()) {
            slavestate = "handshake";
        } else {
            switch(server.repl_state) {
            case REPL_STATE_NONE: slavestate = "none"; break;
            case REPL_STATE_CONNECT: slavestate = "connect"; break;
            case REPL_STATE_CONNECTING: slavestate = "connecting"; break;
            case REPL_STATE_TRANSFER: slavestate = "sync"; break;
            case REPL_STATE_CONNECTED: slavestate = "connected"; break;
            default: slavestate = "unknown"; break;
            }
        }
        addReplyBulkCString(c,slavestate);
        addReplyLongLong(c,server.master ? server.master->reploff : -1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0xbc6a0(%rip), %r15     # 0x106858
cmpq $0x0, 0x818(%r15)
je 0x4a248
movl $0x5, %esi
movq %rbx, %rdi
callq 0x4063b
leaq 0x81a93(%rip), %rsi     # 0xcbc6d
movl $0x5, %edx
movq %rbx, %rdi
callq 0x4070f
movq 0x818(%r15), %rsi
movq %rbx, %rdi
callq 0x404b9
movslq 0x820(%r15), %rsi
movq %rbx, %rdi
callq 0x40606
movl 0x83c(%r15), %eax
leal -0xe(%rax), %ecx
cmpl $-0xc, %ecx
ja 0x4a365
cmpl $0x1, %eax
jle 0x4a3a6
cmpl $0x2, %eax
je 0x4a3b8
cmpl $0xe, %eax
je 0x4a3c1
cmpl $0xf, %eax
jne 0x4a3d3
leaq 0x81420(%rip), %rsi     # 0xcb663
jmp 0x4a36c
movl $0x3, %esi
movq %rbx, %rdi
callq 0x4063b
leaq 0x819bf(%rip), %rsi     # 0xcbc1b
movl $0x6, %edx
movq %rbx, %rdi
callq 0x4070f
movq 0x7b0(%r15), %rsi
movq %rbx, %rdi
callq 0x40606
movq %rbx, %rdi
callq 0x402b0
movq %rax, %r14
movq 0x1e0(%r15), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x2e582
movq %r15, %rdi
callq 0x2e59f
xorl %r15d, %r15d
testq %rax, %rax
je 0x4a348
movq %r14, 0x8(%rsp)
leaq 0x20(%rsp), %r12
leaq 0x10(%rsp), %r13
movq 0x10(%rax), %r14
cmpb $0x0, 0x118(%r14)
je 0x4a2d1
leaq 0x118(%r14), %rbp
jmp 0x4a2ec
movl 0x8(%r14), %edi
movl $0x2e, %edx
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x31360
movq %r12, %rbp
cmpl $-0x1, %eax
je 0x4a32f
cmpl $0x9, 0xa0(%r14)
jne 0x4a32f
movl $0x3, %esi
movq %rbx, %rdi
callq 0x4063b
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x404b9
movslq 0x114(%r14), %rsi
movq %rbx, %rdi
callq 0x407de
movq 0xd0(%r14), %rsi
movq %rbx, %rdi
callq 0x407de
incl %r15d
movq %r13, %rdi
callq 0x2e59f
testq %rax, %rax
jne 0x4a2ba
movslq %r15d, %r15
movq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x402ec
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7b119(%rip), %rsi     # 0xc5485
movq %rbx, %rdi
callq 0x404b9
movq 0x828(%r15), %rax
testq %rax, %rax
je 0x4a389
movq 0xc8(%rax), %rsi
jmp 0x4a390
movq $-0x1, %rsi
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40606
testl %eax, %eax
je 0x4a3ca
cmpl $0x1, %eax
jne 0x4a3d3
leaq 0x7b0d9(%rip), %rsi     # 0xc548f
jmp 0x4a36c
leaq 0x7b0d8(%rip), %rsi     # 0xc5497
jmp 0x4a36c
leaq 0x83a70(%rip), %rsi     # 0xcde38
jmp 0x4a36c
leaq 0x79c09(%rip), %rsi     # 0xc3fda
jmp 0x4a36c
leaq 0x799b9(%rip), %rsi     # 0xc3d93
jmp 0x4a36c