// File: /workspace/github_cpp_makefile_star2_O3/migueeelvargas[P]Auto-Complete/DictionaryTrie.cpp
// Function: DictionaryTrie::predictCompletions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int)
std::vector<std::string> DictionaryTrie::predictCompletions(std::string prefix, 
  unsigned int num_completions) {

  // First check if the prefix is in the TST & if not return an empty vector
  if(!find(prefix)){
    std::cout << "Prefix not in trie." << std::endl;
    return {};
  }

  if(num_completions == 0) {
    std::cout << "The number of completions is set to 0, 0 returned." << std::endl;
    return {};
  }

  std::vector<std::string> words;
  std::multimap<int, std::string, std::greater<int>> prefixWords;

  // Finds all the words with the given prefix
  findPrefixWords(prefix, prefixWords);

  // Based on the num_completions add only the top # of words
  unsigned int count = 0;
  for(auto it = prefixWords.begin(); 
    (count < num_completions) && (it != prefixWords.end()); ++it) {
    
    words.push_back(it->second);
    count++;
  }
  return words;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x349c
movq %r14, %rdi
movq %r12, %rsi
callq 0x603a
movl %eax, %r12d
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x618e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
testb %r12b, %r12b
je 0x6252
testl %ebp, %ebp
je 0x6267
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq 0x50(%rsp), %r12
movl $0x0, (%r12)
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x349c
leaq 0x8(%rsp), %rsi
leaq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x6320
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x6212
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x60(%rsp), %r14
cmpq %r12, %r14
je 0x6246
movl $0x1, %r15d
leaq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0x5b74
movq %r14, %rdi
callq 0x2150
cmpl %ebp, %r15d
jae 0x6246
movq %rax, %r14
incl %r15d
cmpq %r12, %rax
jne 0x6222
leaq 0x48(%rsp), %rdi
callq 0x6776
jmp 0x62b7
movq 0x4d7f(%rip), %r14      # 0xafd8
leaq 0x1ec2(%rip), %rsi      # 0x8122
movl $0x13, %edx
jmp 0x627a
movq 0x4d6a(%rip), %r14      # 0xafd8
leaq 0x1ec1(%rip), %rsi      # 0x8136
movl $0x32, %edx
movq %r14, %rdi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x6306
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x6306
jmp 0x6303
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x6318
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x6318
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x6776
movq %rbx, %rdi
callq 0x3352
movq %r14, %rdi
callq 0x22e0