// File: /workspace/github_cpp_makefile_star2_O3/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 0x5e7c
movq %rsi, %r13
movq %rdi, %r12
leaq 0x28(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rsi), %rsi
addq %rsi, %rdx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x349c
movq %r12, %rdi
movq %r15, %rsi
callq 0x603a
movl %eax, %ebp
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x5e77
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
testb %bpl, %bpl
je 0x5e83
xorl %eax, %eax
jmp 0x6009
movl %ebx, 0x14(%rsp)
leaq 0x48(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
callq 0x349c
movq %r12, 0x8(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x60d2
movq %rax, %r12
movl %edx, %r15d
movq (%rbp), %rdi
cmpq %rbx, %rdi
je 0x5ed4
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x8(%rsp), %rbx
cmpq $0x0, 0x8(%rbx)
je 0x5ef7
movl %r15d, %eax
movq 0x8(%r13), %rbx
cmpq %rax, %rbx
jne 0x5f39
movb $0x1, 0x20(%r12)
jmp 0x6007
movl $0x28, %edi
callq 0x21c0
movq %rax, %r12
movq (%r13), %rdx
movb (%rdx), %al
movb %al, (%r12)
movl $0x0, 0x24(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movups %xmm0, 0x11(%r12)
movq %r12, 0x8(%rbx)
movl (%rbx), %r14d
incl %r14d
movl %r14d, (%rbx)
movq 0x8(%r13), %rbx
jmp 0x5f9b
movb (%r12), %r14b
movq (%r13), %rdx
movb (%rdx,%rax), %r13b
cmpb %r13b, %r14b
jne 0x5f54
movq 0x8(%rsp), %rax
movl (%rax), %r14d
jmp 0x5f9b
movq %rdx, %rbp
movl $0x28, %edi
callq 0x21c0
movb %r13b, (%rax)
movl $0x0, 0x24(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x11(%rax)
cmpb %r14b, %r13b
jge 0x5f82
movq %rax, 0x8(%r12)
jmp 0x5f87
movq %rax, 0x10(%r12)
movq 0x8(%rsp), %rcx
movl (%rcx), %r14d
incl %r14d
movl %r14d, (%rcx)
movq %rax, %r12
movq %rbp, %rdx
leal 0x1(%r15), %r13d
cmpq %r13, %rbx
jbe 0x5ff9
addl $0x2, %r15d
incl %r14d
movl $0x28, %edi
movq %rbx, %rbp
movq %rdx, %rbx
callq 0x21c0
movq %rbx, %rdx
movq %rbp, %rbx
movb (%rdx,%r13), %cl
movb %cl, (%rax)
movl $0x0, 0x24(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x11(%rax)
movups %xmm0, 0x8(%rax)
movq %rax, 0x18(%r12)
movq 0x8(%rsp), %rcx
movl %r14d, (%rcx)
movl %r15d, %r13d
incl %r15d
incl %r14d
movq %rax, %r12
cmpq %r13, %rbp
ja 0x5fab
jmp 0x5ffc
movq %r12, %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 %r14, %rdi
je 0x6032
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22e0