// File: BenLangmead[P]bowtie/./ebwt_search_backtrack.h
// Function: EbwtRangeSource::hhCheck(Branch*, unsigned int, bool)
bool hhCheck(Branch *b, uint32_t depth, bool empty) {
		const uint32_t nedits = (uint32_t)b->edits_.size();
		ASSERT_ONLY(uint32_t lim3 = (offRev3_ == offRev2_)? 2 : 3);
		ASSERT_ONLY(uint32_t lim5 = (offRev1_ == offRev0_)? 2 : 1);
		if((depth == (depth5_-1)) && !empty) {
			// We're crossing the boundary separating the hi-half
			// from the non-seed portion of the read.
			// We should induce a mismatch if we haven't mismatched
			// yet, so that we don't waste time pursuing a match
			// that was covered by a previous phase
			assert_leq(nedits, lim5);
			return nedits > 0;
		} else if((depth == (depth3_-1)) && !empty) {
			// We're crossing the boundary separating the lo-half
			// from the non-seed portion of the read
			assert_leq(nedits, lim3);
			assert_gt(nedits, 0);
			// Count the mismatches in the lo and hi halves
			uint32_t loHalfMms = 0, hiHalfMms = 0;
			for(size_t i = 0; i < nedits; i++) {
				uint32_t depth = b->edits_.get(i).pos;
				if     (depth < depth5_) hiHalfMms++;
				else if(depth < depth3_) loHalfMms++;
				else assert(false);
			}
			assert_leq(loHalfMms + hiHalfMms, lim3);
			bool invalidHalfAndHalf = (loHalfMms == 0 || hiHalfMms == 0);
			return (nedits >= (uint32_t)halfAndHalf_ && !invalidHalfAndHalf);
		}
#ifndef NDEBUG
		if(depth < depth5_-1) {
			assert_leq(nedits, lim5);
		}
		else if(depth >= depth5_ && depth < depth3_-1) {
			assert_gt(nedits, 0);
			assert_leq(nedits, lim3);
		}
#endif
		return true;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
callq 0x41bd0
movq -0x48(%rbp), %rcx
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl 0x98(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x44c8d
testb $0x1, -0x1d(%rbp)
jne 0x44c8d
cmpl $0x0, -0x24(%rbp)
seta %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x44d80
movq -0x48(%rbp), %rcx
movl -0x1c(%rbp), %eax
movl 0x9c(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x44d7a
testb $0x1, -0x1d(%rbp)
jne 0x44d7a
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
jae 0x44d37
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rsi
callq 0x41d50
movq -0x48(%rbp), %rcx
movl (%rax), %eax
shrl $0x14, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x98(%rcx), %eax
jae 0x44d09
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x44d27
movq -0x48(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x9c(%rcx), %eax
jae 0x44d23
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x44d25
jmp 0x44d25
jmp 0x44d27
jmp 0x44d29
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x44cc5
movb $0x1, %al
cmpl $0x0, -0x28(%rbp)
movb %al, -0x49(%rbp)
je 0x44d4c
cmpl $0x0, -0x2c(%rbp)
sete %al
movb %al, -0x49(%rbp)
movq -0x48(%rbp), %rdx
movb -0x49(%rbp), %al
andb $0x1, %al
movb %al, -0x3d(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl 0x90(%rdx), %ecx
movb %al, -0x4a(%rbp)
jb 0x44d70
movb -0x3d(%rbp), %al
xorb $-0x1, %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x44d80
jmp 0x44d7c
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)