// File: /workspace/github_cpp_makefile_star2_O3/nilnilnil[P]autocomplete/./include/sparsetable.hpp
// Function: SparseTable::initialize(std::vector<unsigned int, std::allocator<unsigned int>> const&)
void initialize(vui_t const& elems) {

        this->len = elems.size();
        this->repr.clear();

        cerr<<"len: "<<this->len<<endl;

        const size_t ntables = log2(this->len) + 1;
        this->repr.resize(ntables);

        cerr<<"ntables: "<<ntables<<endl;

        this->repr[0].resize(this->len);
        for (size_t i = 0; i < this->len; ++i) {
            this->repr[0][i] = std::make_pair(elems[i], i);
        }

        for (size_t i = 1; i < ntables; ++i) {
            // bs is the 'block size'. i.e. Number of element in the
            // array this->repr[i]
            // cerr<<"starting i: "<<i<<endl;
            const uint_t pbs = 1<<(i-1);
            const uint_t bs = 1<<i;
            const size_t vsz = this->len - bs + 1;

            this->repr[i] = vpui_t();
            this->repr[i].resize(vsz);

            // cerr<<"i: "<<i<<", vsz: "<<vsz<<endl;

            vpui_t& curr = this->repr[i];
            vpui_t& prev = this->repr[i - 1];

            for (size_t j = 0; j < vsz; ++j) {
                // 'j' is the starting index of a block of size 'bs'
                if (prev[j].first > prev[j+pbs].first) {
                    curr[j] = prev[j];
                }
                else {
                    curr[j] = prev[j+pbs];
                }
                // cerr<<"curr["<<j<<"] = "<<curr[j].first<<endl;
            }
            // cerr<<"done with i: "<<i<<endl;
        }
        // cerr<<"initialize() completed"<<endl;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq 0x8(%rsi), %rax
subq (%rsi), %rax
movq %rdi, %rbx
shrq $0x2, %rax
movl %eax, 0x18(%rdi)
movq (%rdi), %rsi
callq 0xc91a
movq 0x10350(%rip), %r14     # 0x1bff0
leaq 0x9762(%rip), %rsi      # 0x15409
movl $0x5, %edx
movq %r14, %rdi
callq 0x5590
movl 0x18(%rbx), %esi
movq %r14, %rdi
callq 0x52f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5480
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5300
movl 0x18(%rbx), %ecx
movl $0x1, %eax
cmpl $0x2, %ecx
jb 0xbd03
movl %ecx, %edx
shrl %edx
incl %eax
cmpl $0x3, %ecx
movl %edx, %ecx
ja 0xbcf8
movl %eax, %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc8de
movq 0x102d8(%rip), %r12     # 0x1bff0
leaq 0x96f0(%rip), %rsi      # 0x1540f
movl $0x9, %edx
movq %r12, %rdi
callq 0x5590
movq %r12, %rdi
movq %r14, (%rsp)
movq %r14, %rsi
callq 0x52f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x5480
movsbl %al, %esi
movq %r12, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5300
movq (%rbx), %rdi
movl 0x18(%rbx), %esi
callq 0xc5b6
movl 0x18(%rbx), %eax
testq %rax, %rax
je 0xbd95
movq (%r15), %rcx
movq (%rbx), %rdx
movq (%rdx), %rdx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
movl %edi, (%rdx,%rsi,8)
movl %esi, 0x4(%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0xbd83
cmpl $0x2, (%rsp)
jb 0xbe73
movq (%rbx), %rdi
movl $0x1, %r15d
leaq -0x1(%r15), %r12
movl $0x1, %ebp
movl %r12d, %ecx
shll %cl, %ebp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %r15d, %ecx
shll %cl, %r13d
movl 0x18(%rbx), %r14d
leaq (%r15,%r15,2), %rcx
movq (%rdi,%rcx,8), %rax
movq 0x10(%rdi,%rcx,8), %rsi
xorps %xmm0, %xmm0
movups %xmm0, (%rdi,%rcx,8)
movq $0x0, 0x10(%rdi,%rcx,8)
testq %rax, %rax
je 0xbdf6
subq %rax, %rsi
movq %rax, %rdi
callq 0x54c0
movq (%rbx), %rdi
addl %r14d, %r13d
incl %r13d
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r14
addq %r14, %rdi
movq %r13, %rsi
callq 0xc5b6
movq (%rbx), %rdi
testq %r13, %r13
je 0xbe66
addq %rdi, %r14
leaq (%r12,%r12,2), %rax
movq (%rdi,%rax,8), %rax
movl %ebp, %ecx
leaq (%rax,%rcx,8), %rcx
movq (%r14), %rdx
shlq $0x3, %r13
xorl %esi, %esi
leaq (%rax,%rsi), %r8
movl (%rax,%rsi), %r9d
leaq (%rcx,%rsi), %r10
movl (%rcx,%rsi), %r11d
cmpl %r11d, %r9d
cmoval %r9d, %r11d
cmovaq %r8, %r10
movl %r11d, (%rdx,%rsi)
movl 0x4(%r10), %r8d
movl %r8d, 0x4(%rdx,%rsi)
addq $0x8, %rsi
cmpq %rsi, %r13
jne 0xbe35
incq %r15
cmpq (%rsp), %r15
jne 0xbda8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq