// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %r8, %rbx
movq %rcx, 0x20(%rsp)
movq %rdi, %r15
movb 0x68(%rdi), %al
movl %esi, 0xc(%rsp)
testl %esi, %esi
je 0x3c5c9
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0xa(%rsp)
movb 0xb5(%r15), %sil
movl %eax, %ecx
xorb %sil, %cl
movb %cl, 0xb(%rsp)
movq 0x58(%r15), %r10
movq 0x38(%r10), %rdi
movq 0x50(%r10), %rcx
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r11
cmpb %al, %sil
setne %sil
leaq 0x30(%rdi,%r9), %r8
leaq 0xf0(%rdi,%r9), %r14
cmovneq %r11, %r8
leaq 0x60(%rdi,%r9), %r9
cmoveq %r14, %r9
leaq 0x18(%r10), %rdi
jmp 0x3c618
movb 0xb4(%r15), %sil
movl %esi, %ecx
xorb %al, %cl
movb %cl, 0xb(%rsp)
movq 0x58(%r15), %r10
movq 0x18(%r10), %rdi
movq 0x50(%r10), %rcx
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r11
cmpb %al, %sil
setne %sil
leaq 0x60(%rdi,%r9), %r14
leaq 0x30(%rdi,%r9), %r8
leaq 0xf0(%rdi,%r9), %r9
cmovneq %r11, %r8
cmovneq %r14, %r9
leaq 0x38(%r10), %rdi
movb %al, 0xa(%rsp)
movq (%rdi), %rdi
imulq $0x268, %rcx, %r11      # imm = 0x268
movl 0x20(%rdi,%r11), %r12d
movl 0x20(%r8), %ecx
movl 0x98(%r15), %edi
movl 0x9c(%r15), %r14d
movzbl 0xb4(%r15), %r13d
movq 0x18(%r10), %rbp
addq %r11, %rbp
xorl $0x1, %r13d
movl 0x1a8(%rbp,%r13,4), %ebp
subl %ebp, %edi
xorl %r13d, %r13d
testl %edi, %edi
cmovlel %r13d, %edi
subl %ebp, %r14d
testl %r14d, %r14d
cmovlel %r13d, %r14d
addq 0x38(%r10), %r11
movzbl 0xb5(%r15), %r10d
movl 0x1a8(%r11,%r10,4), %r10d
subl %r10d, %edi
testl %edi, %edi
cmovlel %r13d, %edi
subl %r10d, %r14d
testl %r14d, %r14d
cmovlel %r13d, %r14d
cmpl %r12d, %ecx
movl %r12d, %r10d
cmoval %ecx, %r10d
cmpl %r10d, %r14d
jbe 0x3c902
movl (%rdx), %r13d
movl 0x4(%rdx), %ebp
movzbl 0x30b20(%rip), %edx     # 0x6d1d0
cmpb $0x0, 0xa(%rsp)
movq %r13, 0x10(%rsp)
je 0x3c717
movl %r12d, %r11d
subl %ecx, %r11d
xorl %r10d, %r10d
testl %edx, %edx
cmovnel %r10d, %r11d
cmpl %ecx, %r12d
cmovbel %r10d, %r11d
leal (%r14,%rbp), %r10d
subl %edi, %r14d
xorl $0x1, %edx
addl %ebp, %edx
addl %r11d, %edx
addl %ecx, %r14d
movl %r10d, %r11d
subl %r14d, %r11d
cmpl %r11d, %edx
cmoval %edx, %r11d
cmpl %r14d, %r10d
cmovbel %edx, %r11d
movq 0x50(%r15), %rdx
movq 0x428(%rdx), %rdx
movl (%rdx,%r13,4), %edx
cmpl %edx, %r10d
cmovael %edx, %r10d
cmpl %edx, %r11d
cmovael %edx, %r11d
jmp 0x3c766
movl %esi, %r13d
leal (%r12,%rbp), %r10d
movq %rbp, %rsi
xorl %ebp, %ebp
movl %r10d, %r11d
subl %r14d, %r11d
cmovbl %ebp, %r11d
testl %edx, %edx
jne 0x3c75b
cmpl %r12d, %ecx
cmovbl %ecx, %r12d
leal (%r12,%rsi), %edx
decl %edx
movl %edi, %r14d
notl %r14d
addl %ecx, %r10d
addl %r10d, %r14d
cmpl %edx, %r14d
cmovael %edx, %r14d
cmpl %edi, %r10d
cmoval %r14d, %ebp
movl %ebp, %r10d
movq %rsi, %rbp
movl %r13d, %esi
movq 0x10(%rsp), %r13
movl %r10d, %edx
subl %r11d, %edx
cmpl %ecx, %edx
jae 0x3c778
xorl %r13d, %r13d
jmp 0x3c902
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq 0x28(%rsp), %r14
movq %rcx, (%r14)
xorl %edx, %edx
movq %rdx, 0x8(%r14)
movl $0x80, %edi
movq %rdi, 0x10(%r14)
movq %rdx, 0x18(%r14)
leaq 0x48(%rsp), %r12
movq %rcx, (%r12)
movq %rdx, 0x8(%r12)
movq %rdi, 0x10(%r12)
movq %rdx, 0x18(%r12)
movq 0x50(%r15), %rcx
movq 0x78(%r15), %rdi
movq %r13, %rdx
leaq 0x2248(%r15), %r13
movq %rbp, 0x18(%rsp)
leaq 0x2278(%r15), %rbp
testb %al, %al
cmovneq %rbp, %r13
movq (%rdi), %rax
movq 0x10(%rax), %rax
subq $0x8, %rsp
movzbl %sil, %ebp
movl $0x1, %esi
pushq %rbp
pushq 0x28(%rsp)
pushq %r13
pushq %r12
pushq %r14
pushq %r10
pushq %r11
callq *%rax
addq $0x40, %rsp
cmpq $0x0, 0x40(%rsp)
je 0x3c8e6
movl 0xc(%rsp), %eax
xorb $0x1, %al
movl %eax, 0xc(%rsp)
movb 0xa(%rsp), %bpl
xorb $0x1, %bpl
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x30(%rsp), %rax
movb 0xb(%rsp), %cl
movb %cl, 0x14(%rax,%r14)
movl 0xc(%rax,%r14), %ecx
shll $0xe, %ecx
orw %cx, 0x8(%rax,%r14)
movl 0xc(%rsp), %ecx
movb %cl, 0x15(%rax,%r14)
movq 0x50(%rsp), %rcx
movl (%rcx,%r12,4), %r8d
movl (%rbx), %ecx
movl %ecx, (%rax,%r14)
movl 0x4(%rbx), %ecx
movl %ecx, 0x4(%rax,%r14)
movq 0x58(%rbx), %rcx
movb 0x10(%rcx), %cl
movl %ebp, %edi
orb %cl, %dil
movb 0xa(%rsp), %r10b
testb %r10b, %r10b
movq 0x18(%rsp), %rdx
movl %edx, %r9d
cmovnel %r8d, %r9d
cmovnel %edx, %r8d
leaq (%rax,%r14), %rsi
movq %rbx, %rdx
cmovneq %rsi, %rdx
cmovneq %rbx, %rsi
orb %r10b, %cl
movzbl 0x68(%r15), %eax
xorl $0x1, %eax
movzbl %cl, %r10d
andl $0x1, %r10d
movzbl %dil, %r11d
andl $0x1, %r11d
movq %r15, %rdi
movq 0x10(%rsp), %rcx
pushq %r10
pushq %r11
pushq %rax
pushq 0x38(%rsp)
callq 0x3c93a
addq $0x20, %rsp
movl %eax, %r13d
testb %al, %al
jne 0x3c8e9
incq %r12
addq $0x60, %r14
cmpq 0x40(%rsp), %r12
jb 0x3c827
jmp 0x3c8e9
xorl %r13d, %r13d
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3c8f8
callq 0x95e0
leaq 0x28(%rsp), %rdi
callq 0x37cba
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c916
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3c928
callq 0x95e0
leaq 0x28(%rsp), %rdi
callq 0x37cba
movq %rbx, %rdi
callq 0x9930