// File: reddragon[P]packed-memory-array/impl2.cpp
// Function: PMA::insert_merge(int, int)
void
    insert_merge(int l, int v) {
        dprintf("insert_merge(%d, %d)\n", l, v);
        // Insert by merging elements in a window of size 'chunk_size'
        tmp.clear();
        tmp.reserve(this->chunk_size);
        for (int i = l; i < l + this->chunk_size; ++i) {
            if (this->present[i]) {
                this->present[i] = false;
                tmp.push_back(this->impl[i]);
            }
        }
        vi_t::iterator iter = std::lower_bound(tmp.begin(), tmp.end(), v);
        tmp.insert(iter, v);

        dprintf("insert_merge::tmp.size(): %d\n", tmp.size());
        for (int i = 0; i < tmp.size(); ++i) {
            this->present[l + i] = true;
            this->impl[l + i] = tmp[i];
        }
        ++this->nelems;
        nmoves += chunk_size;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x80(%rbp)
addq $0x58, %rdi
callq 0x2850
movq -0x80(%rbp), %rax
movq %rax, %rdi
addq $0x58, %rdi
movslq 0x48(%rax), %rsi
callq 0x2870
movl -0xc(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x80(%rbp), %rdx
movl -0x14(%rbp), %eax
movl -0xc(%rbp), %ecx
addl 0x48(%rdx), %ecx
cmpl %ecx, %eax
jge 0x1dbb
movq -0x80(%rbp), %rdi
addq $0x20, %rdi
movslq -0x14(%rbp), %rsi
callq 0x1b70
movq %rax, -0x28(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1bd0
testb $0x1, %al
jne 0x1d5d
jmp 0x1dab
movq -0x80(%rbp), %rdi
addq $0x20, %rdi
movslq -0x14(%rbp), %rsi
callq 0x1b70
movq %rax, -0x38(%rbp)
movq %rdx, -0x30(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x2970
movq -0x80(%rbp), %rdi
movq %rdi, %rax
addq $0x58, %rax
movq %rax, -0x88(%rbp)
movslq -0x14(%rbp), %rsi
callq 0x2530
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x29c0
jmp 0x1dad
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d20
movq -0x80(%rbp), %rdi
addq $0x58, %rdi
callq 0x2a80
movq -0x80(%rbp), %rdi
movq %rax, -0x48(%rbp)
addq $0x58, %rdi
callq 0x2ab0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0x2a30
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, -0x40(%rbp)
addq $0x58, %rax
movq %rax, -0x90(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2ce0
movq -0x90(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0x2ae0
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x80(%rbp), %rdi
movslq -0x64(%rbp), %rax
movq %rax, -0x98(%rbp)
addq $0x58, %rdi
callq 0x1a90
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x1ec4
movq -0x80(%rbp), %rdi
addq $0x20, %rdi
movl -0xc(%rbp), %eax
addl -0x64(%rbp), %eax
movslq %eax, %rsi
callq 0x1b70
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x2970
movq -0x80(%rbp), %rdi
addq $0x58, %rdi
movslq -0x64(%rbp), %rsi
callq 0x2530
movq -0x80(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
movl -0xc(%rbp), %eax
addl -0x64(%rbp), %eax
movslq %eax, %rsi
callq 0x2530
movl -0x9c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1e30
movq -0x80(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movslq 0x48(%rax), %rax
addq 0x91f4(%rip), %rax      # 0xb0d0
movq %rax, 0x91ed(%rip)      # 0xb0d0
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)