// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x432a0
movq %rax, -0x18(%rbp)
leaq 0xf47e1(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x2e470
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2e4a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x83c70
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x83a58
movq -0x30(%rbp), %rax
cmpl $0x0, 0x840(%rax)
jne 0x83a5a
jmp 0x83a0b
movl $0x0, -0x34(%rbp)
cmpl $0x4000, -0x34(%rbp)    # imm = 0x4000
jge 0x83c6b
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x81d00
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x83a90
cmpl $-0x1, -0x38(%rbp)
jne 0x83a8e
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x83a90
cmpl $-0x1, -0x38(%rbp)
je 0x83c5b
cmpl $0x0, -0x3c(%rbp)
je 0x83aad
cmpl $0x3fff, -0x34(%rbp)    # imm = 0x3FFF
jne 0x83c5b
movl $0x3, -0x44(%rbp)
movq -0x8(%rbp), %rdi
callq 0x432a0
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x83ad9
cmpl $0x3fff, -0x34(%rbp)    # imm = 0x3FFF
jne 0x83ad9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x83b02
movq -0x8(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x43780
movq -0x8(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x43780
jmp 0x83b21
movq -0x8(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x43780
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x43780
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x437f0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x890, %rsi            # imm = 0x890
callq 0x43580
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq 0x8c0(%rax), %rsi
callq 0x43780
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
movl $0x28, %edx
callq 0x43920
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x844(%rcx), %eax
jge 0x83c41
movq -0x30(%rbp), %rax
movq 0x848(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x30(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x83bb1
jmp 0x83c33
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x437f0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x848(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x890, %rsi            # imm = 0x890
callq 0x43580
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x848(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x8c0(%rax), %rsi
callq 0x43780
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x848(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
movl $0x28, %edx
callq 0x43920
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x83b7b
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq -0x44(%rbp), %rdx
callq 0x43310
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x83c5d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x83a61
jmp 0x83a0b
movq -0x28(%rbp), %rdi
callq 0x2e600
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0xc(%rbp), %rdx
callq 0x43310
addq $0x50, %rsp
popq %rbp
retq