// File: Ahhgust[P]STRaitRazor/trie.cpp
// Function: Trie::existsPrefixMatch(char const*, unsigned int, unsigned int, unsigned char)
bool
Trie::existsPrefixMatch(const char *w, unsigned wordLen, unsigned outId, unsigned char outType) {

  unsigned i;
  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) {
	if ( parent->type->at(i) == outType &&
	     parent->id->at(i) == outId)
	  return true;
      }
    }


    c = *w;
    if (c == 'A') {
      if (parent->a == NULL) {
	return false;
      }
      child = parent->a;
    } else if (c == 'C') {
      if (parent->c == NULL) {
	return false;
      }
      child = parent->c;
    } else if (c == 'G') {
      if (parent->g == NULL) {
	return false;
      }
      child = parent->g;
    } else {
      if (parent->t == NULL) {
	return false;
      }
      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) {
	if ( parent->type->at(i) == outType &&
	     parent->id->at(i) == outId)
	  return true;
    }
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x51(%rbp)
jae 0x11538
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x11544
jmp 0x11688
movq -0x38(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x115ba
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x8ea0
movl %eax, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x115b8
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
movslq -0x48(%rbp), %rsi
callq 0x13190
movzbl (%rax), %eax
movzbl -0x21(%rbp), %ecx
cmpl %ecx, %eax
jne 0x115ab
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0x48(%rbp), %rsi
callq 0x131d0
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x115ab
movb $0x1, -0x1(%rbp)
jmp 0x116ff
jmp 0x115ad
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x11566
jmp 0x115ba
movq -0x18(%rbp), %rax
movb (%rax), %al
movb %al, -0x29(%rbp)
movsbl -0x29(%rbp), %eax
cmpl $0x41, %eax
jne 0x115ec
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x115df
movb $0x0, -0x1(%rbp)
jmp 0x116ff
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x11666
movsbl -0x29(%rbp), %eax
cmpl $0x43, %eax
jne 0x11617
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x11609
movb $0x0, -0x1(%rbp)
jmp 0x116ff
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x11664
movsbl -0x29(%rbp), %eax
cmpl $0x47, %eax
jne 0x11642
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x11634
movb $0x0, -0x1(%rbp)
jmp 0x116ff
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x11662
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x11656
movb $0x0, -0x1(%rbp)
jmp 0x116ff
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x11664
jmp 0x11666
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x1151e
movq -0x38(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x116fb
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x8ea0
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x116f9
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
movslq -0x50(%rbp), %rsi
callq 0x13190
movzbl (%rax), %eax
movzbl -0x21(%rbp), %ecx
cmpl %ecx, %eax
jne 0x116ec
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0x50(%rbp), %rsi
callq 0x131d0
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x116ec
movb $0x1, -0x1(%rbp)
jmp 0x116ff
jmp 0x116ee
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x116aa
jmp 0x116fb
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)