// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/cluster.c
// Function: clusterReset
void clusterReset(int hard) {
    dictIterator *di;
    dictEntry *de;
    int j;

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

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

    /* Unassign all the slots. */
    for (j = 0; j < REDIS_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;

        /* 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, REDIS_CLUSTER_NAMELEN);
        dictDelete(server.cluster->nodes,oldname);
        sdsfree(oldname);
        getRandomHexChars(myself->name, REDIS_CLUSTER_NAMELEN);
        clusterAddNode(myself);
    }

    /* 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 0x8dfac(%rip), %rdi     # 0xde628
testb $0x2, 0x30(%rdi)
je 0x5068c
callq 0x507c8
callq 0x357e0
leaq 0x79915(%rip), %r15     # 0xc9fa8
movq 0x7d0(%r15), %rdi
addq $0x28, %rdi
xorl %ebp, %ebp
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x1f110
movl $0x20028, %edi          # imm = 0x20028
addq 0x7d0(%r15), %rdi
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x1f110
callq 0x50620
movl %ebp, %edi
callq 0x5085d
incl %ebp
cmpl $0x4000, %ebp           # imm = 0x4000
jne 0x506c9
movq 0x7d0(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x22aa0
movq %rax, %r14
movq %rax, %rdi
callq 0x22acf
testq %rax, %rax
je 0x50711
movq 0x8(%rax), %rdi
cmpq 0x8df23(%rip), %rdi     # 0xde628
je 0x5070c
callq 0x508f6
movq %r14, %rdi
jmp 0x506f0
movq %r14, %rdi
callq 0x22b86
testl %ebx, %ebx
je 0x507af
movq 0x7d0(%r15), %rax
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rcx, 0x60070(%rax)
movq 0x8deec(%rip), %rdi     # 0xde628
movq %rcx, 0x38(%rdi)
addq $0x8, %rdi
movl $0x28, %esi
callq 0x283f4
movq %rax, %rbx
movq 0x7d0(%r15), %rax
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x22796
movq %rbx, %rdi
callq 0x2850d
movq 0x8deb5(%rip), %rdi     # 0xde628
addq $0x8, %rdi
movl $0x28, %esi
callq 0x3036a
movq 0x8dea0(%rip), %rbx     # 0xde628
movq 0x7d0(%r15), %rax
movq 0x18(%rax), %r14
leaq 0x8(%rbx), %rdi
movl $0x28, %esi
callq 0x283f4
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2249c
movq 0x7d0(%r15), %rax
orl $0xe, 0x60078(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq