// File: /workspace/github_cpp_makefile_star2_O1/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 0x17fa
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 0x1600
movl %r15d, %ecx
cmpq %rcx, %rax
jbe 0x161f
movl 0x48(%r14), %r12d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1892
movl %eax, %r13d
leal -0x1(%r12), %eax
movl %eax, 0x10(%rsp)
movb $0x0, 0xf(%rsp)
movl 0x48(%r14), %eax
addl %r13d, %eax
decl %eax
cltq
leaq 0x3f(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x6, %rcx
shlq $0x3, %rcx
addq 0x20(%r14), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x3f(%rdx), %rsi
andq %rax, %rsi
xorl %edi, %edi
cmpq %rdx, %rsi
setbe %dil
movq -0x8(%rcx,%rdi,8), %rcx
btq %rax, %rcx
jae 0x1566
leaq 0xf(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x1916
cmpl %r12d, 0x10(%rsp)
jge 0x157c
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x19c2
jmp 0x15f1
movl %ebx, 0x14(%rsp)
leaq 0xf(%rsp), %r13
movb $0x0, (%r13)
xorl %ebp, %ebp
cmpl 0x50(%r14), %ebp
jge 0x15d0
incl %ebp
addl %r12d, %r12d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1892
movl %eax, %ebx
movq %r14, %rdi
movl %eax, %esi
movl %ebp, %edx
movq %r13, %rcx
leaq 0x10(%rsp), %r8
callq 0x1916
cmpb $0x1, 0xf(%rsp)
jne 0x158c
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x1e3a
jmp 0x15e5
movq 0x8(%r14), %rsi
subq (%r14), %rsi
shrq %rsi
andl $-0x2, %esi
movq %r14, %rdi
callq 0x1b94
movq %r14, %rdi
movl 0x14(%rsp), %esi
callq 0x14a2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a5b(%rip), %rdi      # 0x3062
leaq 0x1a5b(%rip), %rsi      # 0x3069
leaq 0x1a5e(%rip), %rcx      # 0x3073
movl $0x128, %edx            # imm = 0x128
callq 0x1090
leaq 0x1a63(%rip), %rdi      # 0x3089
leaq 0x1a3c(%rip), %rsi      # 0x3069
leaq 0x1a3f(%rip), %rcx      # 0x3073
movl $0x129, %edx            # imm = 0x129
callq 0x1090