// File: /workspace/github_cpp_makefile_star2_O2/SeanChao[P]KV-Store/kvstore.cc
// Function: KVStore::renameLevel(int, int)
void KVStore::renameLevel(int level, int mode) {
    if (mode == 0) {
        int id = 0;
        if (!std::filesystem::exists(resolvePath(-1)))
            std::filesystem::create_directories(resolvePath(-1));
        while (std::filesystem::exists(resolvePath(level, id))) {
            std::filesystem::rename(resolvePath(level, id),
                                    resolvePath(-1, id));
            std::clog << "rename " << resolvePath(level, id) << "->"
                      << resolvePath(-1, id) << std::endl;
            id++;
        }
    } else if (mode == 1) {
        int tmp = 0;
        int id = 0;
        while (std::filesystem::exists(resolvePath(-1, tmp))) {
            while (std::filesystem::exists(resolvePath(level, id))) id++;
            std::filesystem::rename(resolvePath(-1, tmp++),
                                    resolvePath(level, id++));
            std::clog << "rename " << resolvePath(-1, tmp - 1) << "->"
                      << resolvePath(level, id - 1) << std::endl;
        }
    } else {
        std::clog << "error no rename with mode " << mode << std::endl;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %esi, %ebx
movq %rdi, %r14
testl %edx, %edx
je 0x5957
movl %edx, %ebp
cmpl $0x1, %edx
jne 0x5b2f
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
leaq 0x8(%rsp), %r13
xorl %ebp, %ebp
movq %r15, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rdx
movl %r12d, 0x4(%rsp)
movl %r12d, %ecx
callq 0x51ec
movq %r13, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0x7588
movq %r13, %rdi
callq 0x738a
movl %eax, %r12d
movq %r13, %rdi
callq 0x740e
movq %r15, %rdi
callq 0x3438
testb %r12b, %r12b
je 0x5b1d
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x51ec
movq %r13, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0x7588
movq %r13, %rdi
callq 0x738a
movl %eax, %r12d
movq %r13, %rdi
callq 0x740e
movq %r15, %rdi
callq 0x3438
testb %r12b, %r12b
je 0x585d
incl %ebp
jmp 0x581c
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rdx
movl 0x4(%rsp), %ecx
callq 0x51ec
movq %r13, %rdi
movq %r12, %rsi
pushq $0x2
popq %rdx
callq 0x7588
leaq 0x78(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x51ec
movq %r15, %rdi
movq %r12, %rsi
pushq $0x2
popq %rdx
callq 0x7588
movq %r13, %rdi
movq %r15, %rsi
callq 0x3190
movq %r15, %rdi
callq 0x740e
movq %r12, %rdi
callq 0x3438
movq %r13, %rdi
callq 0x740e
leaq 0x58(%rsp), %rdi
callq 0x3438
movq 0x96d0(%rip), %rdi      # 0xefa8
leaq 0x4aae(%rip), %rsi      # 0xa38d
callq 0x3270
movq %rax, %r12
movq %r13, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rdx
movl 0x4(%rsp), %ecx
callq 0x51ec
movq %r12, %rdi
movq %r13, %rsi
callq 0x3240
movq %rax, %rdi
leaq 0x49ec(%rip), %rsi      # 0xa2fa
callq 0x3270
movq %rax, %r12
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x51ec
movq %r12, %rdi
movq %r15, %rsi
callq 0x3240
movq %rax, %rdi
callq 0x3160
movl 0x4(%rsp), %r12d
incl %r12d
incl %ebp
movq %r15, %rdi
callq 0x3438
movq %r13, %rdi
callq 0x3438
jmp 0x57d4
leaq 0x30(%rsp), %r15
pushq $-0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5694
leaq 0x8(%rsp), %rdi
pushq $0x2
popq %rdx
movq %r15, %rsi
callq 0x7588
leaq 0x8(%rsp), %rdi
callq 0x738a
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x740e
leaq 0x30(%rsp), %rdi
callq 0x3438
testb %bpl, %bpl
jne 0x59e0
leaq 0x30(%rsp), %r15
pushq $-0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5694
leaq 0x8(%rsp), %rdi
pushq $0x2
popq %rdx
movq %r15, %rsi
callq 0x7588
leaq 0x8(%rsp), %rdi
callq 0x31a0
leaq 0x8(%rsp), %rdi
callq 0x740e
leaq 0x30(%rsp), %rdi
callq 0x3438
xorl %ebp, %ebp
leaq 0x30(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x51ec
movq %r12, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0x7588
movq %r12, %rdi
callq 0x738a
movl %eax, %r13d
movq %r12, %rdi
callq 0x740e
movq %r15, %rdi
callq 0x3438
testb %r13b, %r13b
je 0x5b1d
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x51ec
movq %r12, %rdi
movq %r13, %rsi
pushq $0x2
popq %rdx
callq 0x7588
leaq 0x78(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rdx
movl %ebp, %ecx
callq 0x51ec
movq %r15, %rdi
movq %r13, %rsi
pushq $0x2
popq %rdx
callq 0x7588
movq %r12, %rdi
movq %r15, %rsi
callq 0x3190
movq %r15, %rdi
callq 0x740e
leaq 0x78(%rsp), %rdi
callq 0x3438
movq %r12, %rdi
callq 0x740e
leaq 0x58(%rsp), %rdi
callq 0x3438
movq 0x9500(%rip), %rdi      # 0xefa8
leaq 0x48de(%rip), %rsi      # 0xa38d
callq 0x3270
movq %rax, %r13
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x51ec
movq %r13, %rdi
movq %r12, %rsi
callq 0x3240
movq %rax, %rdi
leaq 0x481f(%rip), %rsi      # 0xa2fa
callq 0x3270
movq %rax, %r13
movq %r15, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rdx
movl %ebp, %ecx
callq 0x51ec
movq %r13, %rdi
movq %r15, %rsi
callq 0x3240
movq %rax, %rdi
callq 0x3160
movq %r15, %rdi
callq 0x3438
movq %r12, %rdi
callq 0x3438
incl %ebp
jmp 0x59ec
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9472(%rip), %rdi      # 0xefa8
leaq 0x4858(%rip), %rsi      # 0xa395
callq 0x3270
movq %rax, %rdi
movl %ebp, %esi
callq 0x33c0
movq %rax, %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3160
jmp 0x5bda
jmp 0x5bd5
jmp 0x5bda
jmp 0x5bd5
jmp 0x5bcb
jmp 0x5b77
jmp 0x5b83
jmp 0x5b7e
jmp 0x5b88
movq %rax, %rbx
jmp 0x5ba9
jmp 0x5bcb
movq %rax, %rbx
jmp 0x5b95
movq %rax, %rbx
jmp 0x5b9f
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x740e
leaq 0x78(%rsp), %rdi
callq 0x3438
leaq 0x8(%rsp), %rdi
callq 0x740e
leaq 0x58(%rsp), %rdi
jmp 0x5bec
jmp 0x5bd5
jmp 0x5bda
jmp 0x5bd5
jmp 0x5bda
jmp 0x5bcb
jmp 0x5bbc
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3438
jmp 0x5bce
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x5bec
movq %rax, %rbx
jmp 0x5be7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x740e
leaq 0x30(%rsp), %rdi
callq 0x3438
movq %rbx, %rdi
callq 0x33e0
nop