// File: /workspace/github_cpp_makefile_star2_O3/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 0xd658
movq (%rax), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0xcf10
movq 0x8(%r15), %rax
subq (%r15), %rax
cmpq $0x30, %rax
jne 0xa0ba
leaq 0x70(%rsp), %rsi
movq $0x1, (%rsi)
movq %r14, %rdi
callq 0xe516
testq %rax, %rax
jne 0x9f8f
movl $0x28, %edi
callq 0x3270
movq %rax, %r15
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r15)
leaq 0xbe04(%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 0xd658
movq %r15, %rcx
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x8(%rax), %rdi
movq %r15, 0x8(%rax)
testq %rdi, %rdi
je 0x9f8f
callq 0x7c76
leaq 0x38(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0xa2f4
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 0xa3de
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
callq 0xe572
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa534
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
movl $0x1, %ecx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xa630
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rbp
xorl %r12d, %r12d
cmpq %rbp, %r13
je 0xa045
movq (%r13), %rdi
callq 0x6860
cmpq %r12, %rax
cmovaq %rax, %r12
addq $0x10, %r13
jmp 0xa02a
leaq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rdx
leaq 0x70(%rsp), %r8
movq %rbx, %rsi
movq %r12, %rcx
callq 0xa6b4
leaq 0x58(%rsp), %rcx
movl $0x1, %r8d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xaba2
movq %rbx, %rdi
callq 0xad90
leaq 0x58(%rsp), %rdi
callq 0xce64
leaq 0x70(%rsp), %rdi
callq 0xd4ca
leaq 0x40(%rsp), %rdi
callq 0xce64
leaq 0x8(%rsp), %rdi
callq 0xce64
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbf2f(%rip), %rdi      # 0x15ff0
leaq 0x6338(%rip), %rsi      # 0x10400
movl $0x33, %edx
callq 0x32b0
movq 0xbf17(%rip), %rdi      # 0x15ff0
callq 0x3140
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x32d0
movq %rax, %rbx
movq %r15, %rdi
callq 0x7c76
jmp 0xa133
jmp 0xa108
jmp 0xa108
jmp 0xa11c
jmp 0xa11c
jmp 0xa0ff
movq %rax, %rbx
jmp 0xa129
jmp 0xa108
jmp 0xa108
movq %rax, %rbx
jmp 0xa133
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xce64
jmp 0xa11f
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xd4ca
leaq 0x40(%rsp), %rdi
callq 0xce64
leaq 0x8(%rsp), %rdi
callq 0xce64
movq %rbx, %rdi
callq 0x3460
nop