// File: /workspace/github_cpp_makefile_star2_O1/migueeelvargas[P]Auto-Complete/DictionaryTrie.cpp
// Function: DictionaryTrie::insert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int)
bool DictionaryTrie::insert(std::string word, unsigned int freq)
{
  // Check for empty strings
  if (word.length() == 0)
    return false;

  // Checks if the word is in TST, if it is returns false
  if (find(word))
    return false;

  // If not in TST, traverse TST
  auto retVal = traverse(word);
  auto curr = retVal.first;

  // Check if TST is empty
  if (root == NULL) {
    root = new TrieNode(word[0]);
    curr = root;
    ++num_vertices;
  }

  // Sets flag if word was already in BST
  else if (retVal.second == word.length()) {
    retVal.first->isAWord = true;
    return true;
  }
  // Check if we need to add a new branch to TST
  else if (retVal.first->symbol != word[retVal.second]) {
    if (word[retVal.second] < curr->symbol) {
      curr->left = new TrieNode(word[retVal.second]);
      curr = curr->left;
      ++num_vertices;
    }
    else {
      curr->right = new TrieNode(word[retVal.second]);
      curr = curr->right;
      ++num_vertices;
    }
  }

  // Now, add rest of characters down the middle
  for (auto i = retVal.second + 1; i < word.length(); ++i) {
    curr->mid = new TrieNode(word[i]);
    curr = curr->mid;
    ++num_vertices;
  }

  // Sets word flag & word frequency
  curr->isAWord = true;
  curr->freq = freq;

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %ebx
movq 0x8(%rsi), %rdx
testq %rdx, %rdx
je 0x5e84
movq %rsi, %r14
movq %rdi, %r13
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rsi), %rsi
addq %rsi, %rdx
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x34b0
movq %r13, %rdi
movq %r12, %rsi
callq 0x6016
movl %eax, %ebp
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x5e7f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
testb %bpl, %bpl
je 0x5e8b
xorl %eax, %eax
jmp 0x5fe5
movl %ebx, 0x14(%rsp)
leaq 0x48(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
callq 0x34b0
movq %r13, (%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x60ae
movq %rax, %r13
movl %edx, %r12d
movq (%rbp), %rdi
cmpq %rbx, %rdi
je 0x5eda
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21d0
movq (%rsp), %rbx
cmpq $0x0, 0x8(%rbx)
je 0x5ef8
movl %r12d, %ebx
cmpq %rbx, 0x8(%r14)
jne 0x5f21
movb $0x1, 0x20(%r13)
jmp 0x5fe3
movl $0x28, %edi
callq 0x21c0
movq (%r14), %rcx
movb (%rcx), %cl
movb %cl, (%rax)
movl $0x0, 0x24(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x11(%rax)
movq %rax, 0x8(%rbx)
jmp 0x5f6d
movb (%r13), %al
movq (%r14), %rbp
movb (%rbp,%rbx), %r15b
cmpb %r15b, %al
je 0x5f72
movl $0x28, %edi
movb %al, 0x8(%rsp)
callq 0x21c0
movb (%rbp,%rbx), %cl
movb %cl, (%rax)
movl $0x0, 0x24(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x11(%rax)
movups %xmm0, 0x8(%rax)
cmpb 0x8(%rsp), %r15b
jge 0x5f65
movq %rax, 0x8(%r13)
jmp 0x5f69
movq %rax, 0x10(%r13)
movq (%rsp), %rbx
incl (%rbx)
movq %rax, %r13
movq 0x8(%r14), %rbp
leal 0x1(%r12), %r15d
cmpq %r15, %rbp
jbe 0x5fd5
movq %r14, 0x8(%rsp)
movq (%rsp), %r14
movl (%r14), %ebx
addl $0x2, %r12d
incl %ebx
movl $0x28, %edi
callq 0x21c0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movb (%rcx,%r15), %cl
movb %cl, (%rax)
movl $0x0, 0x24(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x11(%rax)
movq %rax, 0x18(%r13)
movl %ebx, (%r14)
movl %r12d, %r15d
incl %r12d
incl %ebx
movq %rax, %r13
cmpq %r15, %rbp
ja 0x5f92
jmp 0x5fd8
movq %r13, %rax
movb $0x1, 0x20(%rax)
movl 0x14(%rsp), %ecx
movl %ecx, 0x24(%rax)
movb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x600e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22e0