// File: xx01cyx[P]LSM-Tree/kvstore.cc
// Function: KVStore::compactOneSST(std::shared_ptr<SSTable> const&, unsigned long)
void KVStore::compactOneSST(const SSTPtr& sst, size_t lowerLevel) {

    int64_t minOverlapIndex = -1;
    int64_t maxOverlapIndex = -1;
    vector<SSTPtr> overlapSSTs = getOverlapSSTs(sst->getMinKey(), sst->getMaxKey(), lowerLevel,
                                                minOverlapIndex, maxOverlapIndex);

    KVPair data = getCompactionData(sst, overlapSSTs);

    reconstructLowerLevelDisk(minOverlapIndex, maxOverlapIndex, lowerLevel);

    TimeStamp maxTimeStamp = getMaxTimeStamp(sst, overlapSSTs);
    vector<SSTPtr> mergedSSTs;

    if (overlapSSTs.empty())                 // no overlapping
        mergedSSTs.push_back(generateNewSST(sst->getKeys(), data, lowerLevel, maxTimeStamp));
    else                                     // does overlap
        mergedSSTs = mergeAndWriteToDisk(sst, overlapSSTs, maxTimeStamp, data);

    reconstructLowerLevelMemory(minOverlapIndex, maxOverlapIndex, mergedSSTs, lowerLevel);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq $-0x1, -0x20(%rbp)
movq $-0x1, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd330
movq %rax, %rdi
callq 0x98e0
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd330
movq %rax, %rdi
callq 0x9900
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
movq %rsp, %rax
leaq -0x28(%rbp), %rdi
movq %rdi, (%rax)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
leaq -0x20(%rbp), %r9
callq 0x12400
movq -0xf0(%rbp), %rdx
movq -0x10(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x13850
jmp 0x13424
movq -0x100(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x127c0
jmp 0x1343e
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x138d0
movq %rax, -0x108(%rbp)
jmp 0x13454
movq -0x108(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x15ef0
leaq -0x40(%rbp), %rdi
callq 0x160e0
testb $0x1, %al
jne 0x13480
jmp 0x13569
movq -0x10(%rbp), %rdi
callq 0xd330
movq %rax, %rsi
leaq -0xd0(%rbp), %rdi
callq 0x9970
jmp 0x1349a
movq -0x18(%rbp), %rcx
movq -0x90(%rbp), %r8
leaq -0xb8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x13980
jmp 0x134be
leaq -0xa8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x168d0
jmp 0x134d3
leaq -0xb8(%rbp), %rdi
callq 0xd350
leaq -0xd0(%rbp), %rdi
callq 0x69d0
jmp 0x135b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x1360d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x13604
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x135f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x13558
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xd350
leaq -0xd0(%rbp), %rdi
callq 0x69d0
jmp 0x135f8
movq -0x100(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x90(%rbp), %r8
leaq -0xe8(%rbp), %rdi
leaq -0x40(%rbp), %rcx
leaq -0x78(%rbp), %r9
callq 0x14230
jmp 0x13591
leaq -0xa8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x16900
leaq -0xe8(%rbp), %rdi
callq 0x163c0
movq -0x100(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %r8
leaq -0xa8(%rbp), %rcx
callq 0x12e70
jmp 0x135d1
leaq -0xa8(%rbp), %rdi
callq 0x163c0
leaq -0x78(%rbp), %rdi
callq 0x168b0
leaq -0x40(%rbp), %rdi
callq 0x163c0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0xa8(%rbp), %rdi
callq 0x163c0
leaq -0x78(%rbp), %rdi
callq 0x168b0
leaq -0x40(%rbp), %rdi
callq 0x163c0
movq -0x80(%rbp), %rdi
callq 0x4560
nop