// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/cluster.c
// Function: clusterReplyMultiBulkSlots
void clusterReplyMultiBulkSlots(client *c) {
    /* Format: 1) 1) start slot
     *            2) end slot
     *            3) 1) master IP
     *               2) master port
     *               3) node ID
     *            4) 1) replica IP
     *               2) replica port
     *               3) node ID
     *           ... continued until done
     */

    int num_masters = 0;
    void *slot_replylen = addDeferredMultiBulkLength(c);

    dictEntry *de;
    dictIterator *di = dictGetSafeIterator(server.cluster->nodes);
    while((de = dictNext(di)) != NULL) {
        clusterNode *node = dictGetVal(de);
        int j = 0, start = -1;

        /* Skip slaves (that are iterated when producing the output of their
         * master) and  masters not serving any slot. */
        if (!nodeIsMaster(node) || node->numslots == 0) continue;

        for (j = 0; j < CLUSTER_SLOTS; j++) {
            int bit, i;

            if ((bit = clusterNodeGetSlotBit(node,j)) != 0) {
                if (start == -1) start = j;
            }
            if (start != -1 && (!bit || j == CLUSTER_SLOTS-1)) {
                int nested_elements = 3; /* slots (2) + master addr (1). */
                void *nested_replylen = addDeferredMultiBulkLength(c);

                if (bit && j == CLUSTER_SLOTS-1) j++;

                /* If slot exists in output map, add to it's list.
                 * else, create a new output map for this slot */
                if (start == j-1) {
                    addReplyLongLong(c, start); /* only one slot; low==high */
                    addReplyLongLong(c, start);
                } else {
                    addReplyLongLong(c, start); /* low */
                    addReplyLongLong(c, j-1);   /* high */
                }
                start = -1;

                /* First node reply position is always the master */
                addReplyMultiBulkLen(c, 3);
                addReplyBulkCString(c, node->ip);
                addReplyLongLong(c, node->port);
                addReplyBulkCBuffer(c, node->name, CLUSTER_NAMELEN);

                /* Remaining nodes in reply are replicas for slot range */
                for (i = 0; i < node->numslaves; i++) {
                    /* This loop is copy/pasted from clusterGenNodeDescription()
                     * with modifications for per-slot node aggregation */
                    if (nodeFailed(node->slaves[i])) continue;
                    addReplyMultiBulkLen(c, 3);
                    addReplyBulkCString(c, node->slaves[i]->ip);
                    addReplyLongLong(c, node->slaves[i]->port);
                    addReplyBulkCBuffer(c, node->slaves[i]->name, CLUSTER_NAMELEN);
                    nested_elements++;
                }
                setDeferredMultiBulkLength(c, nested_replylen, nested_elements);
                num_masters++;
            }
        }
    }
    dictReleaseIterator(di);
    setDeferredMultiBulkLength(c, slot_replylen, num_masters);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
callq 0x36dad
movq %rax, %r14
leaq 0x9a079(%rip), %rax     # 0xf98a8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x2a9c4
movq %rax, %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x5fa44
movq 0x8(%rax), %r15
testb $0x1, 0x30(%r15)
je 0x5f845
cmpl $0x0, 0x840(%r15)
je 0x5f845
movq %r14, 0x8(%rsp)
leaq 0x890(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x8(%r15), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
pushq $-0x1
popq %rdi
movl %edi, %esi
pushq $0x8
popq %r8
movq %r12, 0x30(%rsp)
cmpl $0x3fff, %r14d          # imm = 0x3FFF
jg 0x5fa3a
movl %r14d, %eax
cltd
idivl %r8d
cltq
movzbl 0x40(%r15,%rax), %eax
movl %r14d, %ecx
andb $0x7, %cl
movl %eax, %ebp
shrl %cl, %ebp
movl %r14d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
movl %esi, %r12d
cmovbl %r14d, %r12d
cmpl $-0x1, %esi
cmovnel %esi, %r12d
cmpl $-0x1, %r12d
je 0x5fa03
cmpl $0x3fff, %r14d          # imm = 0x3FFF
je 0x5f8f1
movl %ebp, %eax
andl $0x1, %eax
jne 0x5fa06
movq %rbx, %rdi
callq 0x36dad
movq %rax, 0x20(%rsp)
testb $0x1, %bpl
movl %r14d, %ebp
movl $0x4000, %eax           # imm = 0x4000
cmovnel %eax, %ebp
cmpl $0x3fff, %r14d          # imm = 0x3FFF
cmovnel %r14d, %ebp
movq %r13, 0x28(%rsp)
leal -0x1(%rbp), %r13d
movslq %r12d, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x370a6
cmpl %r13d, %r12d
movslq %r13d, %rsi
movq 0x28(%rsp), %r13
cmoveq %r14, %rsi
movq %rbx, %rdi
callq 0x370a6
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x370d9
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x36f5d
movslq 0x8c0(%r15), %rsi
movq %rbx, %rdi
callq 0x370a6
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
pushq $0x28
popq %rdx
callq 0x3716c
xorl %r12d, %r12d
pushq $0x3
popq %r14
movslq 0x844(%r15), %rax
cmpq %rax, %r12
jge 0x5fa0b
movq 0x848(%r15), %rax
movq (%rax,%r12,8), %rax
testb $0x8, 0x30(%rax)
jne 0x5f9fe
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x370d9
movq 0x848(%r15), %rax
movq (%rax,%r12,8), %rsi
movl $0x890, %eax            # imm = 0x890
addq %rax, %rsi
movq %rbx, %rdi
callq 0x36f5d
movq 0x848(%r15), %rax
movq (%rax,%r12,8), %rax
movslq 0x8c0(%rax), %rsi
movq %rbx, %rdi
callq 0x370a6
movq 0x848(%r15), %rax
movq (%rax,%r12,8), %rsi
addq $0x8, %rsi
movq %rbx, %rdi
pushq $0x28
popq %rdx
callq 0x3716c
incl %r14d
incq %r12
jmp 0x5f984
movl %edi, %r12d
movl %r14d, %ebp
jmp 0x5fa28
movslq %r14d, %rdx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x36de9
incl %r13d
pushq $-0x1
popq %rdi
movl %edi, %r12d
pushq $0x8
popq %r8
incl %ebp
movl %r12d, %esi
movl %ebp, %r14d
movq 0x30(%rsp), %r12
jmp 0x5f896
movq 0x8(%rsp), %r14
jmp 0x5f845
movq %r12, %rdi
callq 0x2aa94
movslq %r13d, %rdx
movq %rbx, %rdi
movq %r14, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36de9