// File: /workspace/github_cpp_makefile_star2_O1/Ahhgust[P]STRaitRazor/trie.cpp
// Function: Trie::addWord(char const*, unsigned int, unsigned int, unsigned char)
void
Trie::addWord(const char *w, unsigned wordLen, unsigned id, unsigned char type) {
  
  unsigned i;
  char c;
  TrieNode *parent, *child;
  parent = root;

  //  cout << w << "\t" << mem - root << "\t";

  // traverse the tree, allocing as needed
  for (i=0; i < wordLen && *w; ++i, ++w) {
    c = *w;
    if (c == 'A') {
      if (parent->a == NULL) {
	parent->a = ++mem;
      }
      child = parent->a;
    } else if (c == 'C') {
      if (parent->c == NULL) {
	parent->c = ++mem;
      }
      child = parent->c;
    } else if (c == 'G') {
      if (parent->g == NULL) {
	parent->g = ++mem;
      }
      child = parent->g;
    } else {
      if (parent->t == NULL) {
	parent->t = ++mem;
      }
      child = parent->t;
    }
    
    parent = child;
  }

  if (parent->id == NULL) {
    parent->id = new vector<unsigned>;
    parent->type = new vector<unsigned char>;
    parent->id->push_back(id);
    parent->type->push_back(type);
  } else {
    // ensure that each type/id pair is only added once    
    for (i=0; i < parent->id->size(); ++i) {
      if (parent->id->at(i) == id &&
          parent->type->at(i) == type)
        return;
    }

    parent->id->push_back(id);
    parent->type->push_back(type);    


  }


  
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %ecx, %ebx
movl %ecx, 0xc(%rsp)
movb %r8b, 0xb(%rsp)
movq (%rdi), %r14
testl %edx, %edx
je 0x9b2a
movq 0x8(%rdi), %rax
addq $0x8, %rdi
movl %edx, %ecx
xorl %edx, %edx
movzbl (%rsi,%rdx), %r9d
cmpl $0x42, %r9d
jle 0x9ae3
cmpl $0x43, %r9d
je 0x9af7
cmpl $0x47, %r9d
jne 0x9b1d
leaq 0x10(%r14), %r9
cmpq $0x0, 0x10(%r14)
jne 0x9b0c
jmp 0x9b02
cmpl $0x41, %r9d
jne 0x9b18
cmpq $0x0, (%r14)
movq %r14, %r9
je 0x9b02
movq %r14, %r9
jmp 0x9b0c
leaq 0x8(%r14), %r9
cmpq $0x0, 0x8(%r14)
jne 0x9b0c
addq $0x30, %rax
movq %rax, (%rdi)
movq %rax, (%r9)
movq (%r9), %r14
incq %rdx
cmpl %edx, %ecx
jne 0x9abf
jmp 0x9b2a
testl %r9d, %r9d
je 0x9b2a
leaq 0x18(%r14), %r9
cmpq $0x0, 0x18(%r14)
jne 0x9b0c
jmp 0x9b02
movq 0x20(%r14), %rdi
testq %rdi, %rdi
je 0x9b81
movq (%rdi), %rcx
movq 0x8(%rdi), %rsi
movq %rsi, %r9
subq %rcx, %r9
je 0x9bbc
sarq $0x2, %r9
movl $0x1, %r10d
xorl %eax, %eax
cmpl %ebx, (%rcx,%rax,4)
jne 0x9b74
movq 0x28(%r14), %rdx
movq (%rdx), %r11
movq 0x8(%rdx), %rdx
subq %r11, %rdx
cmpq %rax, %rdx
jbe 0x9c06
cmpb %r8b, (%r11,%rax)
je 0x9bfc
movl %r10d, %eax
incl %r10d
cmpq %rax, %r9
ja 0x9b4e
jmp 0x9bbc
movl $0x18, %edi
callq 0x32c0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
xorl %r15d, %r15d
movq %r15, 0x10(%rax)
movq %rax, 0x20(%r14)
movl $0x18, %edi
callq 0x32c0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r15, 0x10(%rax)
movq %rax, 0x28(%r14)
movq 0x20(%r14), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x9bce
movl %ebx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x9bd8
leaq 0xc(%rsp), %rdx
callq 0x840a
movq 0x28(%r14), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x9bf2
movb 0xb(%rsp), %al
movb %al, (%rsi)
incq 0x8(%rdi)
jmp 0x9bfc
leaq 0xb(%rsp), %rdx
callq 0xab34
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x23e2(%rip), %rdi      # 0xbfef
movq %rax, %rsi
xorl %eax, %eax
callq 0x33d0
nop