// File: /workspace/github_c_makefile_star2_O2/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 0xb155e(%rip), %rax     # 0x10e230
testb $0x1, 0x30(%rax)
movq %rax, (%rsp)
jne 0x5cce7
movq 0x850(%rax), %rcx
movq %rcx, (%rsp)
cmpq %rbx, %rax
je 0x5cdf4
xorl %r12d, %r12d
leaq 0x9cbae(%rip), %rbp     # 0xf98a8
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq $0x4000, %r12           # imm = 0x4000
je 0x5cdc0
movl %r12d, %eax
shrl $0x3, %eax
movzbl (%r14,%rax), %eax
movl %r12d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5cdb8
movq 0x9b0(%rbp), %rcx
movq 0x40028(%rcx,%r12,8), %rax
cmpq %rbx, %rax
je 0x5cdb8
cmpq $0x0, 0x20028(%rcx,%r12,8)
jne 0x5cdb8
testq %rax, %rax
je 0x5cd56
movq 0x8(%rsp), %rcx
cmpq %rcx, 0x38(%rax)
jae 0x5cdb8
cmpq 0xb14d3(%rip), %rax     # 0x10e230
jne 0x5cd80
movl %r12d, %edi
callq 0x3cb9a
testl %eax, %eax
je 0x5cd80
cmpq %rbx, 0xb14be(%rip)     # 0x10e230
je 0x5cd80
movslq %r13d, %r13
movw %r12w, 0x10(%rsp,%r13,2)
incl %r13d
movq 0x9b0(%rbp), %rax
movq (%rsp), %rcx
cmpq %rcx, 0x40028(%rax,%r12,8)
cmoveq %rbx, %r15
movl %r12d, %edi
callq 0x5bc88
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5b377
movq 0x9b0(%rbp), %rax
orl $0xe, 0x60080(%rax)
incq %r12
jmp 0x5cd00
testq %r15, %r15
je 0x5cdd2
movq (%rsp), %rax
cmpl $0x0, 0x840(%rax)
je 0x5ce16
testl %r13d, %r13d
je 0x5ce41
xorl %ebx, %ebx
testl %r13d, %r13d
cmovlel %ebx, %r13d
cmpq %rbx, %r13
je 0x5ce41
movzwl 0x10(%rsp,%rbx,2), %edi
callq 0x3cb04
incq %rbx
jmp 0x5cde0
leaq 0x5bec9(%rip), %rsi     # 0xb8cc4
pushq $0x3
popq %rdi
xorl %eax, %eax
addq $0x8018, %rsp           # imm = 0x8018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b699
leaq 0x8(%rbx), %rdx
leaq 0x5becb(%rip), %rsi     # 0xb8cec
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq %rbx, %rdi
callq 0x5ce6d
movq 0x9b0(%rbp), %rax
orl $0xe, 0x60080(%rax)
addq $0x8018, %rsp           # imm = 0x8018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq