// File: /workspace/github_cpp_makefile_star2_O2/xx01cyx[P]LSM-Tree/kvstore.cc
// Function: KVStore::reconstructLowerLevelMemory(long, long, std::vector<std::shared_ptr<SSTable>, std::allocator<std::shared_ptr<SSTable>>> const&, unsigned long)
void KVStore::reconstructLowerLevelMemory(int64_t minOverlapIndex, int64_t maxOverlapIndex,
                                          const vector<SSTPtr>& newSSTs, size_t lowerLevel) {

    vector<SSTPtr> previousSSTs = *ssTables[lowerLevel];
    uint32_t length = previousSSTs.size();
    vector<SSTPtr> updatedSSTs;

    if (length == 0)
        minOverlapIndex = maxOverlapIndex = 0;

    // If no overlapping, binary search for the insert position.
    if (minOverlapIndex == -1 && maxOverlapIndex == -1) {
        LsmKey insertMinKey = newSSTs.front()->getMinKey();
        if (insertMinKey < previousSSTs.front()->getMinKey())
            minOverlapIndex = maxOverlapIndex = 0;
        else
            minOverlapIndex = maxOverlapIndex =
                    sstBinarySearch(previousSSTs, insertMinKey, 0, length - 1) + 1;
    }

    // Old SSTs left to the overlapping SSTs.
    for (uint32_t i = 0; i < minOverlapIndex; ++i)
        updatedSSTs.push_back(previousSSTs[i]);

    // New SSTs that need insert into the level.
    for (const auto& newSST : newSSTs)
        updatedSSTs.push_back(newSST);

    // Old SSTs right to the overlapping SSTs.
    for (uint32_t i = maxOverlapIndex; i < length; ++i)
        updatedSSTs.push_back(previousSSTs[i]);

    // Save the new layer in the memory.
    ssTables[lowerLevel] = make_shared<vector<SSTPtr>>(updatedSSTs);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x50(%rsp), %rsi
movq %r8, (%rsi)
addq $0x20, %rbx
movq %rbx, %rdi
callq 0xbc36
movq (%rax), %rsi
leaq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0xa5bc
movq 0x8(%r13), %rbp
subq (%r13), %rbp
andq $0x0, 0x20(%rsp)
shrq $0x4, %rbp
xorps %xmm0, %xmm0
xorl %r14d, %r14d
testl %ebp, %ebp
cmoveq %r14, %r15
cmoveq %r14, %r12
movaps %xmm0, 0x10(%rsp)
movq %r12, %rax
andq %r15, %rax
cmpq $-0x1, %rax
jne 0x8eab
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x57f8
movq %rax, %r15
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x57f8
cmpq %rax, %r15
jae 0x8e90
xorl %r15d, %r15d
xorl %r12d, %r12d
jmp 0x8eab
leal -0x1(%rbp), %ecx
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x85e2
movl %eax, %r15d
incl %r15d
movq %r15, %r12
leaq 0x10(%rsp), %r13
movl %r14d, %r14d
cmpq %r14, %r12
jle 0x8ed1
movq %r14, %rsi
shlq $0x4, %rsi
addq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0xa4a8
incl %r14d
jmp 0x8eb0
movq 0x8(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %r13
leaq 0x10(%rsp), %r14
cmpq %r13, %r12
je 0x8ef8
movq %r14, %rdi
movq %r12, %rsi
callq 0xa4a8
addq $0x10, %r12
jmp 0x8ee2
movl %r15d, %r15d
movl %ebp, %r12d
movq %r15, %r13
shlq $0x4, %r13
leaq 0x10(%rsp), %r14
cmpq %r12, %r15
jae 0x8f28
movq 0x28(%rsp), %rsi
addq %r13, %rsi
movq %r14, %rdi
callq 0xa4a8
incq %r15
addq $0x10, %r13
jmp 0x8f0a
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xa52c
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0xbc36
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0xb188
leaq 0x48(%rsp), %rdi
callq 0x6932
leaq 0x10(%rsp), %rdi
callq 0xa552
leaq 0x28(%rsp), %rdi
callq 0xa552
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8f95
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x6932
jmp 0x8f98
jmp 0x8f95
jmp 0x8f95
jmp 0x8f95
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xa552
leaq 0x28(%rsp), %rdi
callq 0xa552
movq %rbx, %rdi
callq 0x3440