// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 0xb9f82(%rip), %r15     # 0xf98a8
cmpq $0x0, 0x828(%r15)
je 0x3f9be
pushq $0x5
popq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x370d9
leaq 0x7a393(%rip), %rsi     # 0xb9cdd
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3716c
movq 0x828(%r15), %rsi
movq %rbx, %rdi
callq 0x36f5d
movslq 0x830(%r15), %rsi
movq %rbx, %rdi
callq 0x370a6
movl 0x84c(%r15), %eax
leal -0xe(%rax), %ecx
cmpl $-0xc, %ecx
ja 0x3faaf
testl %eax, %eax
je 0x3fb10
cmpl $0xf, %eax
je 0x3faec
cmpl $0x2, %eax
je 0x3fafe
cmpl $0xe, %eax
je 0x3faf5
cmpl $0x1, %eax
jne 0x3fb07
leaq 0x742ba(%rip), %rsi     # 0xb3c73
jmp 0x3fab6
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x370d9
leaq 0x7a2bb(%rip), %rsi     # 0xb9c8b
pushq $0x6
popq %rdx
movq %rbx, %rdi
callq 0x3716c
movq 0x7c0(%r15), %rsi
movq %rbx, %rdi
callq 0x370a6
movq %rbx, %rdi
callq 0x36dad
movq %rax, 0x8(%rsp)
movq 0x1e0(%r15), %rdi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0x2702c
xorl %r14d, %r14d
leaq 0x20(%rsp), %r15
movq %r12, %rdi
callq 0x27046
testq %rax, %rax
je 0x3fa90
movq 0x10(%rax), %rbp
cmpb $0x0, 0x118(%rbp)
je 0x3fa36
leaq 0x118(%rbp), %r13
jmp 0x3fa4e
movl 0x8(%rbp), %edi
movq %r15, %rsi
pushq $0x2e
popq %rdx
xorl %ecx, %ecx
callq 0x29db9
movq %r15, %r13
cmpl $-0x1, %eax
je 0x3fa13
cmpl $0x9, 0xa0(%rbp)
jne 0x3fa13
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x370d9
movq %rbx, %rdi
movq %r13, %rsi
callq 0x36f5d
movslq 0x114(%rbp), %rsi
movq %rbx, %rdi
callq 0x37206
movq 0xd0(%rbp), %rsi
movq %rbx, %rdi
callq 0x37206
incl %r14d
jmp 0x3fa13
movslq %r14d, %rdx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x36de9
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x741b3(%rip), %rsi     # 0xb3c69
movq %rbx, %rdi
callq 0x36f5d
movq 0x838(%r15), %rax
testq %rax, %rax
je 0x3fad3
movq 0xc8(%rax), %rsi
jmp 0x3fad6
pushq $-0x1
popq %rsi
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x370a6
leaq 0x79be0(%rip), %rsi     # 0xb96d3
jmp 0x3fab6
leaq 0x7c204(%rip), %rsi     # 0xbbd00
jmp 0x3fab6
leaq 0x74176(%rip), %rsi     # 0xb3c7b
jmp 0x3fab6
leaq 0x72bad(%rip), %rsi     # 0xb26bb
jmp 0x3fab6
leaq 0x72d23(%rip), %rsi     # 0xb283a
jmp 0x3fab6