// File: migueeelvargas[P]Auto-Complete/DictionaryTrie.cpp
// Function: DictionaryTrie::traverse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>) const
std::pair<TrieNode*, unsigned int> DictionaryTrie::traverse(std::string word) const {
  TrieNode* curr = root;

  // If TST is empty, returns an empty pair
  if (curr == NULL)
    return std::make_pair(curr, 0);

	// We are going to traverse the trie as long as there is chars to cover
  unsigned int i = 0;

  // We will traverse as long there is characters to look for
  while (i < word.length()) {
    if(curr->symbol == word[i]) {
      if (curr->mid != NULL && i != word.length()-1) {
        curr = curr->mid;
        ++i;
      }
      else
        return std::make_pair(curr, i);
    }

    else if (word[i] < curr->symbol) {
      if (curr->left != NULL)
        curr = curr->left;
      else
        return std::make_pair(curr, i);
    }

    else {
      if (curr->right != NULL)
        curr = curr->right;
      else
        return std::make_pair(curr, i);
    }
  }
  // Added as a precaution
  return std::make_pair(curr, i);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rsi, -0xa0(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x95f8
movl $0x0, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x9f90
movl %edx, -0x48(%rbp)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x9fc0
jmp 0x97a5
movl $0x0, -0x54(%rbp)
movq -0xa0(%rbp), %rdi
movl -0x54(%rbp), %eax
movq %rax, -0xa8(%rbp)
callq 0x3360
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x9777
movq -0xa0(%rbp), %rdi
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0xac(%rbp)
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x3430
movq %rax, %rcx
movl -0xac(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x96cd
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x96a1
movq -0xa0(%rbp), %rdi
movl -0x54(%rbp), %eax
movq %rax, -0xb8(%rbp)
callq 0x3360
movq %rax, %rcx
movq -0xb8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x96a1
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x96c8
leaq -0x28(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x9ff0
movl %edx, -0x60(%rbp)
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x97a5
jmp 0x9772
movq -0xa0(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x3430
movsbl (%rax), %eax
movq -0x28(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x972b
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x9705
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x9729
leaq -0x28(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x9ff0
movl %edx, -0x70(%rbp)
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x97a5
jmp 0x9770
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x9744
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x976e
leaq -0x28(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x9ff0
movl %edx, -0x80(%rbp)
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x97a5
jmp 0x9770
jmp 0x9772
jmp 0x95ff
leaq -0x28(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x9ff0
movl %edx, -0x90(%rbp)
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %edx
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)