// File: /workspace/github_c_makefile_star2_O3/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 0x3cee9
movq %rax, %r14
leaq 0x972fb(%rip), %rax     # 0x1018a8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x2efe5
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x2f015
xorl %r13d, %r13d
testq %rax, %rax
je 0x6a7f5
movq %r14, 0x10(%rsp)
movq 0x8(%rax), %rbp
testb $0x1, 0x30(%rbp)
je 0x6a7da
cmpl $0x0, 0x840(%rbp)
je 0x6a7da
leaq 0x890(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq 0x8(%rbp), %rax
movq %rax, 0x18(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
leal 0x7(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
movl %r14d, %edx
sarl $0x3, %eax
cltq
movzbl 0x40(%rbp,%rax), %eax
movl %r15d, %ecx
andb $0x7, %cl
movl %eax, %r12d
shrl %cl, %r12d
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
cmovbl %r15d, %r14d
cmpl $-0x1, %edx
cmovnel %edx, %r14d
cmpl $-0x1, %r14d
je 0x6a7bf
cmpl $0x3fff, %r15d          # imm = 0x3FFF
je 0x6a66b
movl %r12d, %eax
andl $0x1, %eax
jne 0x6a7c5
movq %rbx, %rdi
callq 0x3cee9
movq %rax, 0x28(%rsp)
testb $0x1, %r12b
movl %r15d, %r12d
movl $0x4000, %eax           # imm = 0x4000
cmovnel %eax, %r12d
cmpl $0x3fff, %r15d          # imm = 0x3FFF
cmovnel %r15d, %r12d
movq %r13, 0x30(%rsp)
leal -0x1(%r12), %r13d
movslq %r14d, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3d23f
cmpl %r13d, %r14d
movslq %r13d, %rsi
movq 0x30(%rsp), %r13
cmoveq %r15, %rsi
movq %rbx, %rdi
callq 0x3d23f
movl $0x3, %r15d
movl $0x3, %esi
movq %rbx, %rdi
callq 0x3d274
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x3d0f2
movslq 0x8c0(%rbp), %rsi
movq %rbx, %rdi
callq 0x3d23f
movl $0x28, %edx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x3d346
movl 0x844(%rbp), %eax
testl %eax, %eax
jle 0x6a7a4
movl $0x3, %r14d
xorl %r15d, %r15d
movq 0x848(%rbp), %rcx
movq (%rcx,%r15,8), %rcx
testb $0x8, 0x30(%rcx)
jne 0x6a792
movl $0x3, %esi
movq %rbx, %rdi
callq 0x3d274
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rsi
movl $0x890, %eax            # imm = 0x890
addq %rax, %rsi
movq %rbx, %rdi
callq 0x3d0f2
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rax
movslq 0x8c0(%rax), %rsi
movq %rbx, %rdi
callq 0x3d23f
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rsi
addq $0x8, %rsi
movl $0x28, %edx
movq %rbx, %rdi
callq 0x3d346
incl %r14d
movl 0x844(%rbp), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x6a71a
movslq %r14d, %r15
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x3cf25
incl %r13d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x6a7c8
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r15d, %r12d
leal 0x1(%r12), %r15d
cmpl $0x3fff, %r12d          # imm = 0x3FFF
jl 0x6a614
movq 0x8(%rsp), %rdi
callq 0x2f015
testq %rax, %rax
jne 0x6a5db
movslq %r13d, %r13
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rdi
callq 0x2f0dd
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cf25