// File: xx01cyx[P]LSM-Tree/kvstore.cc
// Function: KVStore::readAllSSTsFromDisk()
void KVStore::readAllSSTsFromDisk() {
    size_t level = 0;
    string levelDir = "./data/level-" + to_string(level) + "/";
    vector<string> filenames;
    bool emptyL0;

    while (utils::dirExists(levelDir)) {
        utils::scanDir(levelDir, filenames);
        vector<SSTPtr> levelSSTs;
        for (const auto& filename : filenames) {
            string sstName = levelDir + filename;
            SSTPtr sst = readSSTFromDisk(sstName, level);
            levelSSTs.push_back(sst);
        }

        if (level == 0) {
            if (levelSSTs.empty())
                emptyL0 = true;
            else if (levelSSTs.size() == 1)
                timeStamp = levelSSTs.front()->getTimeStamp() + 1;
            else {
                SSTTimeStampPriorComparator timeStampLessThan;
                SSTPtr firstSST = levelSSTs[0];
                SSTPtr secondSST = levelSSTs[1];
                timeStamp = timeStampLessThan(firstSST, secondSST) ?
                            secondSST->getTimeStamp() + 1 : firstSST->getTimeStamp() + 1;
            }
        } else {
            if (level == 1 && emptyL0)
                timeStamp = getMaxTimeStamp(levelSSTs) + 1;
            SSTKeyPriorComparator sstComparator;
            sort(levelSSTs.begin(), levelSSTs.end(), sstComparator);
        }
        ssTables[level] = make_shared<vector<SSTPtr>>(levelSSTs);

        ++level;
        levelDir = "./data/level-" + to_string(level) + "/";
        filenames.clear();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x210(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x9ed0
movq -0x208(%rbp), %rdx
leaq 0x12f2a(%rip), %rsi     # 0x231ae
leaq -0x50(%rbp), %rdi
callq 0x9e80
jmp 0x1028f
leaq 0x1301c(%rip), %rdx     # 0x232b2
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x9d60
jmp 0x102a5
leaq -0x50(%rbp), %rdi
callq 0x4608
leaq -0x70(%rbp), %rdi
callq 0x4608
leaq -0x98(%rbp), %rdi
callq 0x15ed0
leaq -0xc0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4120
jmp 0x102d5
leaq -0xc0(%rbp), %rdi
callq 0xff30
movb %al, -0x211(%rbp)
jmp 0x102e9
leaq -0xc0(%rbp), %rdi
callq 0x4608
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x10304
jmp 0x10867
leaq -0xe0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4120
jmp 0x10316
leaq -0xe0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x115d0
jmp 0x1032b
leaq -0xe0(%rbp), %rdi
callq 0x4608
leaq -0xf8(%rbp), %rdi
callq 0x15ef0
leaq -0x98(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
callq 0x15f10
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
callq 0x15f40
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x15f70
testb $0x1, %al
jne 0x10393
jmp 0x104da
leaq -0x108(%rbp), %rdi
callq 0x15fb0
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x15fd0
jmp 0x103bf
movq -0x10(%rbp), %rdx
leaq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x11710
jmp 0x103d8
leaq -0xf8(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x16050
jmp 0x103ed
leaq -0x148(%rbp), %rdi
callq 0xd350
leaq -0x138(%rbp), %rdi
callq 0x4608
leaq -0x108(%rbp), %rdi
callq 0x160c0
jmp 0x10377
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x10439
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4608
leaq -0x70(%rbp), %rdi
callq 0x4608
jmp 0x1089a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x10885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x4608
jmp 0x10885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x4608
jmp 0x10885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x10859
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x104c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xd350
leaq -0x138(%rbp), %rdi
callq 0x4608
jmp 0x10859
cmpq $0x0, -0x10(%rbp)
jne 0x10690
leaq -0xf8(%rbp), %rdi
callq 0x160e0
testb $0x1, %al
jne 0x104f7
jmp 0x10503
movb $0x1, -0x99(%rbp)
jmp 0x1068e
leaq -0xf8(%rbp), %rdi
callq 0x16120
cmpq $0x1, %rax
jne 0x10555
leaq -0xf8(%rbp), %rdi
callq 0x16140
movq %rax, %rdi
callq 0xd330
movq %rax, %rdi
callq 0x98c0
movq %rax, -0x220(%rbp)
jmp 0x1053a
movq -0x210(%rbp), %rax
movq -0x220(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, 0x58(%rax)
jmp 0x1068c
xorl %eax, %eax
movl %eax, %esi
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x16170
movq %rax, %rsi
leaq -0x160(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x16190
movq -0x240(%rbp), %rdi
movl $0x1, %esi
callq 0x16170
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x16190
movq -0x238(%rbp), %rsi
movq -0x230(%rbp), %rdx
leaq -0x149(%rbp), %rdi
callq 0x161c0
movb %al, -0x221(%rbp)
jmp 0x105cb
movb -0x221(%rbp), %al
testb $0x1, %al
jne 0x105d7
jmp 0x10608
leaq -0x170(%rbp), %rdi
callq 0xd330
movq %rax, %rdi
callq 0x98c0
movq %rax, -0x248(%rbp)
jmp 0x105f4
movq -0x248(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x250(%rbp)
jmp 0x10637
leaq -0x160(%rbp), %rdi
callq 0xd330
movq %rax, %rdi
callq 0x98c0
movq %rax, -0x258(%rbp)
jmp 0x10625
movq -0x258(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x250(%rbp)
movq -0x210(%rbp), %rax
movq -0x250(%rbp), %rcx
movq %rcx, 0x58(%rax)
leaq -0x170(%rbp), %rdi
callq 0xd350
leaq -0x160(%rbp), %rdi
callq 0xd350
jmp 0x1068c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xd350
leaq -0x160(%rbp), %rdi
callq 0xd350
jmp 0x10859
jmp 0x1068e
jmp 0x1070f
cmpq $0x1, -0x10(%rbp)
jne 0x106cb
testb $0x1, -0x99(%rbp)
je 0x106cb
leaq -0xf8(%rbp), %rdi
callq 0x119d0
movq %rax, -0x260(%rbp)
jmp 0x106b5
movq -0x210(%rbp), %rax
movq -0x260(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, 0x58(%rax)
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x162a0
movq -0x268(%rbp), %rdi
movq %rax, -0x180(%rbp)
callq 0x162d0
movq %rax, -0x188(%rbp)
movq -0x180(%rbp), %rdi
movq -0x188(%rbp), %rsi
callq 0x16260
jmp 0x1070d
jmp 0x1070f
leaq -0x1a0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x16300
jmp 0x10724
movq -0x210(%rbp), %rdi
addq $0x20, %rdi
leaq -0x10(%rbp), %rsi
callq 0x16370
movq %rax, -0x270(%rbp)
jmp 0x10741
movq -0x270(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movq %rsi, -0x278(%rbp)
callq 0x15e10
movq -0x278(%rbp), %rdi
callq 0x15e40
movq -0x10(%rbp), %rax
incq %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x200(%rbp), %rdi
callq 0x9ed0
jmp 0x10784
leaq 0x12a23(%rip), %rsi     # 0x231ae
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rdx
callq 0x9e80
jmp 0x107a0
leaq 0x12b0b(%rip), %rdx     # 0x232b2
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x9d60
jmp 0x107bc
leaq -0x30(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x4370
leaq -0x1c0(%rbp), %rdi
callq 0x4608
leaq -0x1e0(%rbp), %rdi
callq 0x4608
leaq -0x200(%rbp), %rdi
callq 0x4608
leaq -0x98(%rbp), %rdi
callq 0x163a0
leaq -0xf8(%rbp), %rdi
callq 0x163c0
jmp 0x102c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x15e40
jmp 0x10859
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x1084d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x4608
leaq -0x200(%rbp), %rdi
callq 0x4608
leaq -0xf8(%rbp), %rdi
callq 0x163c0
jmp 0x10885
leaq -0x98(%rbp), %rdi
callq 0x16420
leaq -0x30(%rbp), %rdi
callq 0x4608
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x16420
leaq -0x30(%rbp), %rdi
callq 0x4608
movq -0x78(%rbp), %rdi
callq 0x4560
nopw %cs:(%rax,%rax)