// File: BenLangmead[P]bowtie/./range_source.h
// Function: CostAwareRangeSourceDriver<EbwtRangeSource>::advanceImpl(int)
virtual void advanceImpl(int until) {
		lastRange_ = NULL;
		ASSERT_ONLY(uint16_t iminCost = this->minCost);
		const size_t actSz = active_.size();
		assert(sortedActives());
		if(delayedRange_ != NULL) {
			assert_eq(iminCost, delayedRange_->cost);
			lastRange_ = delayedRange_;
			delayedRange_ = NULL;
			this->foundRange = true;
			assert_eq(range().cost, iminCost);
			if(!active_.empty()) {
				assert_geq(active_[0]->minCost, this->minCost);
				this->minCost = max(active_[0]->minCost, this->minCost);
			} else {
				this->done = true;
			}
			return; // found a range
		}
		assert(delayedRange_ == NULL);
		if(mateEliminated() || actSz == 0) {
			// No more alternatoves; clear the active set and signal
			// we're done
			active_.clear();
			this->done = true;
			return;
		}
		// Advance lowest-cost RangeSourceDriver
		TRangeSrcDrPtr p = active_[0];
		uint16_t precost = p->minCost;
		assert(!p->done || p->foundRange);
		if(!p->foundRange) {
			p->advance(until);
		}
		bool needsSort = false;
		if(p->foundRange) {
			Range *r = &p->range();
			assert_eq(r->cost, iminCost);
			needsSort = foundFirstRange(r); // may set delayedRange_; re-sorts active_
			assert_eq(lastRange_->cost, iminCost);
			if(delayedRange_ != NULL) assert_eq(delayedRange_->cost, iminCost);
			p->foundRange = false;
		}
		if(p->done || (precost != p->minCost) || needsSort) {
			sortActives();
			if(mateEliminated() || active_.empty()) {
				active_.clear();
				this->done = (delayedRange_ == NULL);
			}
		}
		assert(sortedActives());
		assert(lastRange_ == NULL || lastRange_->cost == iminCost);
		assert(delayedRange_ == NULL || delayedRange_->cost == iminCost);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movq $0x0, 0x70(%rdi)
addq $0x30, %rdi
callq 0x4a490
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x18(%rbp)
cmpq $0x0, 0x78(%rax)
je 0x4a711
movq -0x38(%rbp), %rdi
movq 0x78(%rdi), %rax
movq %rax, 0x70(%rdi)
movq $0x0, 0x78(%rdi)
movb $0x1, 0x8(%rdi)
addq $0x30, %rdi
callq 0x4adb0
testb $0x1, %al
jne 0x4a704
movq -0x38(%rbp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4a4b0
movq -0x38(%rbp), %rsi
movq (%rax), %rdi
addq $0xa, %rdi
addq $0xa, %rsi
callq 0x499e0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movw (%rcx), %cx
movw %cx, 0xa(%rax)
jmp 0x4a70c
movq -0x38(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x4a82a
movq -0x38(%rbp), %rdi
callq 0x4add0
testb $0x1, %al
jne 0x4a725
cmpq $0x0, -0x18(%rbp)
jne 0x4a73f
movq -0x38(%rbp), %rdi
addq $0x30, %rdi
callq 0x4a4e0
movq -0x38(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x4a82a
movq -0x38(%rbp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4a4b0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movw 0xa(%rax), %ax
movw %ax, -0x22(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x8(%rax)
jne 0x4a77a
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
movq (%rdi), %rax
callq *0x20(%rax)
movb $0x0, -0x23(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x8(%rax)
je 0x4a7c0
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq -0x38(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
callq 0x4aea0
movb %al, %cl
movq -0x38(%rbp), %rax
andb $0x1, %cl
movb %cl, -0x23(%rbp)
cmpq $0x0, 0x78(%rax)
je 0x4a7b8
jmp 0x4a7b8
movq -0x20(%rbp), %rax
movb $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
testb $0x1, 0x9(%rax)
jne 0x4a7e0
movzwl -0x22(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jne 0x4a7e0
testb $0x1, -0x23(%rbp)
je 0x4a82a
movq -0x38(%rbp), %rdi
callq 0x4aa40
movq -0x38(%rbp), %rdi
callq 0x4add0
testb $0x1, %al
jne 0x4a809
movq -0x38(%rbp), %rdi
addq $0x30, %rdi
callq 0x4adb0
testb $0x1, %al
jne 0x4a809
jmp 0x4a828
movq -0x38(%rbp), %rdi
addq $0x30, %rdi
callq 0x4a4e0
movq -0x38(%rbp), %rax
cmpq $0x0, 0x78(%rax)
sete %cl
andb $0x1, %cl
movb %cl, 0x9(%rax)
jmp 0x4a82a
addq $0x40, %rsp
popq %rbp
retq