// File: 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
movq %rsp, %rbp
subq $0x3f0, %rsp            # imm = 0x3F0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x340(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x914e
movq -0x340(%rbp), %rsi
movl $0x0, -0x14(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x348(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8b40
movq -0x348(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x8d54
leaq -0x40(%rbp), %rdi
callq 0xc570
movb %al, -0x349(%rbp)
jmp 0x8d65
movb -0x349(%rbp), %al
xorb $-0x1, %al
movb %al, -0x34a(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc680
leaq -0x60(%rbp), %rdi
callq 0x45d8
movb -0x34a(%rbp), %al
testb $0x1, %al
jne 0x8d94
jmp 0x8e5d
movq -0x340(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x358(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8b40
movq -0x358(%rbp), %rsi
leaq -0x98(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x8dcd
leaq -0x98(%rbp), %rdi
callq 0x4200
jmp 0x8ddb
leaq -0x98(%rbp), %rdi
callq 0xc680
leaq -0xb8(%rbp), %rdi
callq 0x45d8
jmp 0x8e5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8e18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc680
leaq -0x60(%rbp), %rdi
callq 0x45d8
jmp 0x956f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8e4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xc680
leaq -0xb8(%rbp), %rdi
callq 0x45d8
jmp 0x956f
jmp 0x8e5f
movq -0x340(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0x100(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x8330
movq -0x360(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x8e99
leaq -0xe0(%rbp), %rdi
callq 0xc570
movb %al, -0x361(%rbp)
jmp 0x8ead
leaq -0xe0(%rbp), %rdi
callq 0xc680
leaq -0x100(%rbp), %rdi
callq 0x45d8
movb -0x361(%rbp), %al
testb $0x1, %al
jne 0x8ed4
jmp 0x9149
movq -0x340(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0x148(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0x8330
movq -0x370(%rbp), %rsi
leaq -0x128(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x8f0e
movq -0x340(%rbp), %rsi
movl -0x14(%rbp), %ecx
leaq -0x190(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8330
jmp 0x8f2b
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movl $0x2, %edx
callq 0xd1a0
jmp 0x8f45
leaq -0x128(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x41e0
jmp 0x8f5a
leaq -0x170(%rbp), %rdi
callq 0xc680
leaq -0x190(%rbp), %rdi
callq 0x45d8
leaq -0x128(%rbp), %rdi
callq 0xc680
leaq -0x148(%rbp), %rdi
callq 0x45d8
movq 0x1600f(%rip), %rdi     # 0x1efa0
leaq 0xd42b(%rip), %rsi      # 0x163c3
callq 0x42f0
movq -0x340(%rbp), %rsi
movq %rax, -0x388(%rbp)
movl -0xc(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x8330
movq -0x388(%rbp), %rdi
movq -0x380(%rbp), %rsi
callq 0x42c0
movq %rax, -0x378(%rbp)
jmp 0x8fe0
movq -0x378(%rbp), %rdi
leaq 0xd342(%rip), %rsi      # 0x16330
callq 0x42f0
movq %rax, -0x390(%rbp)
jmp 0x8ffc
movq -0x340(%rbp), %rsi
movl -0x14(%rbp), %ecx
leaq -0x1d0(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8330
jmp 0x9019
movq -0x390(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x398(%rbp)
jmp 0x9035
movq -0x398(%rbp), %rdi
movq 0x15f6d(%rip), %rsi     # 0x1efb0
callq 0x4320
jmp 0x904a
leaq -0x1d0(%rbp), %rdi
callq 0x45d8
leaq -0x1b0(%rbp), %rdi
callq 0x45d8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8e5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9096
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xc680
leaq -0x100(%rbp), %rdi
callq 0x45d8
jmp 0x956f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9101
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x90f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x90e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xc680
leaq -0x190(%rbp), %rdi
callq 0x45d8
leaq -0x128(%rbp), %rdi
callq 0xc680
leaq -0x148(%rbp), %rdi
callq 0x45d8
jmp 0x956f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9138
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x45d8
leaq -0x1b0(%rbp), %rdi
callq 0x45d8
jmp 0x956f
jmp 0x9566
cmpl $0x1, -0x10(%rbp)
jne 0x9537
movl $0x0, -0x1d4(%rbp)
movl $0x0, -0x1d8(%rbp)
movq -0x340(%rbp), %rsi
movl -0x1d4(%rbp), %ecx
leaq -0x220(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8330
movq -0x3a0(%rbp), %rsi
leaq -0x200(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x91ab
leaq -0x200(%rbp), %rdi
callq 0xc570
movb %al, -0x3a1(%rbp)
jmp 0x91bf
leaq -0x200(%rbp), %rdi
callq 0xc680
leaq -0x220(%rbp), %rdi
callq 0x45d8
movb -0x3a1(%rbp), %al
testb $0x1, %al
jne 0x91e6
jmp 0x9535
jmp 0x91e8
movq -0x340(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x1d8(%rbp), %ecx
leaq -0x268(%rbp), %rdi
movq %rdi, -0x3b0(%rbp)
callq 0x8330
movq -0x3b0(%rbp), %rsi
leaq -0x248(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x9225
leaq -0x248(%rbp), %rdi
callq 0xc570
movb %al, -0x3b1(%rbp)
jmp 0x9239
leaq -0x248(%rbp), %rdi
callq 0xc680
leaq -0x268(%rbp), %rdi
callq 0x45d8
movb -0x3b1(%rbp), %al
testb $0x1, %al
jne 0x9260
jmp 0x92e2
movl -0x1d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d8(%rbp)
jmp 0x91e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x929a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0xc680
leaq -0x220(%rbp), %rdi
callq 0x45d8
jmp 0x956f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x92d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0xc680
leaq -0x268(%rbp), %rdi
callq 0x45d8
jmp 0x956f
movq -0x340(%rbp), %rsi
movl -0x1d4(%rbp), %ecx
movl %ecx, %eax
incl %eax
movl %eax, -0x1d4(%rbp)
leaq -0x2b0(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8330
movq -0x3c0(%rbp), %rsi
leaq -0x290(%rbp), %rdi
movl $0x2, %edx
callq 0xd1a0
jmp 0x932b
movq -0x340(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x1d8(%rbp), %ecx
movl %ecx, %eax
incl %eax
movl %eax, -0x1d8(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x8330
jmp 0x9353
leaq -0x2d8(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
movl $0x2, %edx
callq 0xd1a0
jmp 0x936d
leaq -0x290(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x41e0
jmp 0x9382
leaq -0x2d8(%rbp), %rdi
callq 0xc680
leaq -0x2f8(%rbp), %rdi
callq 0x45d8
leaq -0x290(%rbp), %rdi
callq 0xc680
leaq -0x2b0(%rbp), %rdi
callq 0x45d8
movq 0x15be7(%rip), %rdi     # 0x1efa0
leaq 0xd003(%rip), %rsi      # 0x163c3
callq 0x42f0
movq -0x340(%rbp), %rsi
movq %rax, -0x3d8(%rbp)
movl -0x1d4(%rbp), %ecx
decl %ecx
leaq -0x318(%rbp), %rdi
movq %rdi, -0x3d0(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8330
movq -0x3d8(%rbp), %rdi
movq -0x3d0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x3c8(%rbp)
jmp 0x940f
movq -0x3c8(%rbp), %rdi
leaq 0xcf13(%rip), %rsi      # 0x16330
callq 0x42f0
movq %rax, -0x3e0(%rbp)
jmp 0x942b
movq -0x340(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x1d8(%rbp), %ecx
decl %ecx
leaq -0x338(%rbp), %rdi
callq 0x8330
jmp 0x944b
movq -0x3e0(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x42c0
movq %rax, -0x3e8(%rbp)
jmp 0x9467
movq -0x3e8(%rbp), %rdi
movq 0x15b3b(%rip), %rsi     # 0x1efb0
callq 0x4320
jmp 0x947c
leaq -0x338(%rbp), %rdi
callq 0x45d8
leaq -0x318(%rbp), %rdi
callq 0x45d8
jmp 0x916c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x94f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x94e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x94db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0xc680
leaq -0x2f8(%rbp), %rdi
callq 0x45d8
leaq -0x290(%rbp), %rdi
callq 0xc680
leaq -0x2b0(%rbp), %rdi
callq 0x45d8
jmp 0x956f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9527
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x45d8
leaq -0x318(%rbp), %rdi
callq 0x45d8
jmp 0x956f
jmp 0x9564
movq 0x15a62(%rip), %rdi     # 0x1efa0
leaq 0xce86(%rip), %rsi      # 0x163cb
callq 0x42f0
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x4510
movq %rax, %rdi
movq 0x15a51(%rip), %rsi     # 0x1efb0
callq 0x4320
jmp 0x9566
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x4530
nopl (%rax,%rax)