// File: /workspace/github_cpp_makefile_star2_O3/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 0xe280
movq (%rax), %rsi
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0xcf10
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 0xac51
movq (%r14), %rax
movq (%rax), %rdi
callq 0x6866
movq %rax, %r15
movq 0x40(%rsp), %rax
movq (%rax), %rdi
callq 0x6866
cmpq %rax, %r15
jae 0xac36
xorl %r15d, %r15d
jmp 0xac89
leal -0x1(%rbp), %ecx
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xa254
movl %eax, %r15d
incl %r15d
movq %r15, %r12
testq %r12, %r12
jle 0xac89
movq %r14, 0x58(%rsp)
movl $0x1, %r14d
xorl %esi, %esi
leaq 0x20(%rsp), %r13
shlq $0x4, %rsi
addq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0xcdc6
movl %r14d, %esi
incl %r14d
cmpq %rsi, %r12
ja 0xac68
movq 0x58(%rsp), %r14
movq (%r14), %r12
movq 0x8(%r14), %r13
cmpq %r13, %r12
je 0xacae
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0xcdc6
addq $0x10, %r12
cmpq %r13, %r12
jne 0xac9a
subl %r15d, %ebp
jbe 0xacd7
movl %r15d, %r15d
shlq $0x4, %r15
leaq 0x20(%rsp), %r14
movq 0x40(%rsp), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0xcdc6
addq $0x10, %r15
decl %ebp
jne 0xacbf
leaq 0x18(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x10(%rsp), %rsi
leaq 0xf(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0xe356
leaq 0x60(%rsp), %rsi
movq %rbx, %rdi
callq 0xe280
movaps 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0x8(%rax), %rdi
movups %xmm0, (%rax)
testq %rdi, %rdi
je 0xad23
callq 0x7c76
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xad32
callq 0x7c76
leaq 0x20(%rsp), %rdi
callq 0xce64
leaq 0x40(%rsp), %rdi
callq 0xce64
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xad71
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xad74
callq 0x7c76
jmp 0xad74
jmp 0xad71
jmp 0xad71
jmp 0xad71
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xce64
leaq 0x40(%rsp), %rdi
callq 0xce64
movq %rbx, %rdi
callq 0x3460