// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x60(%rsp), %rsi
movq %r8, (%rsi)
addq $0x20, %rbx
movq %rbx, %rdi
callq 0xe3ca
movq (%rax), %rsi
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0xcfe4
movq 0x8(%r13), %rbp
subq (%r13), %rbp
shrq $0x4, %rbp
xorl %eax, %eax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
testl %ebp, %ebp
cmoveq %rax, %r15
cmoveq %rax, %r12
movaps %xmm0, 0x20(%rsp)
movq %r12, %rax
andq %r15, %rax
cmpq $-0x1, %rax
jne 0xadbc
movq (%r14), %rax
movq (%rax), %rdi
callq 0x6910
movq %rax, %r15
movq 0x40(%rsp), %rax
movq (%rax), %rdi
callq 0x6910
cmpq %rax, %r15
jae 0xada1
xorl %r15d, %r15d
xorl %r12d, %r12d
jmp 0xadbc
leal -0x1(%rbp), %ecx
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xa3fa
movl %eax, %r15d
incl %r15d
movq %r15, %r12
movq %rbx, 0x58(%rsp)
testq %r12, %r12
jle 0xadec
movl $0x1, %ebx
xorl %esi, %esi
leaq 0x20(%rsp), %r13
shlq $0x4, %rsi
addq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0xcea8
movl %ebx, %esi
incl %ebx
cmpq %rsi, %r12
jg 0xadd2
movq (%r14), %r12
movq 0x8(%r14), %rbx
cmpq %rbx, %r12
je 0xae11
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0xcea8
addq $0x10, %r12
cmpq %rbx, %r12
jne 0xadfd
cmpl %ebp, %r15d
jae 0xae43
movl %r15d, %r15d
movl %ebp, %eax
movq %r15, %rbx
shlq $0x4, %rbx
subq %rax, %r15
leaq 0x20(%rsp), %r14
movq 0x40(%rsp), %rsi
addq %rbx, %rsi
movq %r14, %rdi
callq 0xcea8
addq $0x10, %rbx
incq %r15
jne 0xae2a
leaq 0x18(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x10(%rsp), %rsi
leaq 0xf(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0xe48c
leaq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0xe3ca
movaps 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0x8(%rax), %rdi
movups %xmm0, (%rax)
testq %rdi, %rdi
je 0xae91
callq 0x7d9e
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xaea0
callq 0x7d9e
leaq 0x20(%rsp), %rdi
callq 0xcf40
leaq 0x40(%rsp), %rdi
callq 0xcf40
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaedf
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xaee2
callq 0x7d9e
jmp 0xaee2
jmp 0xaedf
jmp 0xaedf
jmp 0xaedf
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xcf40
leaq 0x40(%rsp), %rdi
callq 0xcf40
movq %rbx, %rdi
callq 0x3460