// File: /workspace/github_c_makefile_star2_O1/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 0x8d9f3(%rip), %rdi     # 0xde628
testb $0x2, 0x30(%rdi)
je 0x50c45
callq 0x50d81
callq 0x353b2
leaq 0x7935c(%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 0x50bd9
movl %ebp, %edi
callq 0x50e15
incl %ebp
cmpl $0x4000, %ebp           # imm = 0x4000
jne 0x50c82
movq 0x7d0(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x228e4
movq %rax, %r14
movq %rax, %rdi
callq 0x22913
testq %rax, %rax
je 0x50cca
movq 0x8(%rax), %rdi
cmpq 0x8d96a(%rip), %rdi     # 0xde628
je 0x50cc5
callq 0x50eae
movq %r14, %rdi
jmp 0x50ca9
movq %r14, %rdi
callq 0x229b9
testl %ebx, %ebx
je 0x50d68
movq 0x7d0(%r15), %rax
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rcx, 0x60070(%rax)
movq 0x8d933(%rip), %rdi     # 0xde628
movq %rcx, 0x38(%rdi)
addq $0x8, %rdi
movl $0x28, %esi
callq 0x28148
movq %rax, %rbx
movq 0x7d0(%r15), %rax
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x225d3
movq %rbx, %rdi
callq 0x28204
movq 0x8d8fc(%rip), %rdi     # 0xde628
addq $0x8, %rdi
movl $0x28, %esi
callq 0x30096
movq 0x8d8e7(%rip), %rbx     # 0xde628
movq 0x7d0(%r15), %rax
movq 0x18(%rax), %r14
leaq 0x8(%rbx), %rdi
movl $0x28, %esi
callq 0x28148
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x222b6
movq 0x7d0(%r15), %rax
orl $0xe, 0x60078(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq