// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rsi), %rax
subq (%rsi), %rax
shrq $0x2, %rax
movl %eax, 0x18(%rdi)
callq 0xa0ba
movq 0x10a8e(%rip), %r12     # 0x19fe8
leaq 0x8ea8(%rip), %rsi      # 0x12409
movq %r12, %rdi
callq 0x5480
movl 0x18(%rbx), %esi
movq %rax, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5240
movl 0x18(%rbx), %edi
callq 0x5b81
movl %eax, %r14d
incl %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa0c2
leaq 0x8e73(%rip), %rsi      # 0x1240f
movq %r12, %rdi
callq 0x5480
movq %rax, %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rsi
callq 0x52f0
movq %rax, %rdi
callq 0x5240
movq (%rbx), %rdi
movl 0x18(%rbx), %esi
callq 0x9d22
movl 0x18(%rbx), %eax
movq (%r15), %rcx
movq (%rbx), %rdi
xorl %edx, %edx
cmpq %rdx, %rax
je 0x95eb
movl (%rcx,%rdx,4), %esi
movq (%rdi), %r8
movl %esi, (%r8,%rdx,8)
movl %edx, 0x4(%r8,%rdx,8)
incq %rdx
jmp 0x95d2
pushq $0x1
popq %r15
leaq 0x10(%rsp), %r12
cmpq 0x8(%rsp), %r15
jae 0x96a9
leal -0x1(%r15), %ecx
pushq $0x1
popq %rax
movl %eax, %ebp
shll %cl, %ebp
pushq $-0x1
popq %rax
movl %r15d, %ecx
shll %cl, %eax
movl 0x18(%rbx), %ecx
leal (%rax,%rcx), %r13d
incl %r13d
imulq $0x18, %r15, %r14
addq %r14, %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %r12, %rsi
callq 0xa374
movq %r12, %rdi
callq 0x9f06
movq (%rbx), %rdi
addq %r14, %rdi
movq %r13, %rsi
callq 0x9d22
movq (%rbx), %rdi
leaq (%rdi,%r14), %rax
leaq (%rdi,%r14), %rcx
addq $-0x18, %rcx
shlq $0x3, %r13
shlq $0x3, %rbp
xorl %edx, %edx
cmpq %rdx, %r13
je 0x96a1
movq (%rcx), %rsi
movl (%rsi,%rdx), %r8d
addq %rdx, %rsi
leaq (%rsi,%rbp), %r9
movl (%rbp,%rsi), %r10d
cmpl %r10d, %r8d
cmoval %r8d, %r10d
movq (%rax), %r8
cmovaq %rsi, %r9
movl %r10d, (%r8,%rdx)
movl 0x4(%r9), %esi
movl %esi, 0x4(%r8,%rdx)
addq $0x8, %rdx
jmp 0x9668
incq %r15
jmp 0x95f4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq