// File: /workspace/github_cpp_makefile_star2_O1/nilnilnil[P]autocomplete/./include/suggest.hpp
// Function: suggest(PhraseMap&, SegmentTree&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int)
vp_t
suggest(PhraseMap &pm, RMQ &st, std::string prefix, uint_t n = 16) {
    pvpi_t phrases = pm.query(prefix);
    // cerr<<"Got "<<phrases.second - phrases.first<<" candidate phrases from PhraseMap"<<endl;

    uint_t first = phrases.first  - pm.repr.begin();
    uint_t last  = phrases.second - pm.repr.begin();

    if (first == last) {
        return vp_t();
    }

    vp_t ret;
    --last;

    pqpr_t heap;
    pui_t best = st.query_max(first, last);
    heap.push(PhraseRange(first, last, best.first, best.second));

    while (ret.size() < n && !heap.empty()) {
        PhraseRange pr = heap.top();
        heap.pop();
        // cerr<<"Top phrase is at index: "<<pr.index<<endl;
        // cerr<<"And is: "<<pm.repr[pr.index].first<<endl;

        ret.push_back(pm.repr[pr.index]);

        uint_t lower = pr.first;
        uint_t upper = pr.index - 1;

        // Prevent underflow
        if (pr.index - 1 < pr.index && lower <= upper) {
            // cerr<<"[1] adding to heap: "<<lower<<", "<<upper<<", "<<best.first<<", "<<best.second<<endl;

            best = st.query_max(lower, upper);
            heap.push(PhraseRange(lower, upper, best.first, best.second));
        }

        lower = pr.index + 1;
        upper = pr.last;

        // Prevent overflow
        if (pr.index + 1 > pr.index && lower <= upper) {
            // cerr<<"[2] adding to heap: "<<lower<<", "<<upper<<", "<<best.first<<", "<<best.second<<endl;

            best = st.query_max(lower, upper);
            heap.push(PhraseRange(lower, upper, best.first, best.second));
        }
    }

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq (%rsi), %rdi
movq 0x8(%rsi), %rsi
movq %rcx, %rdx
callq 0xcbab
movq %r15, 0x40(%rsp)
movq (%r15), %rcx
subq %rcx, %rax
shrq $0x3, %rax
imull $0xb6db6db7, %eax, %r12d # imm = 0xB6DB6DB7
subq %rcx, %rdx
shrq $0x3, %rdx
imull $0xb6db6db7, %edx, %r13d # imm = 0xB6DB6DB7
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
cmpl %r13d, %r12d
je 0x70e0
decl %r13d
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x18(%r14), %ecx
decl %ecx
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %r12d, %r8d
movl %r13d, %r9d
callq 0xc7fc
movq %rax, %rcx
shrq $0x20, %rcx
movq %rsp, %rsi
movl %r12d, (%rsi)
movl %r13d, 0x4(%rsi)
movl %eax, 0x8(%rsi)
movl %ecx, 0xc(%rsi)
leaq 0x10(%rsp), %rdi
callq 0xc046
movl %ebp, %ecx
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rdx, %rax
movq %rcx, 0x38(%rsp)
cmpq %rcx, %rax
jae 0x70c9
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x70c9
movl (%rax), %r12d
movl 0x4(%rax), %ebp
movl 0xc(%rax), %r13d
leaq 0x10(%rsp), %rdi
callq 0xc0dc
imulq $0x38, %r13, %rsi
movq 0x40(%rsp), %rax
addq (%rax), %rsi
movq %rbx, %rdi
callq 0xc11c
movl %r13d, %r15d
subl $0x1, %r15d
setb %al
cmpl %r15d, %r12d
seta %cl
orb %al, %cl
jne 0x7061
movl 0x18(%r14), %ecx
decl %ecx
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %r12d, %r8d
movl %r15d, %r9d
callq 0xc7fc
movq %rax, %rcx
shrq $0x20, %rcx
movl %r12d, (%rsp)
movl %r15d, 0x4(%rsp)
movl %eax, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
movq %rsp, %rsi
callq 0xc046
cmpl %ebp, %r13d
jae 0x70a5
incl %r13d
movl 0x18(%r14), %ecx
decl %ecx
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %r13d, %r8d
movl %ebp, %r9d
callq 0xc7fc
movq %rax, %rcx
shrq $0x20, %rcx
movl %r13d, (%rsp)
movl %ebp, 0x4(%rsp)
movl %eax, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
movq %rsp, %rsi
callq 0xc046
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rax
cmpq 0x38(%rsp), %rax
jb 0x6fd8
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x70e0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x54c0
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x70fe
jmp 0x70fe
jmp 0x70fe
jmp 0x70fe
jmp 0x70fe
jmp 0x70fe
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7118
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x54c0
movq %rbx, %rdi
callq 0xc17a
movq %r14, %rdi
callq 0x58e0