// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %rbx
movl %edx, 0x14(%rsp)
leaq 0x58(%rdi), %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rdi), %rax
cmpq %rax, 0x60(%rdi)
je 0x1a05
movq %rax, 0x60(%rbx)
movslq 0x48(%rbx), %rsi
movq 0x8(%rsp), %rdi
callq 0x2160
cmpl $0x0, 0x48(%rbx)
movslq %r15d, %r13
jle 0x1ad0
leaq (,%r13,4), %r14
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
leaq 0x3f(%rax), %r12
movq %r13, %r15
leal 0x3f(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x20(%rbx), %rax
movq %r15, %rcx
andq %r12, %rcx
xorl %edx, %edx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
cmpq %rsi, %rcx
setbe %dl
movl $0x1, %esi
movl %r15d, %ecx
shlq %cl, %rsi
movq -0x8(%rax,%rdx,8), %rcx
btq %r15, %rcx
jae 0x1ab9
leaq -0x8(,%rdx,8), %rdx
notq %rsi
andq %rsi, %rcx
movq %rcx, (%rax,%rdx)
movq (%rbx), %rdx
addq %r14, %rdx
movq 0x60(%rbx), %rsi
cmpq 0x68(%rbx), %rsi
je 0x1aaf
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rbx)
jmp 0x1ab9
movq 0x8(%rsp), %rdi
callq 0x2292
incq %r15
movslq 0x48(%rbx), %rax
addq %r13, %rax
addq $0x4, %r14
cmpq %rax, %r15
jl 0x1a39
movq 0x58(%rbx), %rsi
movq 0x60(%rbx), %rax
subq %rsi, %rax
sarq $0x2, %rax
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
testq %rax, %rax
jle 0x1b18
movq %rax, %rcx
shrq %rcx
movq %rcx, %rdx
notq %rdx
addq %rax, %rdx
leaq (%rsi,%rcx,4), %rax
addq $0x4, %rax
cmpl %ebp, -0x4(%rax)
cmovlq %rax, %rsi
cmovgeq %rcx, %rdx
movq %rdx, %rax
testq %rdx, %rdx
jg 0x1aee
leaq 0x14(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x21fc
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rdx
subq %rax, %rdx
je 0x1ba5
sarq $0x2, %rdx
movq 0x20(%rbx), %rsi
cmpq $0x1, %rdx
adcq $0x0, %rdx
movl %r13d, %edi
leaq (,%r13,4), %r8
addq (%rbx), %r8
xorl %r9d, %r9d
leaq 0x3f(%r12), %r10
leaq (%r9,%r13), %rcx
movl %edi, %r11d
addl %r9d, %r11d
leal 0x3f(%rdi,%r9), %ebp
cmovnsl %r11d, %ebp
sarl $0x6, %ebp
movslq %ebp, %r11
movq %rcx, %r14
andq %r10, %r14
xorl %r15d, %r15d
cmpq %r12, %r14
setbe %r15b
movl $0x1, %r14d
shlq %cl, %r14
leaq (%rsi,%r11,8), %rcx
orq %r14, -0x8(%rcx,%r15,8)
movl (%rax,%r9,4), %ecx
movl %ecx, (%r8,%r9,4)
incq %r9
cmpq %r9, %rdx
jne 0x1b5a
incl 0x18(%rbx)
movslq 0x48(%rbx), %rax
addq %rax, 0x350d(%rip)      # 0x50c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq