// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8018, %rsp           # imm = 0x8018
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movq 0xaec6d(%rip), %rax     # 0x116230
testb $0x1, 0x30(%rax)
movq %rax, %rbp
jne 0x675d3
movq 0x850(%rax), %rbp
cmpq %rbx, %rax
je 0x6770b
xorl %r12d, %r12d
leaq 0x9a2c2(%rip), %r13     # 0x1018a8
movq $0x0, (%rsp)
xorl %r15d, %r15d
movl %r12d, %eax
shrl $0x3, %eax
movzbl (%r14,%rax), %eax
movl %r12d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x676cb
movq 0x9b0(%r13), %rcx
movq 0x40028(%rcx,%r12,8), %rax
cmpq %rbx, %rax
je 0x676cb
cmpq $0x0, 0x20028(%rcx,%r12,8)
jne 0x676cb
testq %rax, %rax
je 0x67646
movq 0x8(%rsp), %rcx
cmpq %rcx, 0x38(%rax)
jae 0x676cb
cmpq 0xaebe3(%rip), %rax     # 0x116230
jne 0x67676
movl %r12d, %edi
callq 0x43ddd
testl %eax, %eax
je 0x67676
cmpq %rbx, 0xaebce(%rip)     # 0x116230
je 0x67676
movq (%rsp), %rax
cltq
movw %r12w, 0x10(%rsp,%rax,2)
incl %eax
movq %rax, (%rsp)
movq 0x9b0(%r13), %rax
cmpq %rbp, 0x40028(%rax,%r12,8)
cmoveq %rbx, %r15
movl %r12d, %edi
callq 0x66373
movq 0x9b0(%r13), %rax
cmpq $0x0, 0x40028(%rax,%r12,8)
jne 0x676c4
movq %rbx, %rdi
movl %r12d, %esi
callq 0x6a187
movq 0x9b0(%r13), %rax
movq %rbx, 0x40028(%rax,%r12,8)
movq 0x9b0(%r13), %rax
orb $0xe, 0x60080(%rax)
incq %r12
cmpq $0x4000, %r12           # imm = 0x4000
jne 0x675f1
testq %r15, %r15
je 0x676e9
cmpl $0x0, 0x840(%rbp)
je 0x6772f
movq (%rsp), %rax
testl %eax, %eax
jle 0x6775c
movl %eax, %ebx
xorl %r14d, %r14d
movzwl 0x10(%rsp,%r14,2), %edi
callq 0x43d3d
incq %r14
cmpq %r14, %rbx
jne 0x676f6
jmp 0x6775c
leaq 0x605ca(%rip), %rsi     # 0xc7cdc
movl $0x3, %edi
xorl %eax, %eax
addq $0x8018, %rsp           # imm = 0x8018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2fdad
leaq 0x8(%rbx), %rdx
leaq 0x605ca(%rip), %rsi     # 0xc7d04
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movq %rbx, %rdi
callq 0x6778b
movq 0x9b0(%r13), %rax
orl $0xe, 0x60080(%rax)
addq $0x8018, %rsp           # imm = 0x8018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq