// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %ecx
movl %esi, %r14d
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x4(%rsp)
movl 0x48(%rdi), %eax
shll %cl, %eax
leaq 0x58(%rdi), %rcx
movq %rcx, 0x10(%rsp)
movq 0x58(%rdi), %rcx
cmpq %rcx, 0x60(%rdi)
je 0x1e64
movq %rcx, 0x60(%rdi)
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
movslq %eax, %rbx
movq %rdi, 0x18(%rsp)
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x2160
movq 0x18(%rsp), %rdi
movq %r14, 0x8(%rsp)
leal (%rbx,%r14), %eax
movl %eax, (%rsp)
movq %rbx, 0x20(%rsp)
testl %ebx, %ebx
jle 0x1f63
movslq 0x8(%rsp), %r13
movslq (%rsp), %r8
movq 0x20(%rdi), %rax
leaq (,%r13,4), %r12
leaq 0x3f(%rbp), %r9
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
leal 0x3f(%r13), %edx
testl %r13d, %r13d
cmovnsl %r13d, %edx
sarl $0x6, %edx
movq %r13, %rcx
andq %r9, %rcx
xorl %r15d, %r15d
movq %rbp, %r14
cmpq %rbp, %rcx
setbe %r15b
movl $0x1, %ebx
movl %r13d, %ecx
shlq %cl, %rbx
movslq %edx, %rbp
leaq (%rax,%rbp,8), %rcx
movq -0x8(%rcx,%r15,8), %rcx
btq %r13, %rcx
jae 0x1f50
movq (%rdi), %rdx
addq %r12, %rdx
movq 0x60(%rdi), %rsi
cmpq 0x68(%rdi), %rsi
je 0x1f20
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rdi)
jmp 0x1f3d
movq 0x10(%rsp), %rdi
callq 0x2292
movq 0x28(%rsp), %r9
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %rdi
movq 0x20(%rdi), %rax
leaq -0x8(,%r15,8), %rcx
leaq (%rax,%rbp,8), %rdx
notq %rbx
andq %rbx, (%rcx,%rdx)
incq %r13
addq $0x4, %r12
cmpq %r8, %r13
movq %r14, %rbp
jl 0x1ec4
cvtsi2sdl 0x4(%rsp), %xmm1
cvtsi2sdl 0x48(%rdi), %xmm0
movq 0x58(%rdi), %rax
movq 0x60(%rdi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movq %rdx, %xmm2
punpckldq 0x1093(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x109b(%rip), %xmm2     # 0x3030
mulsd %xmm1, %xmm0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
ucomisd 0x1057(%rip), %xmm0     # 0x3008
jb 0x2077
cmpq %rax, %rcx
movl (%rsp), %r15d
je 0x203d
xorps %xmm1, %xmm1
cvtsi2sdl 0x8(%rsp), %xmm1
movq (%rdi), %rsi
movq 0x20(%rdi), %rdi
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %r8d, %r8d
leaq 0x3f(%rbp), %r9
xorps %xmm2, %xmm2
cvtsi2sd %r8d, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %ecx
cmpl %ecx, %r15d
jle 0x2058
movslq %ecx, %r10
leal 0x3f(%rcx), %r11d
testl %ecx, %ecx
cmovnsl %ecx, %r11d
sarl $0x6, %r11d
movslq %r11d, %r11
movq %r10, %rbx
andq %r9, %rbx
xorl %r14d, %r14d
cmpq %rbp, %rbx
setbe %r14b
movl $0x1, %ebx
shlq %cl, %rbx
leaq (%rdi,%r11,8), %rcx
orq %rbx, -0x8(%rcx,%r14,8)
movl (%rax,%r8,4), %ecx
movl %ecx, (%rsi,%r10,4)
incq %r8
cmpq %r8, %rdx
jne 0x1fdf
movq 0x20(%rsp), %rax
addq %rax, 0x3077(%rip)      # 0x50c0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x121b(%rip), %rdi      # 0x327a
leaq 0x1003(%rip), %rsi      # 0x3069
leaq 0x11e6(%rip), %rcx      # 0x3253
movl $0x114, %edx            # imm = 0x114
callq 0x1090
leaq 0x11cc(%rip), %rdi      # 0x324a
leaq 0xfe4(%rip), %rsi       # 0x3069
leaq 0x11c7(%rip), %rcx      # 0x3253
movl $0x10e, %edx            # imm = 0x10E
callq 0x1090