// File: /workspace/github_cpp_makefile_star2_O1/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 0x34b0
movq %r14, %rdi
movq %r12, %rsi
callq 0x6016
movl %eax, %r12d
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x6168
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
testb %r12b, %r12b
je 0x622c
testl %ebp, %ebp
je 0x6241
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 0x34b0
leaq 0x8(%rsp), %rsi
leaq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x62fa
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x61ec
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x60(%rsp), %r14
cmpq %r12, %r14
je 0x6220
movl $0x1, %r15d
leaq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0x5b42
movq %r14, %rdi
callq 0x2150
cmpl %ebp, %r15d
jae 0x6220
movq %rax, %r14
incl %r15d
cmpq %r12, %rax
jne 0x61fc
leaq 0x48(%rsp), %rdi
callq 0x6750
jmp 0x6291
movq 0x4da5(%rip), %r14      # 0xafd8
leaq 0x1ee8(%rip), %rsi      # 0x8122
movl $0x13, %edx
jmp 0x6254
movq 0x4d90(%rip), %r14      # 0xafd8
leaq 0x1ee7(%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 0x62e0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x62e0
jmp 0x62dd
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x62f2
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x62f2
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x6750
movq %rbx, %rdi
callq 0x3368
movq %r14, %rdi
callq 0x22e0