// File: /workspace/github_c_makefile_star2_O3/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 0xba9d2(%rip), %r15     # 0x1018a8
cmpq $0x0, 0x828(%r15)
je 0x46f66
movl $0x5, %esi
movq %rbx, %rdi
callq 0x3d274
leaq 0x81dfd(%rip), %rsi     # 0xc8cf5
movl $0x5, %edx
movq %rbx, %rdi
callq 0x3d346
movq 0x828(%r15), %rsi
movq %rbx, %rdi
callq 0x3d0f2
movslq 0x830(%r15), %rsi
movq %rbx, %rdi
callq 0x3d23f
movl 0x84c(%r15), %eax
leal -0xe(%rax), %ecx
cmpl $-0xc, %ecx
ja 0x47083
cmpl $0x1, %eax
jle 0x470c4
cmpl $0x2, %eax
je 0x470d6
cmpl $0xe, %eax
je 0x470df
cmpl $0xf, %eax
jne 0x470f1
leaq 0x8178a(%rip), %rsi     # 0xc86eb
jmp 0x4708a
movl $0x3, %esi
movq %rbx, %rdi
callq 0x3d274
leaq 0x81d29(%rip), %rsi     # 0xc8ca3
movl $0x6, %edx
movq %rbx, %rdi
callq 0x3d346
movq 0x7c0(%r15), %rsi
movq %rbx, %rdi
callq 0x3d23f
movq %rbx, %rdi
callq 0x3cee9
movq %rax, %r14
movq 0x1e0(%r15), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x2b3b7
movq %r15, %rdi
callq 0x2b3d4
xorl %r15d, %r15d
testq %rax, %rax
je 0x47066
movq %r14, 0x8(%rsp)
leaq 0x20(%rsp), %r12
leaq 0x10(%rsp), %r13
movq 0x10(%rax), %r14
cmpb $0x0, 0x118(%r14)
je 0x46fef
leaq 0x118(%r14), %rbp
jmp 0x4700a
movl 0x8(%r14), %edi
movl $0x2e, %edx
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x2e279
movq %r12, %rbp
cmpl $-0x1, %eax
je 0x4704d
cmpl $0x9, 0xa0(%r14)
jne 0x4704d
movl $0x3, %esi
movq %rbx, %rdi
callq 0x3d274
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3d0f2
movslq 0x114(%r14), %rsi
movq %rbx, %rdi
callq 0x3d415
movq 0xd0(%r14), %rsi
movq %rbx, %rdi
callq 0x3d415
incl %r15d
movq %r13, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x46fd8
movslq %r15d, %r15
movq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3cf25
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7b48f(%rip), %rsi     # 0xc2519
movq %rbx, %rdi
callq 0x3d0f2
movq 0x838(%r15), %rax
testq %rax, %rax
je 0x470a7
movq 0xc8(%rax), %rsi
jmp 0x470ae
movq $-0x1, %rsi
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3d23f
testl %eax, %eax
je 0x470e8
cmpl $0x1, %eax
jne 0x470f1
leaq 0x7b44f(%rip), %rsi     # 0xc2523
jmp 0x4708a
leaq 0x7b44e(%rip), %rsi     # 0xc252b
jmp 0x4708a
leaq 0x83dea(%rip), %rsi     # 0xcaed0
jmp 0x4708a
leaq 0x79f4f(%rip), %rsi     # 0xc103e
jmp 0x4708a
leaq 0x79ceb(%rip), %rsi     # 0xc0de3
jmp 0x4708a