// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x126652(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x828(%rax)
jne 0x51cd4
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x437f0
movq -0x8(%rbp), %rdi
leaq 0xf1170(%rip), %rsi     # 0x142d24
movl $0x6, %edx
callq 0x43920
movq -0x8(%rbp), %rdi
leaq 0x12660f(%rip), %rax    # 0x1781d8
movq 0x7c0(%rax), %rsi
callq 0x43780
movq -0x8(%rbp), %rdi
callq 0x432a0
movq %rax, -0x28(%rbp)
leaq 0x1265ef(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x27320
leaq -0x18(%rbp), %rdi
callq 0x27380
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x51cbe
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x118, %rax            # imm = 0x118
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x51c5e
movq -0x38(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x70(%rbp), %rsi
movl $0x2e, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2cbf0
cmpl $-0x1, %eax
jne 0x51c56
jmp 0x51bf9
leaq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x9, 0xa0(%rax)
je 0x51c6d
jmp 0x51bf9
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x437f0
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x43580
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movslq 0x114(%rax), %rsi
callq 0x439f0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0xd0(%rax), %rsi
callq 0x439f0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x51bf9
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
callq 0x43310
jmp 0x51e2d
movq $0x0, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movl $0x5, %esi
callq 0x437f0
movq -0x8(%rbp), %rdi
leaq 0xf1081(%rip), %rsi     # 0x142d76
movl $0x5, %edx
callq 0x43920
movq -0x8(%rbp), %rdi
leaq 0x1264ce(%rip), %rax    # 0x1781d8
movq 0x828(%rax), %rsi
callq 0x43580
movq -0x8(%rbp), %rdi
leaq 0x1264b7(%rip), %rax    # 0x1781d8
movslq 0x830(%rax), %rsi
callq 0x43780
callq 0x4f900
cmpl $0x0, %eax
je 0x51d44
leaq 0xeb0a7(%rip), %rax     # 0x13cde5
movq %rax, -0x80(%rbp)
jmp 0x51dc3
leaq 0x12648d(%rip), %rax    # 0x1781d8
movl 0x84c(%rax), %eax
movq %rax, -0x88(%rbp)
subq $0xf, %rax
ja 0x51db6
movq -0x88(%rbp), %rax
leaq 0xe9d0c(%rip), %rcx     # 0x13ba78
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xe9c1e(%rip), %rax     # 0x13b99a
movq %rax, -0x80(%rbp)
jmp 0x51dc1
leaq 0xeb066(%rip), %rax     # 0x13cdef
movq %rax, -0x80(%rbp)
jmp 0x51dc1
leaq 0xeb061(%rip), %rax     # 0x13cdf7
movq %rax, -0x80(%rbp)
jmp 0x51dc1
leaq 0xf304d(%rip), %rax     # 0x144df0
movq %rax, -0x80(%rbp)
jmp 0x51dc1
leaq 0xf09bc(%rip), %rax     # 0x14276c
movq %rax, -0x80(%rbp)
jmp 0x51dc1
leaq 0xe9a60(%rip), %rax     # 0x13b81d
movq %rax, -0x80(%rbp)
jmp 0x51dc3
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x43580
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq 0x1263f6(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x838(%rax)
je 0x51e0a
leaq 0x1263e5(%rip), %rax    # 0x1781d8
movq 0x838(%rax), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0x51e1a
movq $-0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x51e1a
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x43780
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)