// File: /workspace/github_cpp_makefile_star2_O1/Ahhgust[P]STRaitRazor/trie.cpp
// Function: Trie::findPrefixMatch(char const*, unsigned int, unsigned int*, unsigned char*)
unsigned
Trie::findPrefixMatch(const char *w, unsigned wordLen, unsigned *outId, unsigned char *outType) {
  unsigned i, numHits=0;
  
  char c;
  TrieNode *parent, *child;
  parent = root;
  
  // traverse the tree, 
  for (i=0; i < wordLen && *w; ++i, ++w) {

    if (parent->id != NULL) {
      int size = parent->id->size();
      for ( int i = 0; i < size; ++i) {
	++numHits;
	*outType++ = parent->type->at(i);
	*outId++ = parent->id->at(i);
      }
    }


    c = *w;
    if (c == 'A') {
      if (parent->a == NULL) {
	return numHits;
      }
      child = parent->a;
    } else if (c == 'C') {
      if (parent->c == NULL) {
	return numHits;
      }
      child = parent->c;
    } else if (c == 'G') {
      if (parent->g == NULL) {
	return numHits;
      }
      child = parent->g;
    } else {
      if (parent->t == NULL) {
	return numHits;
      }
      child = parent->t;
    }
    
    parent = child;
  }

  // this is a corner case....
  // the entire binaryword matches the entire anchor sequence

  if (parent->id != NULL) {
    int size = parent->id->size();
    for ( int i = 0; i < size; ++i) {
      ++numHits;
      *outType++ = parent->type->at(i);
      *outId++ = parent->id->at(i);
    }
  }

  return numHits;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq (%rdi), %rdi
xorl %eax, %eax
testl %edx, %edx
je 0x986b
xorl %r11d, %r11d
cmpb $0x0, (%rsi)
je 0x986b
movq 0x20(%rdi), %r9
testq %r9, %r9
je 0x982c
movq 0x8(%r9), %rbx
subq (%r9), %rbx
shrq $0x2, %rbx
testl %ebx, %ebx
jle 0x982c
addl %ebx, %eax
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
xorl %r9d, %r9d
movq 0x28(%rdi), %r10
movq (%r10), %r15
movq 0x8(%r10), %r10
subq %r15, %r10
cmpq %r9, %r10
jbe 0x98d7
movb (%r15,%r9), %r10b
movb %r10b, (%r8,%r9)
movq 0x20(%rdi), %r10
movq (%r10), %r15
movq 0x8(%r10), %r10
subq %r15, %r10
sarq $0x2, %r10
cmpq %r9, %r10
jbe 0x98d7
movl (%r15,%r9,4), %r10d
movl %r10d, (%rcx,%r9,4)
incq %r9
addq $-0x4, %r14
cmpq %r9, %rbx
jne 0x97d8
subq %r14, %rcx
addq %r9, %r8
movzbl (%rsi), %r9d
cmpl $0x47, %r9d
je 0x984d
cmpl $0x43, %r9d
je 0x9847
cmpl $0x41, %r9d
jne 0x9853
movq (%rdi), %rdi
jmp 0x9857
movq 0x8(%rdi), %rdi
jmp 0x9857
movq 0x10(%rdi), %rdi
jmp 0x9857
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0x98d1
incl %r11d
incq %rsi
cmpl %edx, %r11d
jne 0x97a9
movq 0x20(%rdi), %rdx
testq %rdx, %rdx
je 0x98d1
movq 0x8(%rdx), %r9
subq (%rdx), %r9
shrq $0x2, %r9
testl %r9d, %r9d
jle 0x98d1
addl %r9d, %eax
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
xorl %esi, %esi
movq 0x28(%rdi), %rdx
movq (%rdx), %r10
movq 0x8(%rdx), %rdx
subq %r10, %rdx
cmpq %rsi, %rdx
jbe 0x98eb
movb (%r10,%rsi), %dl
movb %dl, (%r8,%rsi)
movq 0x20(%rdi), %rdx
movq (%rdx), %r10
movq 0x8(%rdx), %rdx
subq %r10, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x98eb
movl (%r10,%rsi,4), %edx
movl %edx, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %r9
jne 0x9890
popq %rbx
popq %r14
popq %r15
retq
leaq 0x2711(%rip), %rdi      # 0xbfef
movq %r9, %rsi
movq %r10, %rdx
xorl %eax, %eax
callq 0x33d0
leaq 0x26fd(%rip), %rdi      # 0xbfef
jmp 0x98e4