// File: /workspace/github_cpp_makefile_star2_O2/reddragon[P]packed-memory-array/impl2.cpp
// Function: PMA::rebalance_interval(int, int)
void
    rebalance_interval(int left, int level) {
        dprintf("rebalance_interval(%d, %d)\n", left, level);
        int w = (1 << level) * this->chunk_size;
        tmp.clear();
        tmp.reserve(w);
        for (int i = left; i < left + w; ++i) {
            if (this->present[i]) {
                tmp.push_back(this->impl[i]);
                this->present[i] = false;
            }
        }
        double m = (double)(1<<level)*chunk_size / (double)tmp.size();
        dprintf("m: %f, tmp.size(): %d\n", m, tmp.size());
        assert(m >= 1.0);
        for (int i = 0; i < tmp.size(); ++i) {
            int k = i * m + left;
            if (k >= left + w) {
                dprintf("k: %d, left+w: %d\n", k, left + w);
            }
            assert(k < left + w);
            this->present[k] = true;
            this->impl[k] = tmp[i];
        }
        nmoves += w;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ecx
movl %esi, %r12d
movq %rdi, %rbx
pushq $0x1
popq %rax
shll %cl, %eax
movl %eax, 0x10(%rsp)
movl 0x48(%rdi), %eax
shll %cl, %eax
leaq 0x58(%rdi), %r13
movq 0x58(%rdi), %rcx
cmpq %rcx, 0x60(%rdi)
je 0x1bc2
movq %rcx, 0x60(%rbx)
movslq %eax, %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1e7a
movq %r14, 0x20(%rsp)
leal (%r14,%r12), %eax
leaq 0x20(%rbx), %r15
movq %r12, 0x8(%rsp)
movslq %r12d, %rbp
movl %eax, 0x1c(%rsp)
movslq %eax, %r12
leaq (,%rbp,4), %r14
cmpq %r12, %rbp
jge 0x1c31
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1816
testq %rdx, (%rax)
je 0x1c28
movq (%rbx), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0x1f2c
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1816
notq %rdx
andq %rdx, (%rax)
incq %rbp
addq $0x4, %r14
jmp 0x1bf4
cvtsi2sdl 0x10(%rsp), %xmm0
cvtsi2sdl 0x48(%rbx), %xmm2
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movq %rdx, %xmm1
punpckldq 0x13b5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x13bd(%rip), %xmm1     # 0x3020
mulsd %xmm0, %xmm2
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
ucomisd 0x13ab(%rip), %xmm2     # 0x3030
jb 0x1d26
cvtsi2sdl 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r13d, %r13d
movl 0x1c(%rsp), %ebp
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
jbe 0x1cec
cvtsi2sd %r13d, %xmm0
mulsd 0x10(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %ebp
jle 0x1d07
movslq %eax, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1816
orq %rdx, (%rax)
movq (%rbx), %rcx
movq 0x58(%rbx), %rax
movl (%rax,%r13,4), %edx
movl %edx, (%rcx,%r12,4)
incq %r13
movq 0x60(%rbx), %rcx
jmp 0x1c9e
movq 0x20(%rsp), %rax
addq %rax, 0x43d8(%rip)      # 0x60d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x156c(%rip), %rdi      # 0x327a
leaq 0x1354(%rip), %rsi      # 0x3069
leaq 0x1537(%rip), %rcx      # 0x3253
movl $0x114, %edx            # imm = 0x114
callq 0x1090
leaq 0x151d(%rip), %rdi      # 0x324a
leaq 0x1335(%rip), %rsi      # 0x3069
leaq 0x1518(%rip), %rcx      # 0x3253
movl $0x10e, %edx            # imm = 0x10E
callq 0x1090
nop