// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/cluster.c
// Function: clusterReset
void clusterReset(int hard) {
    dictIterator *di;
    dictEntry *de;
    int j;

    /* Turn into master. */
    if (nodeIsSlave(myself)) {
        clusterSetNodeAsMaster(myself);
        replicationUnsetMaster();
        emptyDb(NULL);
    }

    /* Close slots, reset manual failover state. */
    clusterCloseAllSlots();
    resetManualFailover();

    /* Unassign all the slots. */
    for (j = 0; j < CLUSTER_SLOTS; j++) clusterDelSlot(j);

    /* Forget all the nodes, but myself. */
    di = dictGetSafeIterator(server.cluster->nodes);
    while((de = dictNext(di)) != NULL) {
        clusterNode *node = dictGetVal(de);

        if (node == myself) continue;
        clusterDelNode(node);
    }
    dictReleaseIterator(di);

    /* Hard reset only: set epochs to 0, change node ID. */
    if (hard) {
        sds oldname;

        server.cluster->currentEpoch = 0;
        server.cluster->lastVoteEpoch = 0;
        myself->configEpoch = 0;
        serverLog(LL_WARNING, "configEpoch set to 0 via CLUSTER RESET HARD");

        /* To change the Node ID we need to remove the old name from the
         * nodes table, change the ID, and re-add back with new name. */
        oldname = sdsnewlen(myself->name, CLUSTER_NAMELEN);
        dictDelete(server.cluster->nodes,oldname);
        sdsfree(oldname);
        getRandomHexChars(myself->name, CLUSTER_NAMELEN);
        clusterAddNode(myself);
        serverLog(LL_NOTICE,"Node hard reset, now I'm %.40s", myself->name);
    }

    /* Make sure to persist the new config and update the state. */
    clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG|
                         CLUSTER_TODO_UPDATE_STATE|
                         CLUSTER_TODO_FSYNC_CONFIG);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
movq 0xb13ce(%rip), %rdi     # 0x11b1d0
testb $0x2, 0x30(%rdi)
je 0x69e19
callq 0x69f8d
callq 0x49f71
xorl %edi, %edi
callq 0x45479
leaq 0x9ca38(%rip), %r15     # 0x106858
movq 0x9a0(%r15), %rdi
addq $0x28, %rdi
xorl %ebp, %ebp
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x26110
movl $0x20028, %edi          # imm = 0x20028
addq 0x9a0(%r15), %rdi
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x26110
callq 0x69da6
movl %ebp, %edi
callq 0x69fe5
incl %ebp
cmpl $0x4000, %ebp           # imm = 0x4000
jne 0x69e56
movq 0x9a0(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x320e5
movq %rax, %r14
movq %rax, %rdi
callq 0x32116
testq %rax, %rax
je 0x69e9e
movq 0x8(%rax), %rdi
cmpq 0xb133e(%rip), %rdi     # 0x11b1d0
je 0x69e99
callq 0x6a07e
movq %r14, %rdi
jmp 0x69e7d
movq %r14, %rdi
callq 0x321d3
testl %ebx, %ebx
je 0x69f74
movq 0x9a0(%r15), %rax
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rcx, 0x60078(%rax)
movq 0xb1307(%rip), %rax     # 0x11b1d0
movq %rcx, 0x38(%rax)
leaq 0x60aac(%rip), %rsi     # 0xca980
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0xb12e9(%rip), %rdi     # 0x11b1d0
addq $0x8, %rdi
movl $0x28, %esi
callq 0x3910c
movq %rax, %rbx
movq 0x9a0(%r15), %rax
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x31dba
movq %rbx, %rdi
callq 0x392b6
movq 0xb12b6(%rip), %rdi     # 0x11b1d0
addq $0x8, %rdi
movl $0x28, %esi
callq 0x43699
movq 0xb12a1(%rip), %rbx     # 0x11b1d0
movq 0x9a0(%r15), %rax
movq 0x18(%rax), %r14
leaq 0x8(%rbx), %rdi
movl $0x28, %esi
callq 0x3910c
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x31a95
movq 0xb1273(%rip), %rdx     # 0x11b1d0
addq $0x8, %rdx
leaq 0x60a44(%rip), %rsi     # 0xca9ac
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0x9a0(%r15), %rax
orl $0xe, 0x60080(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq