// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
movq %rcx, %rsi
callq 0x974a
movq %rdx, %rcx
movq %r14, 0x40(%rsp)
movq (%r14), %rsi
subq %rsi, %rax
pushq $0x38
popq %rdi
cqto
idivq %rdi
movq %rax, %r14
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %rdi
movq %rax, %r12
xorps %xmm0, %xmm0
cmpl %r12d, %r14d
jne 0x6734
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
jmp 0x6870
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
decl %r12d
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x9512
movq %r15, 0x18(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
leaq 0x8(%rsp), %rsi
movl %r14d, (%rsi)
movl %r12d, 0x4(%rsi)
movl %eax, 0x8(%rsi)
movl %ecx, 0xc(%rsi)
leaq 0x20(%rsp), %rdi
callq 0x9842
movl %ebp, %r12d
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0x38
popq %rcx
idivq %rcx
cmpq %r12, %rax
jae 0x6866
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x6866
movl (%rax), %r14d
movl 0x4(%rax), %ebp
movl 0xc(%rax), %r13d
leaq 0x20(%rsp), %rdi
callq 0x9858
imulq $0x38, %r13, %rsi
movq 0x40(%rsp), %rax
addq (%rax), %rsi
movq %rbx, %rdi
callq 0x9870
movl %r13d, %r15d
subl $0x1, %r15d
setb %al
cmpl %r15d, %r14d
seta %cl
orb %al, %cl
jne 0x681f
movq 0x18(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x9512
movq %rax, %rcx
shrq $0x20, %rcx
movl %r14d, 0x8(%rsp)
movl %r15d, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9842
cmpl %ebp, %r13d
jae 0x6783
incl %r13d
movq 0x18(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x9512
movq %rax, %rcx
shrq $0x20, %rcx
movl %r13d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9842
jmp 0x6783
leaq 0x20(%rsp), %rdi
callq 0xb058
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x688e
jmp 0x688e
jmp 0x688e
jmp 0x688e
jmp 0x688e
jmp 0x688e
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xb058
movq %rbx, %rdi
callq 0x989c
movq %r14, %rdi
callq 0x58e0