// File: BenLangmead[P]bowtie/./range_source.h
// Function: Branch::curtail(AllocOnlyPool<RangeState>&, int, bool)
void curtail(AllocOnlyPool<RangeState>& rpool, int seedLen, bool qualOrder) {
		assert(!curtailed_);
		assert(!exhausted_);
		if(ranges_ == NULL) {
			exhausted_ = true;
			curtailed_ = true;
			return;
		}
		uint16_t lowestCost = 0xffff;
		// Iterate over positions in the path looking for the cost of
		// the lowest-cost non-eliminated position
		uint32_t eliminatedStretch = 0;
		int i = (int)depth0_;
		i = max(0, i - rdepth_);
		// TODO: It matters whether an insertion/deletion at given
		// position would be a gap open or a gap extension
		for(; i <= len_; i++) {
			if(!eliminated(i)) {
				eliminatedStretch = 0;
				uint16_t stratum = (rdepth_ + i < seedLen) ? (1 << 14) : 0;
				uint16_t cost = (qualOrder ? /*TODO*/ ranges_[i].eq.flags.quallo : 0) | stratum;
				if(cost < lowestCost) lowestCost = cost;
			} else if(i < rangesSz_) {
				eliminatedStretch++;
			}
		}
		if(lowestCost > 0 && lowestCost != 0xffff) {
			// This branch's cost will change when curtailed; the
			// caller should re-insert it into the priority queue so
			// that the new cost takes effect.
			cost_ += lowestCost;
		} else if(lowestCost == 0xffff) {
			// This branch is totally exhausted; there are no more
			// valid outgoing paths from any positions within it.
			// Remove it from the PathManager and mark it as exhausted.
			// The caller should delete it.
			exhausted_ = true;
			if(ranges_ != NULL) {
				assert_gt(rangesSz_, 0);
				if(rpool.free(ranges_, rangesSz_)) {
					ranges_ = NULL;
					rangesSz_ = 0;
				}
			}
		} else {
			// Just mark it as curtailed and keep the same cost
		}
		if(ranges_ != NULL) {
			// Try to trim off no-longer-relevant elements of the
			// ranges_ array
			assert(!exhausted_);
			assert_gt(rangesSz_, 0);
			uint32_t trim = (rangesSz_ - len_ - 1) + eliminatedStretch;
			assert_leq(trim, rangesSz_);
			if(rpool.free(ranges_ + rangesSz_ - trim, trim)) {
				rangesSz_ -= trim;
				if(rangesSz_ == 0) {
					ranges_ = NULL;
				}
			}
		}
		curtailed_ = true;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, 0x18(%rax)
jne 0x45320
movq -0x38(%rbp), %rax
movb $0x1, 0x83(%rax)
movb $0x1, 0x82(%rax)
jmp 0x45528
movq -0x38(%rbp), %rcx
movw $0xffff, -0x18(%rbp)    # imm = 0xFFFF
movl $0x0, -0x1c(%rbp)
movzwl 0x4(%rcx), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x20(%rbp), %eax
movzwl 0xc(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x28(%rbp)
leaq -0x24(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x31970
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %eax
movzwl 0xe(%rcx), %ecx
cmpl %ecx, %eax
jg 0x45423
movq -0x38(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x45600
testb $0x1, %al
jne 0x453f9
movq -0x38(%rbp), %rax
movl $0x0, -0x1c(%rbp)
movzwl 0xc(%rax), %edx
addl -0x20(%rbp), %edx
movl -0x14(%rbp), %esi
xorl %eax, %eax
movl $0x4000, %ecx           # imm = 0x4000
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x2a(%rbp)
testb $0x1, -0x15(%rbp)
je 0x453cf
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x20(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
shrq $0x29, %rax
andq $0x7f, %rax
movl %eax, -0x3c(%rbp)
jmp 0x453d6
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0x453d6
movl -0x3c(%rbp), %eax
movzwl -0x2a(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x2c(%rbp)
movzwl -0x2c(%rbp), %eax
movzwl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0x453f7
movw -0x2c(%rbp), %ax
movw %ax, -0x18(%rbp)
jmp 0x45413
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %eax
movzwl 0x20(%rcx), %ecx
cmpl %ecx, %eax
jge 0x45411
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x45413
jmp 0x45415
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4535d
movzwl -0x18(%rbp), %eax
cmpl $0x0, %eax
jle 0x4544b
movzwl -0x18(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x4544b
movq -0x38(%rbp), %rax
movzwl -0x18(%rbp), %edx
movzwl 0x10(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x10(%rax)
jmp 0x4549d
movzwl -0x18(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x45499
movq -0x38(%rbp), %rax
movb $0x1, 0x83(%rax)
cmpq $0x0, 0x18(%rax)
je 0x45497
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x18(%rax), %rsi
movzwl 0x20(%rax), %edx
callq 0x45660
testb $0x1, %al
jne 0x45483
jmp 0x45495
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movw $0x0, 0x20(%rax)
jmp 0x45497
jmp 0x4549b
jmp 0x4549b
jmp 0x4549d
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x4551d
movq -0x38(%rbp), %rax
movzwl 0x20(%rax), %ecx
movzwl 0xe(%rax), %edx
subl %edx, %ecx
subl $0x1, %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq 0x18(%rax), %rsi
movzwl 0x20(%rax), %eax
cltq
imulq $0x30, %rax, %rax
addq %rax, %rsi
movl -0x30(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
subq %rcx, %rax
imulq $0x30, %rax, %rax
addq %rax, %rsi
movl -0x30(%rbp), %edx
callq 0x45660
testb $0x1, %al
jne 0x454f3
jmp 0x4551b
movq -0x38(%rbp), %rax
movl -0x30(%rbp), %edx
movzwl 0x20(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x20(%rax)
movzwl 0x20(%rax), %eax
cmpl $0x0, %eax
jne 0x45519
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0x4551b
jmp 0x4551d
movq -0x38(%rbp), %rax
movb $0x1, 0x82(%rax)
addq $0x40, %rsp
popq %rbp
retq
nop