// File: /workspace/github_cpp_makefile_star2_O3/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 0x9921
xorl %r11d, %r11d
movb (%rsi), %r10b
testb %r10b, %r10b
je 0x9921
movq 0x20(%rdi), %r9
testq %r9, %r9
je 0x98e2
movq 0x8(%r9), %rbx
subq (%r9), %rbx
shrq $0x2, %rbx
testl %ebx, %ebx
jle 0x98e2
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 0x998d
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 0x998d
movl (%r15,%r9,4), %r10d
movl %r10d, (%rcx,%r9,4)
incq %r9
addq $-0x4, %r14
cmpq %r9, %rbx
jne 0x988b
movb (%rsi), %r10b
subq %r14, %rcx
addq %r9, %r8
cmpb $0x47, %r10b
je 0x9903
movzbl %r10b, %r9d
cmpl $0x43, %r9d
je 0x98fd
cmpl $0x41, %r9d
jne 0x9909
movq (%rdi), %rdi
jmp 0x990d
movq 0x8(%rdi), %rdi
jmp 0x990d
movq 0x10(%rdi), %rdi
jmp 0x990d
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0x9987
incl %r11d
incq %rsi
cmpl %edx, %r11d
jne 0x9859
movq 0x20(%rdi), %rdx
testq %rdx, %rdx
je 0x9987
movq 0x8(%rdx), %r9
subq (%rdx), %r9
shrq $0x2, %r9
testl %r9d, %r9d
jle 0x9987
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 0x99a1
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 0x99a1
movl (%r10,%rsi,4), %edx
movl %edx, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %r9
jne 0x9946
popq %rbx
popq %r14
popq %r15
retq
leaq 0x267b(%rip), %rdi      # 0xc00f
movq %r9, %rsi
movq %r10, %rdx
xorl %eax, %eax
callq 0x33d0
leaq 0x2667(%rip), %rdi      # 0xc00f
jmp 0x999a