// File: CMU-SAFARI[P]optimal-seed-solver/HashTree.cc
// Function: HashTree::query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int)
void HashTree::query(string DNA, unsigned int threshold) {
	hashVal = hashgen.calculateHash(DNA, hashLength);
	queryCursor = root[hashVal];
	length = hashLength;

	TreeNode* nextCursor;

	hitLeaf = false;

	if (queryCursor == NULL || queryCursor->isLeaf() || queryCursor->getLocNum() <= threshold ) {
		hitLeaf = true;
		return;
	}

	while (length < DNA.length() ) {


		switch (DNA[length]) {
			case 'A':
				nextCursor = queryCursor->getA();
				break;
			case 'C':
				nextCursor = queryCursor->getC();
				break;
			case 'G':
				nextCursor = queryCursor->getG();
				break;
			case 'T':
				nextCursor = queryCursor->getT();
				break;
			default:
				cerr << "unrecognized character: " << DNA[length] << endl;
				break;
		}

		queryCursor = nextCursor;
		length++;

		if (queryCursor == NULL || queryCursor->isLeaf() || queryCursor->getLocNum() <= threshold ) {
			hitLeaf = true;
			return;
		}
	}
}

// Assembly:
subq $0x48, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %rax, %rdi
addq $0x318, %rdi            # imm = 0x318
movl (%rax), %edx
callq 0x126e0
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x340(%rax)
movq 0x320(%rax), %rcx
movl 0x340(%rax), %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x348(%rax)
movl (%rax), %ecx
movl %ecx, 0x344(%rax)
movb $0x0, 0x350(%rax)
cmpq $0x0, 0x348(%rax)
je 0x803d
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x803d
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
callq 0x6690
cmpl 0x34(%rsp), %eax
ja 0x804e
movq 0x20(%rsp), %rax
movb $0x1, 0x350(%rax)
jmp 0x81d2
jmp 0x8050
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x344(%rax), %eax
movq %rax, 0x10(%rsp)
callq 0x34a0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x81d2
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x344(%rax), %eax
movl %eax, %esi
callq 0x3620
movsbl (%rax), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x13, %eax
ja 0x811c
movq 0x8(%rsp), %rax
leaq 0xb1a0(%rip), %rcx      # 0x13250
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
callq 0x66a0
movq %rax, 0x28(%rsp)
jmp 0x8168
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
callq 0x66b0
movq %rax, 0x28(%rsp)
jmp 0x8168
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
callq 0x66c0
movq %rax, 0x28(%rsp)
jmp 0x8168
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
callq 0x66d0
movq %rax, 0x28(%rsp)
jmp 0x8168
movq 0x12ecd(%rip), %rdi     # 0x1aff0
leaq 0xb2ac(%rip), %rsi      # 0x133d6
callq 0x32a0
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rsp)
movl 0x344(%rax), %eax
movl %eax, %esi
callq 0x3620
movq (%rsp), %rdi
movsbl (%rax), %esi
callq 0x3370
movq %rax, %rdi
movq 0x12e55(%rip), %rsi     # 0x1afb8
callq 0x32f0
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x348(%rax)
movl 0x344(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x344(%rax)
cmpq $0x0, 0x348(%rax)
je 0x81bf
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x81bf
movq 0x20(%rsp), %rax
movq 0x348(%rax), %rdi
callq 0x6690
cmpl 0x34(%rsp), %eax
ja 0x81cd
movq 0x20(%rsp), %rax
movb $0x1, 0x350(%rax)
jmp 0x81d2
jmp 0x8050
addq $0x48, %rsp
retq
nopw (%rax,%rax)