// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdx, -0xe8(%rbp)
movq %rsi, %rax
movq -0xe8(%rbp), %rsi
movq %rdi, -0xe0(%rbp)
movq %rdi, %rdx
movq %rdx, -0xd8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x30f0
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x9460
movb %al, -0xb9(%rbp)
jmp 0x9832
movb -0xb9(%rbp), %al
xorb $-0x1, %al
movb %al, -0xe9(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3170
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x9855
jmp 0x98b5
movq 0xb77c(%rip), %rdi      # 0x14fd8
leaq 0x48a3(%rip), %rsi      # 0xe106
callq 0x3210
movq %rax, %rdi
movq 0xb756(%rip), %rsi      # 0x14fc8
callq 0x3250
movq -0xe0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3150
movq -0xe0(%rbp), %rdi
callq 0x4b30
jmp 0x9a59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3170
jmp 0x9a69
cmpl $0x0, -0x1c(%rbp)
jne 0x9901
movq 0xb716(%rip), %rdi      # 0x14fd8
leaq 0x4851(%rip), %rsi      # 0xe11a
callq 0x3210
movq %rax, %rdi
movq 0xb6f0(%rip), %rsi      # 0x14fc8
callq 0x3250
movq -0xe0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3150
movq -0xe0(%rbp), %rdi
callq 0x4b30
jmp 0x9a59
movq -0xe0(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
callq 0x4b30
leaq -0x80(%rbp), %rdi
callq 0xa020
movq -0xe8(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x30f0
jmp 0x992f
movq -0xd0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x9a80
jmp 0x9948
leaq -0xa0(%rbp), %rdi
callq 0x3170
movl $0x0, -0xa4(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xa040
movq %rax, -0xb0(%rbp)
movl -0xa4(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0xea(%rbp)
jae 0x99aa
leaq -0x80(%rbp), %rdi
callq 0xa0a0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xa070
movb %al, -0xea(%rbp)
movb -0xea(%rbp), %al
testb $0x1, %al
jne 0x99b6
jmp 0x9a1f
leaq -0xb0(%rbp), %rdi
callq 0xa0d0
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x88f0
jmp 0x99d7
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa0f0
jmp 0x996e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9a34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3170
jmp 0x9a34
movb $0x1, -0x4d(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xa120
testb $0x1, -0x4d(%rbp)
jne 0x9a57
jmp 0x9a4b
leaq -0x80(%rbp), %rdi
callq 0xa120
movq -0xe0(%rbp), %rdi
callq 0x4b50
jmp 0x9a69
movq -0xe0(%rbp), %rdi
callq 0x4b50
jmp 0x9a59
movq -0xd8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x33c0
nopw %cs:(%rax,%rax)