// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movb 0x14(%rcx), %al
cmpb $0x1, 0x15(%rcx)
jne 0x3d368
movb 0xc0(%r12), %dl
movb 0xc1(%r12), %cl
cmpb %dl, %al
sete 0xb(%rsp)
jne 0x3d38d
movl %ecx, %r13d
testb $0x1, %cl
jne 0x3d40d
movl %ecx, %r13d
jmp 0x3d397
movb 0xc0(%r12), %dl
movb 0xc1(%r12), %cl
cmpb %cl, %al
sete 0x10(%rsp)
jne 0x3d3c6
movl %edx, %r13d
testb %dl, %dl
je 0x3d3d6
jmp 0x3d446
cmpb $0x1, %cl
jne 0x3d406
movb $0x1, %cl
xorl %r13d, %r13d
movq 0x58(%r12), %rdi
movq 0x38(%rdi), %rax
movq 0x50(%rdi), %r10
imulq $0x268, %r10, %r9       # imm = 0x268
leaq (%rax,%r9), %r8
addq $0x30, %r8
addq %r9, %rax
addq $0xf0, %rax
movq %rax, 0x18(%rsp)
xorl %r9d, %r9d
jmp 0x3d434
movb $0x1, %r13b
testb %dl, %dl
je 0x3d444
movl %edx, %r13d
xorb $0x1, %r13b
movb $0x1, %dl
movq 0x58(%r12), %rdi
movq 0x18(%rdi), %r9
movq 0x50(%rdi), %r10
imulq $0x268, %r10, %r11      # imm = 0x268
leaq (%r9,%r11), %r8
addq $0x30, %r8
addq %r11, %r9
addq $0xf0, %r9
movq %r9, 0x18(%rsp)
xorl %r9d, %r9d
jmp 0x3d46d
movl %ecx, %r13d
xorb $0x1, %r13b
movq 0x58(%r12), %rdi
movq 0x38(%rdi), %rax
movq 0x50(%rdi), %r10
imulq $0x268, %r10, %r9       # imm = 0x268
leaq (%rax,%r9), %r8
addq %r9, %rax
addq $0x60, %rax
movq %rax, 0x18(%rsp)
movb $0x1, %r9b
leaq 0x18(%rdi), %rax
movb 0xb(%rsp), %r11b
movb %r11b, 0x10(%rsp)
jmp 0x3d478
xorl %edx, %edx
movq 0x58(%r12), %rdi
movq 0x18(%rdi), %r9
movq 0x50(%rdi), %r10
imulq $0x268, %r10, %r11      # imm = 0x268
leaq (%r9,%r11), %r8
addq %r11, %r9
addq $0x60, %r9
movq %r9, 0x18(%rsp)
movb $0x1, %r9b
cmpb %cl, %al
setne 0xb(%rsp)
leaq 0x38(%rdi), %rax
movq (%rax), %rax
imulq $0x268, %r10, %r10      # imm = 0x268
movl 0x20(%rax,%r10), %r15d
movl 0xb0(%r12), %eax
movl 0xb4(%r12), %r14d
movq 0x18(%rdi), %r11
addq %r10, %r11
xorb $0x1, %dl
movzbl %dl, %edx
movl 0x1a8(%r11,%rdx,4), %edx
subl %edx, %eax
xorl %ebp, %ebp
testl %eax, %eax
cmovlel %ebp, %eax
subl %edx, %r14d
testl %r14d, %r14d
cmovlel %ebp, %r14d
movl 0x20(%r8), %edx
addq 0x38(%rdi), %r10
movzbl %cl, %ecx
andl $0x1, %ecx
movl 0x1a8(%r10,%rcx,4), %ecx
subl %ecx, %eax
testl %eax, %eax
cmovlel %ebp, %eax
subl %ecx, %r14d
testl %r14d, %r14d
cmovlel %ebp, %r14d
cmpl %r15d, %edx
movl %r15d, %ecx
cmoval %edx, %ecx
cmpl %ecx, %r14d
jbe 0x3d74c
movl %r13d, 0xc(%rsp)
movl (%rsi), %ebp
movl 0x4(%rsi), %r13d
movzbl 0x2fcc6(%rip), %ecx     # 0x6d1d0
cmpb $0x0, 0xb(%rsp)
je 0x3d568
movl %r15d, %esi
subl %edx, %esi
xorl %edi, %edi
testl %ecx, %ecx
cmovnel %edi, %esi
cmpl %edx, %r15d
cmovbel %edi, %esi
leal (%r14,%r13), %r10d
subl %eax, %r14d
xorl $0x1, %ecx
addl %r13d, %ecx
addl %esi, %ecx
addl %edx, %r14d
movl %r10d, %r11d
subl %r14d, %r11d
cmpl %r11d, %ecx
cmoval %ecx, %r11d
cmpl %r14d, %r10d
cmovbel %ecx, %r11d
movq 0x50(%r12), %rax
movq 0x428(%rax), %rax
movl (%rax,%rbp,4), %eax
cmpl %eax, %r10d
cmovael %eax, %r10d
cmpl %eax, %r11d
cmovael %eax, %r11d
jmp 0x3d5a6
leal (%r15,%r13), %r10d
xorl %esi, %esi
movl %r10d, %r11d
subl %r14d, %r11d
cmovbl %esi, %r11d
testl %ecx, %ecx
je 0x3d581
decl %r10d
jmp 0x3d5a6
cmpl %r15d, %edx
cmovbl %edx, %r15d
leal (%r15,%r13), %ecx
decl %ecx
movl %eax, %edi
notl %edi
addl %edx, %r10d
addl %r10d, %edi
cmpl %ecx, %edi
cmovael %ecx, %edi
cmpl %eax, %r10d
cmoval %edi, %esi
movl %esi, %r10d
movl %r10d, %eax
subl %r11d, %eax
cmpl %edx, %eax
jae 0x3d5b7
xorl %ebp, %ebp
jmp 0x3d74c
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq 0x38(%rsp), %rax
movq %rcx, (%rax)
xorl %edx, %edx
movq %rdx, 0x8(%rax)
movl $0x80, %esi
movq %rsi, 0x10(%rax)
movq %rdx, 0x18(%rax)
leaq 0x58(%rsp), %r14
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
movq %rdx, 0x18(%r14)
movq 0x50(%r12), %rcx
movq 0x70(%r12), %rdi
leaq 0x120(%r12), %r15
movq %r12, 0x28(%rsp)
leaq 0xf0(%r12), %rdx
cmpb $0x0, 0x10(%rsp)
cmovneq %rdx, %r15
movq (%rdi), %rdx
movq 0x10(%rdx), %r12
subq $0x8, %rsp
movq %rbp, %rdx
movzbl %r9b, %ebp
movl $0x1, %esi
movq %rdx, 0x28(%rsp)
movq 0x20(%rsp), %r9
pushq %rbp
pushq %r13
pushq %r15
pushq %r14
pushq %rax
pushq %r10
pushq %r11
callq *%r12
addq $0x40, %rsp
cmpq $0x0, 0x50(%rsp)
je 0x3d731
movl 0xc(%rsp), %eax
andb $0x1, %al
movl %eax, 0xc(%rsp)
movb 0xb(%rsp), %r14b
xorb $0x1, %r14b
xorl %r12d, %r12d
movzbl 0x10(%rsp), %eax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movq 0x40(%rsp), %rax
movl 0xc(%rsp), %ecx
movb %cl, 0x14(%rax,%r12)
movl 0xc(%rax,%r12), %ecx
shll $0xe, %ecx
orw %cx, 0x8(%rax,%r12)
movb 0x15(%rbx), %cl
xorb $0x1, %cl
movb %cl, 0x15(%rax,%r12)
movq 0x60(%rsp), %rcx
movl (%rcx,%r15,4), %r8d
movl (%rbx), %ecx
movl %ecx, (%rax,%r12)
movl 0x4(%rbx), %ecx
movl %ecx, 0x4(%rax,%r12)
movq 0x58(%rbx), %rcx
movb 0x10(%rcx), %cl
movl %r14d, %edi
orb %cl, %dil
movb 0xb(%rsp), %r10b
testb %r10b, %r10b
movl %r13d, %r9d
cmovnel %r8d, %r9d
cmovnel %r13d, %r8d
leaq (%rax,%r12), %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 0x20(%rsp)
pushq 0x48(%rsp)
callq 0x3d8ee
addq $0x20, %rsp
movl %eax, %ebp
testb %al, %al
jne 0x3d733
incq %r15
addq $0x60, %r12
cmpq 0x50(%rsp), %r15
jb 0x3d67b
jmp 0x3d733
xorl %ebp, %ebp
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x3d742
callq 0x95e0
leaq 0x38(%rsp), %rdi
callq 0x37cba
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3d75f
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x3d771
callq 0x95e0
leaq 0x38(%rsp), %rdi
callq 0x37cba
movq %rbx, %rdi
callq 0x9930
nop