// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./aligner.h
// Function: PairedBWAlignerV2<EbwtRangeSource>::resolveOutstandingInRef(std::pair<unsigned int, unsigned int> const&, unsigned int, Range const&)
bool resolveOutstandingInRef(const UPair& off,
	                             const TIndexOffU tlen,
	                             const Range& range)
	{
		assert(!donePe_);
		assert(refs_->loaded());
		assert_lt(off.first, refs_->numRefs());
		// pairFw = true if the anchor indicates that the pair will
		// align in its forward orientation (i.e. with mate1 to the
		// left of mate2)
		bool pairFw = (range.mate1)? (range.fw == fw1_) : (range.fw == fw2_);
		// matchRight = true, if the opposite mate will be to the right
		// of the anchor mate
		bool matchRight = (pairFw ? range.mate1 : !range.mate1);
		// fw = orientation of the opposite mate
		bool fw = range.mate1 ? fw2_ : fw1_; // whether outstanding mate is fw/rc
		if(!pairFw) fw = !fw;
		// 'seq' = sequence for opposite mate
		const BTDnaString& seq  =
			fw ? (range.mate1 ? patsrc_->bufb().patFw   :
		                        patsrc_->bufa().patFw)  :
		         (range.mate1 ? patsrc_->bufb().patRc   :
		                        patsrc_->bufa().patRc);
		// 'qual' = qualities for opposite mate
		const BTString& qual =
			fw ? (range.mate1 ? patsrc_->bufb().qual  :
			                    patsrc_->bufa().qual) :
			     (range.mate1 ? patsrc_->bufb().qualRev :
			                    patsrc_->bufa().qualRev);
		uint32_t qlen = (uint32_t)seq.length();  // length of outstanding mate
		uint32_t alen = (range.mate1 ? patsrc_->bufa().length() :
		                               patsrc_->bufb().length());
		int minins = minInsert_;
		int maxins = maxInsert_;
		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);
		}
		assert_geq(minins, 0);
		assert_geq(maxins, 0);
		// 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;  // text id where anchor mate hit
		const TIndexOffU toff = off.second; // offset where anchor mate hit
		// Set begin/end to the range of reference positions where
		// outstanding mate may align while fulfilling insert-length
		// constraints.
		TIndexOffU begin, end;
		assert_geq(maxins, minins);
		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 - 1;
			} else {
				end = toff + mi - 1;
				end = min<TIndexOffU>(end, toff + alen - minins + qlen - 1);
				if(toff + alen + qlen < (TIndexOffU)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, pairFw ? &pairs_fw_ : &pairs_rc_,
		                  toff, fw);
		assert_eq(ranges.size(), offs.size());
		for(size_t i = 0; i < ranges.size(); i++) {
			Range& r = ranges[i];
			r.fw = fw;
			r.cost |= (r.stratum << 14);
			r.mate1 = !range.mate1;
			const TIndexOffU result = offs[i];
			// 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
				pairFw,     // 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 %rcx, %rbx
movq %rdx, 0x30(%rsp)
movq %rdi, %r13
movb 0x14(%rcx), %al
movb 0x15(%rcx), %dil
cmpb $0x1, %dil
jne 0x33b88
movb $0x1, %r8b
movb $0x1, %cl
movl %ecx, 0xc(%rsp)
cmpb 0xc0(%r13), %al
je 0x33ba9
jmp 0x33b9e
cmpb 0xc1(%r13), %al
jne 0x33b9e
movb $0x1, %r8b
movl $0x0, 0xc(%rsp)
jmp 0x33ba9
movl %edi, %eax
xorb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r8d, %r8d
movzbl 0xc1(%r13), %edx
movl 0xc0(%r13), %eax
testb %dil, %dil
movl %eax, %r12d
cmovnel %edx, %r12d
movl %r8d, %r9d
xorb $0x1, %r9b
movq 0x58(%r13), %r10
movq 0x50(%r10), %rcx
cmpb %r9b, %r12b
movl %r8d, 0x14(%rsp)
movb %r9b, 0x10(%rsp)
je 0x33bfd
testb %dil, %dil
je 0x33c23
movq 0x38(%r10), %rdi
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r8
addq %rdi, %r9
addq $0x60, %r9
jmp 0x33c1f
testb %dil, %dil
je 0x33c3b
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 0x33c5a
movq 0x18(%r10), %rdi
imulq $0x268, %rcx, %r9       # imm = 0x268
leaq (%rdi,%r9), %r8
addq %rdi, %r9
addq $0x60, %r9
jmp 0x33c58
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
movl 0xb0(%r13), %ecx
movl 0xb4(%r13), %edi
movq 0x18(%r10), %r15
addq %r11, %r15
notb %al
movzbl %al, %eax
andl $0x1, %eax
movl 0x1a8(%r15,%rax,4), %eax
subl %eax, %ecx
xorl %ebp, %ebp
testl %ecx, %ecx
cmovlel %ebp, %ecx
subl %eax, %edi
testl %edi, %edi
cmovlel %ebp, %edi
movl 0x20(%r8), %eax
addq 0x38(%r10), %r11
movzbl %dl, %edx
andl $0x1, %edx
movl 0x1a8(%r11,%rdx,4), %edx
subl %edx, %ecx
testl %ecx, %ecx
cmovlel %ebp, %ecx
subl %edx, %edi
testl %edi, %edi
cmovlel %ebp, %edi
cmpl %r14d, %eax
movl %r14d, %edx
cmoval %eax, %edx
cmpl %edx, %edi
jbe 0x33f30
movl (%rsi), %r15d
movl 0x4(%rsi), %ebp
movzbl 0x314fe(%rip), %edx     # 0x651e0
cmpb $0x0, 0xc(%rsp)
je 0x33d40
movl %r14d, %esi
subl %eax, %esi
xorl %r10d, %r10d
testl %edx, %edx
cmovnel %r10d, %esi
cmpl %eax, %r14d
cmovbel %r10d, %esi
leal (%rdi,%rbp), %r10d
subl %ecx, %edi
xorl $0x1, %edx
addl %ebp, %edx
addl %esi, %edx
addl %eax, %edi
movl %r10d, %r11d
subl %edi, %r11d
cmpl %r11d, %edx
cmoval %edx, %r11d
cmpl %edi, %r10d
cmovbel %edx, %r11d
movq 0x50(%r13), %rcx
movq 0x428(%rcx), %rcx
movl (%rcx,%r15,4), %ecx
cmpl %ecx, %r10d
cmovael %ecx, %r10d
cmpl %ecx, %r11d
cmovael %ecx, %r11d
jmp 0x33d7e
leal (%r14,%rbp), %r10d
xorl %esi, %esi
movl %r10d, %r11d
subl %edi, %r11d
cmovbl %esi, %r11d
testl %edx, %edx
je 0x33d59
decl %r10d
jmp 0x33d7e
cmpl %r14d, %eax
cmovbl %eax, %r14d
leal (%r14,%rbp), %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, %esi
movl %esi, %r10d
movl %r10d, %ecx
subl %r11d, %ecx
cmpl %eax, %ecx
jae 0x33d8f
xorl %ebp, %ebp
jmp 0x33f30
xorl %r14d, %r14d
cmpb 0x10(%rsp), %r12b
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 %r15, %rax
leaq 0x58(%rsp), %rsi
movq %rcx, (%rsi)
andq $0x0, 0x8(%rsi)
movq %rdx, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
movq 0x50(%r13), %rcx
movq 0x70(%r13), %rdi
movq %rbp, %r15
movl %r12d, %ebp
leaq 0x120(%r13), %r12
movq %r13, 0x28(%rsp)
leaq 0xf0(%r13), %rdx
cmpb $0x0, 0x14(%rsp)
cmovneq %rdx, %r12
movq (%rdi), %rdx
movq 0x10(%rdx), %r13
subq $0x8, %rsp
pushq $0x1
popq %rsi
movq %rax, 0x28(%rsp)
movq %rax, %rdx
pushq %r14
movq %r15, 0x28(%rsp)
pushq %r15
pushq %r12
leaq 0x78(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
pushq %r10
pushq %r11
callq *%r13
addq $0x40, %rsp
andb $0x1, %bpl
xorb 0x10(%rsp), %bpl
movl %ebp, 0x10(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r14d
xorb $0x1, %r14b
xorl %r13d, %r13d
movzbl 0x14(%rsp), %r15d
xorl %r12d, %r12d
cmpq 0x50(%rsp), %r12
setb %bpl
jae 0x33f1c
movq 0x40(%rsp), %rax
movl 0x10(%rsp), %ecx
movb %cl, 0x14(%rax,%r13)
movl 0xc(%rax,%r13), %ecx
shll $0xe, %ecx
orw %cx, 0x8(%rax,%r13)
movb 0x15(%rbx), %cl
xorb $0x1, %cl
movb %cl, 0x15(%rax,%r13)
movq 0x60(%rsp), %rcx
movl (%rcx,%r12,4), %r8d
movl (%rbx), %ecx
movl %ecx, (%rax,%r13)
movl 0x4(%rbx), %ecx
movl %ecx, 0x4(%rax,%r13)
movq 0x58(%rbx), %rcx
movb 0x10(%rcx), %cl
movl %r14d, %edi
orb %cl, %dil
movl 0xc(%rsp), %r10d
testb %r10b, %r10b
movq 0x18(%rsp), %rdx
movl %edx, %r9d
cmovnel %r8d, %r9d
cmovnel %edx, %r8d
leaq (%rax,%r13), %rsi
movq %rbx, %rdx
cmovneq %rsi, %rdx
cmovneq %rbx, %rsi
orb %r10b, %cl
movzbl %cl, %eax
andl $0x1, %eax
movzbl %dil, %r10d
andl $0x1, %r10d
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rcx
pushq %rax
pushq %r10
pushq %r15
pushq 0x48(%rsp)
callq 0x340c2
addq $0x20, %rsp
incq %r12
addq $0x60, %r13
testb %al, %al
je 0x33e5f
leaq 0x58(%rsp), %rdi
callq 0x1c1c4
leaq 0x38(%rsp), %rdi
callq 0x2ee06
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x33f43
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x1c1c4
leaq 0x38(%rsp), %rdi
callq 0x2ee06
movq %rbx, %rdi
callq 0x9950