// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e74
movq %rcx, 0x60(%rdi)
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
movslq %eax, %rbx
movq %rdi, 0x18(%rsp)
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x216a
movq 0x18(%rsp), %rdi
movq %r14, 0x8(%rsp)
leal (%rbx,%r14), %eax
movl %eax, (%rsp)
movq %rbx, 0x20(%rsp)
testl %ebx, %ebx
jle 0x1f6e
movslq 0x8(%rsp), %r13
movslq (%rsp), %r8
leaq (,%r13,4), %r12
leaq 0x3f(%rbp), %r9
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
leaq 0x3f(%r13), %r15
testq %r13, %r13
cmovnsq %r13, %r15
sarq $0x6, %r15
shlq $0x3, %r15
movq 0x20(%rdi), %rax
addq %r15, %rax
movq %r13, %rcx
andq %r9, %rcx
xorl %ebx, %ebx
movq %rbp, %r14
cmpq %rbp, %rcx
setbe %bl
movl $0x1, %ebp
movl %r13d, %ecx
shlq %cl, %rbp
movq -0x8(%rax,%rbx,8), %rax
btq %r13, %rax
jae 0x1f5b
movq (%rdi), %rdx
addq %r12, %rdx
movq 0x60(%rdi), %rsi
cmpq 0x68(%rdi), %rsi
je 0x1f2f
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rdi)
jmp 0x1f48
movq 0x10(%rsp), %rdi
callq 0x2296
movq 0x28(%rsp), %r9
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %rdi
leaq -0x8(,%rbx,8), %rax
addq 0x20(%rdi), %r15
notq %rbp
andq %rbp, (%rax,%r15)
incq %r13
addq $0x4, %r12
cmpq %r8, %r13
movq %r14, %rbp
jl 0x1ed0
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 0x1078(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x1080(%rip), %xmm2     # 0x3020
mulsd %xmm1, %xmm0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
ucomisd 0x1074(%rip), %xmm0     # 0x3030
jb 0x2080
cmpq %rax, %rcx
movl (%rsp), %r15d
je 0x2046
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 0x2061
movslq %ecx, %r10
leaq 0x3f(%r10), %r11
testq %r10, %r10
cmovnsq %r10, %r11
sarq $0x6, %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 0x1fea
movq 0x20(%rsp), %rax
addq %rax, 0x306e(%rip)      # 0x50c0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1212(%rip), %rdi      # 0x327a
leaq 0xffa(%rip), %rsi       # 0x3069
leaq 0x11dd(%rip), %rcx      # 0x3253
movl $0x114, %edx            # imm = 0x114
callq 0x1090
leaq 0x11c3(%rip), %rdi      # 0x324a
leaq 0xfdb(%rip), %rsi       # 0x3069
leaq 0x11be(%rip), %rcx      # 0x3253
movl $0x10e, %edx            # imm = 0x10E
callq 0x1090
nop