// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0xb00a5(%rip), %rdi     # 0x116230
testb $0x2, 0x30(%rdi)
je 0x661a2
callq 0x66316
callq 0x46c8e
xorl %edi, %edi
callq 0x41fe5
leaq 0x9b6ff(%rip), %r15     # 0x1018a8
movq 0x9b0(%r15), %rdi
addq $0x28, %rdi
xorl %ebp, %ebp
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x26110
movl $0x20028, %edi          # imm = 0x20028
addq 0x9b0(%r15), %rdi
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x26110
callq 0x6612f
movl %ebp, %edi
callq 0x66373
incl %ebp
cmpl $0x4000, %ebp           # imm = 0x4000
jne 0x661df
movq 0x9b0(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x2efe5
movq %rax, %r14
movq %rax, %rdi
callq 0x2f015
testq %rax, %rax
je 0x66227
movq 0x8(%rax), %rdi
cmpq 0xb0015(%rip), %rdi     # 0x116230
je 0x66222
callq 0x6640c
movq %r14, %rdi
jmp 0x66206
movq %r14, %rdi
callq 0x2f0dd
testl %ebx, %ebx
je 0x662fd
movq 0x9b0(%r15), %rax
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rcx, 0x60078(%rax)
movq 0xaffde(%rip), %rax     # 0x116230
movq %rcx, 0x38(%rax)
leaq 0x617ab(%rip), %rsi     # 0xc7a08
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0xaffc0(%rip), %rdi     # 0x116230
addq $0x8, %rdi
movl $0x28, %esi
callq 0x36178
movq %rax, %rbx
movq 0x9b0(%r15), %rax
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x2ecb5
movq %rbx, %rdi
callq 0x36330
movq 0xaff8d(%rip), %rdi     # 0x116230
addq $0x8, %rdi
movl $0x28, %esi
callq 0x40256
movq 0xaff78(%rip), %rbx     # 0x116230
movq 0x9b0(%r15), %rax
movq 0x18(%rax), %r14
leaq 0x8(%rbx), %rdi
movl $0x28, %esi
callq 0x36178
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2e9b8
movq 0xaff4a(%rip), %rdx     # 0x116230
addq $0x8, %rdx
leaq 0x61743(%rip), %rsi     # 0xc7a34
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x9b0(%r15), %rax
orl $0xe, 0x60080(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq