// File: /workspace/github_cpp_makefile_star2_O3/reddragon[P]packed-memory-array/impl2.cpp
// Function: PMA::insert(int)
void
    insert(int v) {
        /*
        if ((this->nelems + 2) * 2 > this->impl.size()) {
            // resize array
            this->resize(2 * this->impl.size());
        }
        */

        int i = lower_bound(v);
        if (i == this->impl.size()) {
            --i;
        }
        assert(i > -1);
        assert(i < this->impl.size());

        // Check in a window of size 'w'
        int w = chunk_size;
        int level = 0;
        int l = this->left_interval_boundary(i, w);

        // Number of elements in current window. We just need sz to be
        // less than w -- we don't need the exact value of 'sz' here.
        int sz = w - 1;

        bool in_limit = false;

        // If the current chunk has space, then the last element will
        // be unused (with significant probability). First check that
        // as a quick check.
        if (this->present[l + this->chunk_size - 1]) {
            get_interval_stats(l, level, in_limit, sz);
        }

        if (sz < w) {
            // There is some space in this interval. We can just
            // shuffle elements and insert.
            this->insert_merge(l, v);
        } else {
            // No space in this interval. Find an interval above this
            // interval that is within limits, re-balance, and
            // re-start insertion.
            in_limit = false;
            while (!in_limit) {
                w *= 2;
                level += 1;
                // assert(level <= this->nlevels);
                if (level > this->nlevels) {
                    // Root node is out of balance. Resize array.
                    this->resize(2 * this->impl.size());
                    this->insert(v);
                    return;
                }

                l = this->left_interval_boundary(i, w);
                get_interval_stats(l, level, in_limit, sz);
                dprintf("level: %d, this->nlevels: %d, in_limit: %d, sz: %d\n", level, this->nlevels, in_limit, sz);
            }
            this->rebalance_interval(l, level);
            this->insert(v);
        }

    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq %rdi, %r14
callq 0x1802
movslq %eax, %r15
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x2, %rax
xorl %ecx, %ecx
cmpq %r15, %rax
sete %cl
subl %ecx, %r15d
js 0x1608
movl %r15d, %ecx
cmpq %rcx, %rax
jbe 0x1627
movl 0x48(%r14), %r12d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x189c
movl %eax, %r13d
leal -0x1(%r12), %eax
movl %eax, 0x14(%rsp)
movb $0x0, 0xf(%rsp)
movl 0x48(%r14), %eax
leal (%rax,%r13), %ecx
decl %ecx
movslq %ecx, %rcx
addl %r13d, %eax
addl $0x3e, %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x20(%r14), %rax
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x3f(%rdx), %rsi
andq %rcx, %rsi
xorl %edi, %edi
cmpq %rdx, %rsi
setbe %dil
movq -0x8(%rax,%rdi,8), %rax
btq %rcx, %rax
jae 0x157b
xorl %ebp, %ebp
leaq 0xf(%rsp), %rcx
movl %ebx, 0x10(%rsp)
leaq 0x14(%rsp), %rbx
movq %r14, %rdi
movl %r13d, %esi
xorl %edx, %edx
movq %rbx, %r8
callq 0x1920
cmpl %r12d, (%rbx)
movl 0x10(%rsp), %ebx
jge 0x158a
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x19d4
jmp 0x15f9
leaq 0xf(%rsp), %r13
movb $0x0, (%r13)
cmpl 0x50(%r14), %ebp
jge 0x15d8
incl %ebp
addl %r12d, %r12d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x189c
movl %eax, %ebx
movq %r14, %rdi
movl %eax, %esi
movl %ebp, %edx
movq %r13, %rcx
leaq 0x14(%rsp), %r8
callq 0x1920
cmpb $0x1, 0xf(%rsp)
jne 0x1594
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x1e2a
jmp 0x15ed
movq 0x8(%r14), %rsi
subq (%r14), %rsi
shrq %rsi
andl $-0x2, %esi
movq %r14, %rdi
callq 0x1bc2
movq %r14, %rdi
movl 0x10(%rsp), %esi
callq 0x14a2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a53(%rip), %rdi      # 0x3062
leaq 0x1a53(%rip), %rsi      # 0x3069
leaq 0x1a56(%rip), %rcx      # 0x3073
movl $0x128, %edx            # imm = 0x128
callq 0x1090
leaq 0x1a5b(%rip), %rdi      # 0x3089
leaq 0x1a34(%rip), %rsi      # 0x3069
leaq 0x1a37(%rip), %rcx      # 0x3073
movl $0x129, %edx            # imm = 0x129
callq 0x1090