// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./aligner.h
// Function: PairedBWAlignerV1<EbwtRangeSource>::resolveOutstandingInRef(bool, std::pair<unsigned int, unsigned int> const&, unsigned int, Range const&)
bool resolveOutstandingInRef(const bool off1,
	                             const UPair& off,
	                             const TIndexOffU tlen,
	                             const Range& range)
	{
		assert(refs_->loaded());
		assert_lt(off.first, refs_->numRefs());
		// If matchRight is true, then we're trying to align the other
		// mate to the right of the already-aligned mate.  Otherwise,
		// to the left.
		bool matchRight = (off1 ? !doneFw_ : doneFw_);
		// Sequence and quals for mate to be matched
		bool fw = off1 ? fw2_ : fw1_; // whether outstanding mate is fw/rc
		if(doneFw_) fw = !fw;
		// 'seq' gets sequence of outstanding mate w/r/t the forward
		// reference strand
		const BTDnaString& seq  = fw ? (off1 ? patsrc_->bufb().patFw   :
		                                        patsrc_->bufa().patFw)  :
		                                (off1 ? patsrc_->bufb().patRc   :
		                                        patsrc_->bufa().patRc);
		// 'seq' gets qualities of outstanding mate w/r/t the forward
		// reference strand
		const BTString& qual = fw ? (off1 ? patsrc_->bufb().qual  :
		                                        patsrc_->bufa().qual) :
		                                (off1 ? patsrc_->bufb().qualRev  :
		                                        patsrc_->bufa().qualRev);
		uint32_t qlen = (uint32_t)seq.length();  // length of outstanding mate
		uint32_t alen = (off1 ? patsrc_->bufa().length() :
		                        patsrc_->bufb().length());
		int minins = minInsert_;
		int maxins = maxInsert_;
		// Let minins and maxins be the minimum and maximum insert
		// lengths once we account for the trimming applied to the
		// mates.  The idea is that the insert constraint placed by
		// the user applies to the raw reads, not the trimmed reads.
		if(fw1_) {
			minins = max<int>(0, minins - patsrc_->bufa().trimmed5);
			maxins = max<int>(0, maxins - patsrc_->bufa().trimmed5);
		} else {
			minins = max<int>(0, minins - patsrc_->bufa().trimmed3);
			maxins = max<int>(0, maxins - patsrc_->bufa().trimmed3);
		}
		if(fw2_) {
			minins = max<int>(0, minins - patsrc_->bufb().trimmed3);
			maxins = max<int>(0, maxins - patsrc_->bufb().trimmed3);
		} else {
			minins = max<int>(0, minins - patsrc_->bufb().trimmed5);
			maxins = max<int>(0, maxins - patsrc_->bufb().trimmed5);
		}
		// Sanity check minins and maxins
		assert_geq(minins, 0);
		assert_geq(maxins, 0);
		assert_geq(maxins, minins);
		// Don't even try if either of the mates is longer than the
		// maximum insert size.
		if((uint32_t)maxins <= max(qlen, alen)) {
			return false;
		}
		const TIndexOffU tidx = off.first;
		const TIndexOffU toff = off.second;
		// Set begin/end to be a range of all reference
		// positions that are legally permitted to be involved in
		// the alignment of the outstanding mate.
		//
		// Note that one of the constraints imposed on which positions
		// go into this range is that the opposite mate cannot be
		// contained entirely within the anchor mate, or vice versa.
		TIndexOffU begin, end;
		TIndexOffU insDiff = maxins - minins;
		if(matchRight) {
			end = toff + maxins;
			// Adding 1 disallows the opposite from starting at the
			// left-hand edge of the anchor mate.
			begin = toff + (gAllowMateContainment ? 0 : 1);
			// We can also add a bit more if qlen is less than alen,
			// since we're requiring that opposite not be contained
			// within anchor.
			if(!gAllowMateContainment && qlen < alen) {
				begin += alen-qlen;
			}
			if(end > insDiff + qlen) {
				begin = max<TIndexOffU>(begin, end - insDiff - qlen);
			}
			end = min<TIndexOffU>(refs_->approxLen(tidx), end);
			begin = min<TIndexOffU>(refs_->approxLen(tidx), begin);
		} else {
			if(toff + alen < (TIndexOffU)maxins) {
				begin = 0;
			} else {
				begin = toff + alen - maxins;
			}
			uint32_t mi = min<uint32_t>(alen, qlen);
			if(gAllowMateContainment) {
				end = toff + alen;
			} else {
				end = toff + mi - 1;
				end = min<TIndexOffU>(end, toff + alen - minins + qlen - 1);
				if(toff + alen + qlen < (uint32_t)minins + 1) end = 0;
			}
		}
		// Check if there's not enough space in the range to fit an
		// alignment for the outstanding mate.
		if(end - begin < qlen) return false;
		EList<Range> ranges;
		EList<TIndexOffU> offs;
		refAligner_->find(1, tidx, refs_, seq, qual, begin, end, ranges,
		                  offs, doneFw_ ? &pairs_rc_ : &pairs_fw_,
		                  toff, fw);
		assert_eq(ranges.size(), offs.size());
		for(size_t i = 0; i < ranges.size(); i++) {
			Range& r = ranges[i];
			// Fill in fields that aren't filled in by the RefAligner
			r.fw = fw;
			r.cost |= (r.stratum << 14);
			r.mate1 = !off1;
			const TIndexOffU result = offs[i];
			// NOTE: We have no idea what the BW range delimiting the
			// opposite hit is, because we were operating entirely in
			// reference space when we found it.  For now, we just copy
			// the known range's top and bot for now.
			r.top = range.top;
			r.bot = range.bot;
			bool ebwtLFw = matchRight ? range.ebwt->fw() : true;
			bool ebwtRFw = matchRight ? true : range.ebwt->fw();
			if(report(
				matchRight ? range : r, // range for upstream mate
				matchRight ? r : range, // range for downstream mate
				tidx,                   // ref idx
				matchRight ? toff : result, // upstream offset
				matchRight ? result : toff, // downstream offset
				tlen,       // length of ref
				!doneFw_,   // whether the pair is being mapped to fw strand
				ebwtLFw,
				ebwtRFw)) return true;
		}
		return false;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %rbx
movq %rcx, 0x30(%rsp)
movzbl 0xb5(%rdi), %ebp
movl 0xb4(%rdi), %eax
testl %esi, %esi
movl %eax, %r8d
cmovnel %ebp, %r8d
movb 0x68(%rdi), %r15b
movq %rdi, 0x10(%rsp)
movq 0x58(%rdi), %r10
movq 0x50(%r10), %rcx
movl %r8d, 0x8(%rsp)
cmpb %r15b, %r8b
je 0x32e6a
testb %sil, %sil
je 0x32e90
movq 0x38(%r10), %rdi
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r8
addq %rdi, %r9
addq $0x60, %r9
jmp 0x32e8c
testb %sil, %sil
je 0x32ea8
movq 0x38(%r10), %rdi
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r8
addq $0x30, %r8
addq %rdi, %r9
addq $0xf0, %r9
pushq $0x18
jmp 0x32ec7
movq 0x18(%r10), %rdi
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r8
addq %rdi, %r9
addq $0x60, %r9
jmp 0x32ec5
movq 0x18(%r10), %rdi
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r8
addq $0x30, %r8
addq %rdi, %r9
addq $0xf0, %r9
pushq $0x38
popq %rdi
movq (%r10,%rdi), %rdi
imulq $0x268, %rcx, %r11      # imm = 0x268
movl 0x20(%rdi,%r11), %r14d
movq 0x10(%rsp), %rdi
movl 0x98(%rdi), %ecx
movl 0x9c(%rdi), %edi
movq 0x18(%r10), %r12
addq %r11, %r12
notb %al
movzbl %al, %eax
andl $0x1, %eax
movl 0x1a8(%r12,%rax,4), %eax
subl %eax, %ecx
xorl %r13d, %r13d
testl %ecx, %ecx
cmovlel %r13d, %ecx
subl %eax, %edi
testl %edi, %edi
cmovlel %r13d, %edi
movl 0x20(%r8), %eax
addq 0x38(%r10), %r11
movzbl %bpl, %r10d
andl $0x1, %r10d
movl 0x1a8(%r11,%r10,4), %r10d
subl %r10d, %ecx
testl %ecx, %ecx
cmovlel %r13d, %ecx
subl %r10d, %edi
testl %edi, %edi
cmovlel %r13d, %edi
cmpl %r14d, %eax
movl %r14d, %r10d
cmoval %eax, %r10d
cmpl %r10d, %edi
jbe 0x331d0
movl %r15d, %r10d
xorb %sil, %r10b
movb %r10b, 0x6(%rsp)
movl (%rdx), %r12d
movl 0x4(%rdx), %r13d
movzbl 0x32277(%rip), %edx     # 0x651e0
je 0x32fca
movl %r14d, %r11d
subl %eax, %r11d
xorl %r10d, %r10d
testl %edx, %edx
cmovnel %r10d, %r11d
cmpl %eax, %r14d
cmovbel %r10d, %r11d
leal (%rdi,%r13), %r10d
subl %ecx, %edi
xorl $0x1, %edx
addl %r13d, %edx
addl %r11d, %edx
addl %eax, %edi
movl %r10d, %r11d
subl %edi, %r11d
cmpl %r11d, %edx
cmoval %edx, %r11d
cmpl %edi, %r10d
cmovbel %edx, %r11d
movq 0x10(%rsp), %rcx
movq 0x50(%rcx), %rcx
movq 0x428(%rcx), %rcx
movl (%rcx,%r12,4), %ecx
cmpl %ecx, %r10d
cmovael %ecx, %r10d
cmpl %ecx, %r11d
cmovael %ecx, %r11d
jmp 0x33003
leal (%r14,%r13), %r10d
xorl %ebp, %ebp
movl %r10d, %r11d
subl %edi, %r11d
cmovbl %ebp, %r11d
testl %edx, %edx
jne 0x33003
cmpl %r14d, %eax
cmovbl %eax, %r14d
leal (%r14,%r13), %edx
decl %edx
movl %ecx, %edi
notl %edi
addl %eax, %r10d
addl %r10d, %edi
cmpl %edx, %edi
cmovael %edx, %edi
cmpl %ecx, %r10d
cmoval %edi, %ebp
movl %ebp, %r10d
movl %r10d, %ecx
subl %r11d, %ecx
cmpl %eax, %ecx
jae 0x33015
xorl %r13d, %r13d
jmp 0x331d0
movl %esi, 0xc(%rsp)
xorl %r14d, %r14d
movl %r15d, %esi
movl 0x8(%rsp), %r15d
cmpb %sil, %r15b
setne %r14b
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq 0x38(%rsp), %rax
movq %rcx, (%rax)
andq $0x0, 0x8(%rax)
movl $0x80, %edx
movq %rdx, 0x10(%rax)
andq $0x0, 0x18(%rax)
movq %r12, %rax
leaq 0x58(%rsp), %r12
movq %rcx, (%r12)
andq $0x0, 0x8(%r12)
movq %rdx, 0x10(%r12)
andq $0x0, 0x18(%r12)
movq 0x10(%rsp), %rdx
movq 0x50(%rdx), %rcx
movq 0x78(%rdx), %rdi
movq %r13, %rbp
leaq 0x2248(%rdx), %r13
addq $0x2278, %rdx           # imm = 0x2278
movb %sil, 0x7(%rsp)
testb %sil, %sil
cmovneq %rdx, %r13
movq (%rdi), %rdx
movq 0x10(%rdx), %rdx
movq %rdx, 0x18(%rsp)
subq $0x8, %rsp
pushq $0x1
popq %rsi
movq %rax, 0x30(%rsp)
movq %rax, %rdx
pushq %r14
movq %rbp, 0x30(%rsp)
pushq %rbp
pushq %r13
pushq %r12
leaq 0x60(%rsp), %rax
pushq %rax
pushq %r10
pushq %r11
callq *0x58(%rsp)
addq $0x40, %rsp
andb $0x1, %r15b
xorb 0x7(%rsp), %r15b
movl 0xc(%rsp), %eax
xorb $0x1, %al
movl %eax, 0xc(%rsp)
movb 0x6(%rsp), %al
xorb $0x1, %al
movb %al, 0x8(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
movl %r15d, %ecx
movq 0x10(%rsp), %r12
cmpq 0x50(%rsp), %r14
setb %r13b
jae 0x331bc
movq 0x40(%rsp), %rax
movl %ecx, %r15d
movb %cl, 0x14(%rax,%rbp)
movl 0xc(%rax,%rbp), %ecx
shll $0xe, %ecx
orw %cx, 0x8(%rax,%rbp)
movl 0xc(%rsp), %ecx
movb %cl, 0x15(%rax,%rbp)
movq 0x60(%rsp), %rcx
movl (%rcx,%r14,4), %r8d
movl (%rbx), %ecx
movl %ecx, (%rax,%rbp)
movl 0x4(%rbx), %ecx
movl %ecx, 0x4(%rax,%rbp)
movq 0x58(%rbx), %rcx
movb 0x10(%rcx), %cl
movb 0x8(%rsp), %dil
orb %cl, %dil
movb 0x6(%rsp), %r10b
testb %r10b, %r10b
movq 0x20(%rsp), %rdx
movl %edx, %r9d
cmovnel %r8d, %r9d
cmovnel %edx, %r8d
leaq (%rax,%rbp), %rsi
movq %rbx, %rdx
cmovneq %rsi, %rdx
cmovneq %rbx, %rsi
orb %r10b, %cl
movzbl 0x68(%r12), %eax
xorl $0x1, %eax
movzbl %cl, %r10d
andl $0x1, %r10d
movzbl %dil, %r11d
andl $0x1, %r11d
movq %r12, %rdi
movq 0x28(%rsp), %rcx
pushq %r10
pushq %r11
pushq %rax
pushq 0x48(%rsp)
callq 0x33204
addq $0x20, %rsp
incq %r14
addq $0x60, %rbp
testb %al, %al
movl %r15d, %ecx
je 0x330fa
leaq 0x58(%rsp), %rdi
callq 0x1c1c4
leaq 0x38(%rsp), %rdi
callq 0x2ee06
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x331e4
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x1c1c4
leaq 0x38(%rsp), %rdi
callq 0x2ee06
movq %rbx, %rdi
callq 0x9950
nop