// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./range_source.h
// Function: CostAwareRangeSourceDriver<EbwtRangeSource>::foundFirstRange(Range*)
bool foundFirstRange(Range* r) {
		assert(r != NULL);
		assert(checkRange(r));
		this->foundRange = true;
		lastRange_ = r;
		if(strandFix_) {
			// We found a range but there may be an equally good range
			// on the other strand; let's try to get it.
			const size_t sz = active_.size();
			for(size_t i = 1; i < sz; i++) {
				// Same mate, different orientation?
				if(rss_[i]->mate1() == r->mate1 && rss_[i]->fw() != r->fw) {
					// Yes; see if it has the same cost
					TRangeSrcDrPtr p = active_[i];
					uint16_t minCost = max(this->minCost, p->minCost);
					if(minCost > r->cost) break;
					// Yes, it has the same cost
					assert_eq(minCost, r->cost); // can't be better
					// Advance it until it's done, we've found a range,
					// or its cost increases
					if(this->verbose_) cout << " Looking for opposite range to avoid strand bias:" << endl;
					while(!p->done && !p->foundRange) {
						p->advance(ADV_COST_CHANGES);
						assert_geq(p->minCost, minCost);
						if(p->minCost > minCost) break;
					}
					if(p->foundRange) {
						// Found one!  Now we have to choose which one
						// to give out first; we choose randomly using
						// the size of the ranges as weights.
						delayedRange_ = &p->range();
						assert(checkRange(delayedRange_));
						size_t tot = (delayedRange_->bot - delayedRange_->top) +
						             (lastRange_->bot    - lastRange_->top);
						uint32_t rq = rand_.nextU32() % tot;
						// We picked this range, not the first one
						if(rq < (delayedRange_->bot - delayedRange_->top)) {
							Range *tmp = lastRange_;
							lastRange_ = delayedRange_;
							delayedRange_ = tmp;
						}
						p->foundRange = false;
					}
					// Return true iff we need to force a re-sort
					return true;
				}
			}
			// OK, now we have a choice of two equally good ranges from
			// each strand.
		}
		return false;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movb $0x1, 0x8(%rdi)
movq %rsi, 0x70(%rdi)
cmpb $0x1, 0x51(%rdi)
jne 0x27a3c
movq %rsi, %r15
movq %rdi, %rbx
movq 0x48(%rdi), %r12
pushq $0x1
popq %r14
cmpq %r12, %r14
jae 0x27a3c
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
cmpb %al, 0x15(%r15)
jne 0x27a17
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
cmpb %al, 0x14(%r15)
jne 0x27a1c
incq %r14
jmp 0x279ea
movq 0x38(%rbx), %rax
movq (%rax,%r14,8), %r14
movzwl 0xa(%rbx), %eax
movzwl 0xa(%r14), %r12d
cmpw %r12w, %ax
cmoval %eax, %r12d
cmpw 0x8(%r15), %r12w
jbe 0x27a49
xorl %ebp, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x88(%rbx)
jne 0x27a6d
movq 0x3a557(%rip), %rdi     # 0x61fb0
leaq 0x2304a(%rip), %rsi     # 0x4aaaa
callq 0x94e0
movq %rax, %rdi
callq 0x9210
pushq $0x2
popq %rbp
movb 0x8(%r14), %al
cmpb $0x0, 0x9(%r14)
jne 0x27a95
testb $0x1, %al
jne 0x27a95
movq (%r14), %rax
movq %r14, %rdi
movl %ebp, %esi
callq *0x20(%rax)
cmpw %r12w, 0xa(%r14)
jbe 0x27a70
movb 0x8(%r14), %al
movb $0x1, %bpl
testb $0x1, %al
je 0x27a3e
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
movq %rax, 0x78(%rbx)
movl (%rax), %ecx
movl 0x4(%rax), %r15d
movq 0x70(%rbx), %rax
addl 0x4(%rax), %r15d
addl (%rax), %ecx
subl %ecx, %r15d
leaq 0x58(%rbx), %rdi
callq 0x264f6
xorl %edx, %edx
divl %r15d
movq 0x78(%rbx), %rax
movl 0x4(%rax), %ecx
subl (%rax), %ecx
cmpl %ecx, %edx
jae 0x27ae3
movq 0x70(%rbx), %rcx
movq %rax, 0x70(%rbx)
movq %rcx, 0x78(%rbx)
movb $0x0, 0x8(%r14)
jmp 0x27a3e
nop