// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/cluster.c
// Function: clusterUpdateSlotsConfigWith
void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoch, unsigned char *slots) {
    int j;
    clusterNode *curmaster, *newmaster = NULL;
    /* The dirty slots list is a list of slots for which we lose the ownership
     * while having still keys inside. This usually happens after a failover
     * or after a manual cluster reconfiguration operated by the admin.
     *
     * If the update message is not able to demote a master to slave (in this
     * case we'll resync with the master updating the whole key space), we
     * need to delete all the keys in the slots we lost ownership. */
    uint16_t dirty_slots[CLUSTER_SLOTS];
    int dirty_slots_count = 0;

    /* Here we set curmaster to this node or the node this node
     * replicates to if it's a slave. In the for loop we are
     * interested to check if slots are taken away from curmaster. */
    curmaster = nodeIsMaster(myself) ? myself : myself->slaveof;

    if (sender == myself) {
        serverLog(LL_WARNING,"Discarding UPDATE message about myself.");
        return;
    }

    for (j = 0; j < CLUSTER_SLOTS; j++) {
        if (bitmapTestBit(slots,j)) {
            /* The slot is already bound to the sender of this message. */
            if (server.cluster->slots[j] == sender) continue;

            /* The slot is in importing state, it should be modified only
             * manually via redis-trib (example: a resharding is in progress
             * and the migrating side slot was already closed and is advertising
             * a new config. We still want the slot to be closed manually). */
            if (server.cluster->importing_slots_from[j]) continue;

            /* We rebind the slot to the new node claiming it if:
             * 1) The slot was unassigned or the new node claims it with a
             *    greater configEpoch.
             * 2) We are not currently importing the slot. */
            if (server.cluster->slots[j] == NULL ||
                server.cluster->slots[j]->configEpoch < senderConfigEpoch)
            {
                /* Was this slot mine, and still contains keys? Mark it as
                 * a dirty slot. */
                if (server.cluster->slots[j] == myself &&
                    countKeysInSlot(j) &&
                    sender != myself)
                {
                    dirty_slots[dirty_slots_count] = j;
                    dirty_slots_count++;
                }

                if (server.cluster->slots[j] == curmaster)
                    newmaster = sender;
                clusterDelSlot(j);
                clusterAddSlot(sender,j);
                clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG|
                                     CLUSTER_TODO_UPDATE_STATE|
                                     CLUSTER_TODO_FSYNC_CONFIG);
            }
        }
    }

    /* If at least one slot was reassigned from a node to another node
     * with a greater configEpoch, it is possible that:
     * 1) We are a master left without slots. This means that we were
     *    failed over and we should turn into a replica of the new
     *    master.
     * 2) We are a slave and our master is left without slots. We need
     *    to replicate to the new slots owner. */
    if (newmaster && curmaster->numslots == 0) {
        serverLog(LL_WARNING,
            "Configuration change detected. Reconfiguring myself "
            "as a replica of %.40s", sender->name);
        clusterSetMaster(sender);
        clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG|
                             CLUSTER_TODO_UPDATE_STATE|
                             CLUSTER_TODO_FSYNC_CONFIG);
    } else if (dirty_slots_count) {
        /* If we are here, we received an update message which removed
         * ownership for certain slots we still have keys about, but still
         * we are serving some slots, so this master node was not demoted to
         * a slave.
         *
         * In order to maintain a consistent state between keys and slots
         * we need to remove all the keys from the slots we lost. */
        for (j = 0; j < dirty_slots_count; j++)
            delKeysInSlot(dirty_slots[j]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8040, %rsp           # imm = 0x8040
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x8034(%rbp)
movq 0x10d850(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7f32b
movq 0x10d83e(%rip), %rax    # 0x18cb60
movq %rax, -0x8040(%rbp)
jmp 0x7f340
movq 0x10d82e(%rip), %rax    # 0x18cb60
movq 0x850(%rax), %rax
movq %rax, -0x8040(%rbp)
movq -0x8040(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpq 0x10d80a(%rip), %rax    # 0x18cb60
jne 0x7f370
movl $0x3, %edi
leaq 0xc29f9(%rip), %rsi     # 0x141d5d
movb $0x0, %al
callq 0x2fc60
jmp 0x7f55d
movl $0x0, -0x1c(%rbp)
cmpl $0x4000, -0x1c(%rbp)    # imm = 0x4000
jge 0x7f4de
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x7f570
cmpl $0x0, %eax
je 0x7f4ce
leaq 0xf8e38(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq 0x40028(%rax,%rcx,8), %rax
cmpq -0x8(%rbp), %rax
jne 0x7f3be
jmp 0x7f4d0
leaq 0xf8e13(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x1c(%rbp), %rcx
cmpq $0x0, 0x20028(%rax,%rcx,8)
je 0x7f3e0
jmp 0x7f4d0
leaq 0xf8df1(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x1c(%rbp), %rcx
cmpq $0x0, 0x40028(%rax,%rcx,8)
je 0x7f425
leaq 0xf8dd4(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq 0x40028(%rax,%rcx,8), %rax
movq 0x38(%rax), %rax
cmpq -0x10(%rbp), %rax
jae 0x7f4cc
leaq 0xf8dac(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq 0x40028(%rax,%rcx,8), %rax
cmpq 0x10d71a(%rip), %rax    # 0x18cb60
jne 0x7f486
movl -0x1c(%rbp), %edi
callq 0x4d600
cmpl $0x0, %eax
je 0x7f486
movq -0x8(%rbp), %rax
cmpq 0x10d700(%rip), %rax    # 0x18cb60
je 0x7f486
movl -0x1c(%rbp), %eax
movw %ax, %cx
movslq -0x8034(%rbp), %rax
movw %cx, -0x8030(%rbp,%rax,2)
movl -0x8034(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8034(%rbp)
leaq 0xf8d4b(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq 0x40028(%rax,%rcx,8), %rax
cmpq -0x28(%rbp), %rax
jne 0x7f4ae
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %edi
callq 0x7d970
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x7cb70
movl $0xe, %edi
callq 0x7db50
jmp 0x7f4ce
jmp 0x7f4d0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7f377
cmpq $0x0, -0x30(%rbp)
je 0x7f522
movq -0x28(%rbp), %rax
cmpl $0x0, 0x840(%rax)
jne 0x7f522
movq -0x8(%rbp), %rdx
addq $0x8, %rdx
movl $0x3, %edi
leaq 0xc287f(%rip), %rsi     # 0x141d85
movb $0x0, %al
callq 0x2fc60
movq -0x8(%rbp), %rdi
callq 0x7f5c0
movl $0xe, %edi
callq 0x7db50
jmp 0x7f55d
cmpl $0x0, -0x8034(%rbp)
je 0x7f55b
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x8034(%rbp), %eax
jge 0x7f559
movslq -0x1c(%rbp), %rax
movzwl -0x8030(%rbp,%rax,2), %edi
callq 0x4d520
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7f532
jmp 0x7f55b
jmp 0x7f55d
addq $0x8040, %rsp           # imm = 0x8040
popq %rbp
retq
nopw %cs:(%rax,%rax)