// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq 0xbe866(%rip), %rax     # 0x127f78
movl 0x30(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6972e
movq 0xbe854(%rip), %rdi     # 0x127f78
callq 0x69870
callq 0x420c0
callq 0x694d0
callq 0x69650
movl $0x0, -0x1c(%rbp)
cmpl $0x4000, -0x1c(%rbp)    # imm = 0x4000
jge 0x6975b
movl -0x1c(%rbp), %edi
callq 0x698f0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6973f
leaq 0xaa196(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x24240
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x24270
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x697af
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq 0xbe7d8(%rip), %rax     # 0x127f78
jne 0x697a4
jmp 0x69776
movq -0x28(%rbp), %rdi
callq 0x69990
jmp 0x69776
movq -0x10(%rbp), %rdi
callq 0x243d0
cmpl $0x0, -0x4(%rbp)
je 0x6985e
leaq 0xaa12f(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x8(%rax)
leaq 0xaa119(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x60070(%rax)
movq 0xbe780(%rip), %rax     # 0x127f78
movq $0x0, 0x38(%rax)
movq 0xbe771(%rip), %rdi     # 0x127f78
addq $0x8, %rdi
movl $0x28, %esi
callq 0x2c000
movq %rax, -0x30(%rbp)
leaq 0xaa0d8(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x23c30
movq -0x30(%rbp), %rdi
callq 0x2c160
movq 0xbe734(%rip), %rdi     # 0x127f78
addq $0x8, %rdi
movl $0x28, %esi
callq 0x39c50
movq 0xbe71f(%rip), %rdi     # 0x127f78
callq 0x68bb0
movl $0xe, %edi
callq 0x69b00
addq $0x30, %rsp
popq %rbp
retq
nop