// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0x402b0
movq %rax, %r14
leaq 0x98766(%rip), %rax     # 0x106858
movq 0x9a0(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x320e5
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x32116
xorl %r13d, %r13d
testq %rax, %rax
je 0x6e337
movq %r14, 0x10(%rsp)
movq 0x8(%rax), %rbp
testb $0x1, 0x30(%rbp)
je 0x6e31c
cmpl $0x0, 0x840(%rbp)
je 0x6e31c
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 0x6e301
cmpl $0x3fff, %r15d          # imm = 0x3FFF
je 0x6e1b0
movl %r12d, %eax
andl $0x1, %eax
jne 0x6e307
movq %rbx, %rdi
callq 0x402b0
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 0x40606
cmpl %r13d, %r14d
movslq %r13d, %rsi
movq 0x30(%rsp), %r13
cmoveq %r15, %rsi
movq %rbx, %rdi
callq 0x40606
movl $0x3, %r15d
movl $0x3, %esi
movq %rbx, %rdi
callq 0x4063b
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x404b9
movslq 0x8c0(%rbp), %rsi
movq %rbx, %rdi
callq 0x40606
movl $0x28, %edx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x4070f
cmpl $0x0, 0x844(%rbp)
jle 0x6e2e6
movl $0x3, %r14d
xorl %r15d, %r15d
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rax
testb $0x8, 0x30(%rax)
jne 0x6e2d0
movl $0x3, %esi
movq %rbx, %rdi
callq 0x4063b
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rsi
movl $0x890, %eax            # imm = 0x890
addq %rax, %rsi
movq %rbx, %rdi
callq 0x404b9
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rax
movslq 0x8c0(%rax), %rsi
movq %rbx, %rdi
callq 0x40606
movq 0x848(%rbp), %rax
movq (%rax,%r15,8), %rsi
addq $0x8, %rsi
movl $0x28, %edx
movq %rbx, %rdi
callq 0x4070f
incl %r14d
incq %r15
movslq 0x844(%rbp), %rax
cmpq %rax, %r15
jl 0x6e25e
movslq %r14d, %r15
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x402ec
incl %r13d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x6e30a
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r15d, %r12d
leal 0x1(%r12), %r15d
cmpl $0x3fff, %r12d          # imm = 0x3FFF
jl 0x6e159
movq 0x8(%rsp), %rdi
callq 0x32116
testq %rax, %rax
jne 0x6e120
movslq %r13d, %r13
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rdi
callq 0x321d3
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 0x402ec