// File: /workspace/github_cpp_makefile_star2_O1/xx01cyx[P]LSM-Tree/kvstore.cc
// Function: KVStore::compact0()
void KVStore::compact0() {

    vector<SSTPtr> SSTs = *ssTables[0];
    if (SSTs.size() != 3) {
        cerr << "Number of SSTs in L0 is not 3. L0-compaction error." << endl;
        exit(-1);
    }

    if (!ssTables.count(1))
        ssTables[1] = make_shared<vector<SSTPtr>>();

    // Get the overall interval of SSTs in L0.
    LsmKey minKey, maxKey;
    getCompact0Range(minKey, maxKey);

    // Get all the SSTs in L0 and L1 that need merge.
    int64_t minOverlapIndex = -1;
    int64_t maxOverlapIndex = -1;
    vector<SSTPtr> overlapSSTs = getOverlapSSTs(minKey, maxKey, 1,
                                                minOverlapIndex, maxOverlapIndex);

    // Get all k-v pairs from the disk.
    SSTs.insert(SSTs.end(), overlapSSTs.begin(), overlapSSTs.end());
    KVPair data = getCompactionData(SSTs);

    // Remove the overlapping SST files in the disk.
    reconstructLowerLevelDisk( minOverlapIndex, maxOverlapIndex, 1);

    // Sort the keys and write the data into the disk.
    TimeStamp maxTimeStamp = getMaxTimeStamp(SSTs);
    vector<SSTPtr> mergedSSTs = merge0AndWriteToDisk(SSTs, maxTimeStamp, data);

    // Reconstruct L1 in memory.
    reconstructLowerLevelMemory(minOverlapIndex, maxOverlapIndex, mergedSSTs, 1);

    // Clear L0 in memory and delete corresponding files in the disk.
    reconstructL0();

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
leaq 0x20(%rdi), %r14
leaq 0x70(%rsp), %rsi
movq $0x0, (%rsi)
movq %r14, %rdi
callq 0xd740
movq (%rax), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0xcfe4
movq 0x8(%r15), %rax
subq (%r15), %rax
cmpq $0x30, %rax
jne 0xa260
leaq 0x70(%rsp), %rsi
movq $0x1, (%rsi)
movq %r14, %rdi
callq 0xe64c
testq %rax, %rax
jne 0xa135
movl $0x28, %edi
callq 0x3270
movq %rax, %r15
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r15)
leaq 0xbc5e(%rip), %rax      # 0x15d50
movq %rax, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r15)
movq $0x0, 0x20(%r15)
leaq 0x70(%rsp), %rsi
movq $0x1, (%rsi)
movq %r14, %rdi
callq 0xd740
movq %r15, %rcx
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x8(%rax), %rdi
movq %r15, 0x8(%rax)
testq %rdi, %rdi
je 0xa135
callq 0x7d9e
leaq 0x38(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0xa486
movq $-0x1, %rax
leaq 0x28(%rsp), %r9
movq %rax, (%r9)
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq %rsi, (%rsp)
leaq 0x40(%rsp), %rdi
movl $0x1, %r8d
movq %rbx, %rsi
callq 0xa570
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
callq 0xe680
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa6c4
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
movl $0x1, %ecx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xa7c0
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rbp
xorl %r12d, %r12d
cmpq %rbp, %r13
je 0xa1eb
movq (%r13), %rdi
callq 0x690a
cmpq %r12, %rax
cmovaq %rax, %r12
addq $0x10, %r13
jmp 0xa1d0
leaq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rdx
leaq 0x70(%rsp), %r8
movq %rbx, %rsi
movq %r12, %rcx
callq 0xa844
leaq 0x58(%rsp), %rcx
movl $0x1, %r8d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xad0a
movq %rbx, %rdi
callq 0xaefe
leaq 0x58(%rsp), %rdi
callq 0xcf40
leaq 0x70(%rsp), %rdi
callq 0xd5b2
leaq 0x40(%rsp), %rdi
callq 0xcf40
leaq 0x8(%rsp), %rdi
callq 0xcf40
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbd89(%rip), %rdi      # 0x15ff0
leaq 0x6162(%rip), %rsi      # 0x103d0
movl $0x33, %edx
callq 0x32b0
movq 0xbd71(%rip), %rdi      # 0x15ff0
callq 0x3140
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x32d0
movq %rax, %rbx
movq %r15, %rdi
callq 0x7d9e
jmp 0xa2d9
jmp 0xa2ae
jmp 0xa2ae
jmp 0xa2c2
jmp 0xa2c2
jmp 0xa2a5
movq %rax, %rbx
jmp 0xa2cf
jmp 0xa2ae
jmp 0xa2ae
movq %rax, %rbx
jmp 0xa2d9
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xcf40
jmp 0xa2c5
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xd5b2
leaq 0x40(%rsp), %rdi
callq 0xcf40
leaq 0x8(%rsp), %rdi
callq 0xcf40
movq %rbx, %rdi
callq 0x3460
nop