// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rcx, %rbx
movq %rdx, 0x20(%rsp)
movq %rdi, %r15
movb 0x14(%rcx), %dl
movb 0x15(%rcx), %cl
movl 0xc0(%rdi), %r14d
movzbl 0xc1(%rdi), %eax
testb %cl, %cl
movl %eax, %edi
cmovnel %r14d, %edi
cmovnel %eax, %r14d
movb %dl, 0x3(%rsp)
movl %edi, 0x4(%rsp)
cmpb %dil, %dl
setne %dil
sete 0x1(%rsp)
movq 0x58(%r15), %rax
movq 0x50(%rax), %rdx
cmpb %dil, %r14b
je 0x3e041
imulq $0x268, %rdx, %r8       # imm = 0x268
testb %cl, %cl
je 0x3e04b
addq 0x38(%rax), %r8
jmp 0x3e064
testb %cl, %cl
je 0x3e051
movq 0x38(%rax), %rax
jmp 0x3e055
addq 0x18(%rax), %r8
jmp 0x3e064
movq 0x18(%rax), %rax
imulq $0x268, %rdx, %rdx      # imm = 0x268
leaq (%rax,%rdx), %r8
addq $0x30, %r8
movq 0x58(%r15), %rdx
movq 0x50(%rdx), %rax
cmpb %dil, %r14b
movb %dil, 0x2(%rsp)
je 0x3e080
testb %cl, %cl
je 0x3e08a
movq 0x38(%rdx), %rdx
jmp 0x3e08e
testb %cl, %cl
je 0x3e09f
movq 0x38(%rdx), %rdx
jmp 0x3e0a3
movq 0x18(%rdx), %rdx
imulq $0x268, %rax, %rax      # imm = 0x268
leaq (%rdx,%rax), %r9
addq $0x60, %r9
jmp 0x3e0b5
movq 0x18(%rdx), %rdx
imulq $0x268, %rax, %rax      # imm = 0x268
leaq (%rdx,%rax), %r9
addq $0xf0, %r9
movl 0x20(%r8), %eax
movq 0x58(%r15), %r10
movl %ecx, %edx
xorb $0x1, %dl
movzbl %dl, %edx
shll $0x5, %edx
imulq $0x268, 0x50(%r10), %r11 # imm = 0x268
movq 0x18(%r10,%rdx), %rdx
movl 0x20(%rdx,%r11), %r12d
movl 0xb0(%r15), %edx
movl 0xb4(%r15), %edi
movzbl 0xc0(%r15), %r13d
movq 0x18(%r10), %rbp
addq %r11, %rbp
xorl $0x1, %r13d
movl 0x1a8(%rbp,%r13,4), %r13d
subl %r13d, %edx
xorl %ebp, %ebp
testl %edx, %edx
cmovlel %ebp, %edx
subl %r13d, %edi
testl %edi, %edi
cmovlel %ebp, %edi
addq 0x38(%r10), %r11
movzbl 0xc1(%r15), %r10d
movl 0x1a8(%r11,%r10,4), %r10d
subl %r10d, %edx
testl %edx, %edx
cmovlel %ebp, %edx
subl %r10d, %edi
testl %edi, %edi
cmovlel %ebp, %edi
cmpl %r12d, %eax
movl %r12d, %r10d
cmoval %eax, %r10d
cmpl %r10d, %edi
jbe 0x3e3bf
xorb %cl, 0x1(%rsp)
movl (%rsi), %ebp
movl 0x4(%rsi), %r13d
movzbl 0x30073(%rip), %ecx     # 0x6e1d0
je 0x3e178
leal (%r12,%r13), %r10d
xorl %esi, %esi
movl %r10d, %r11d
subl %edi, %r11d
cmovbl %esi, %r11d
testl %ecx, %ecx
je 0x3e1cf
decl %r10d
jmp 0x3e1f4
movl %r12d, %esi
subl %eax, %esi
xorl %r10d, %r10d
testl %ecx, %ecx
cmovnel %r10d, %esi
cmpl %eax, %r12d
cmovbel %r10d, %esi
leal (%rdi,%r13), %r10d
subl %edx, %edi
xorl $0x1, %ecx
addl %r13d, %ecx
addl %esi, %ecx
addl %eax, %edi
movl %r10d, %r11d
subl %edi, %r11d
cmpl %r11d, %ecx
cmoval %ecx, %r11d
cmpl %edi, %r10d
cmovbel %ecx, %r11d
movq 0x50(%r15), %rcx
movq 0x428(%rcx), %rcx
movl (%rcx,%rbp,4), %ecx
cmpl %ecx, %r10d
cmovael %ecx, %r10d
cmpl %ecx, %r11d
cmovael %ecx, %r11d
jmp 0x3e1f4
cmpl %r12d, %eax
cmovbl %eax, %r12d
leal (%r12,%r13), %ecx
decl %ecx
movl %edx, %edi
notl %edi
addl %eax, %r10d
addl %r10d, %edi
cmpl %ecx, %edi
cmovael %ecx, %edi
cmpl %edx, %r10d
cmoval %edi, %esi
movl %esi, %r10d
movl %r10d, %ecx
subl %r11d, %ecx
cmpl %eax, %ecx
jae 0x3e205
xorl %ebp, %ebp
jmp 0x3e3bf
movq %r13, 0x8(%rsp)
xorl %r13d, %r13d
cmpb 0x2(%rsp), %r14b
setne %r13b
leaq 0x120(%r15), %r12
leaq 0xf0(%r15), %rdx
xorl %ecx, %ecx
movl 0x4(%rsp), %esi
cmpb %sil, 0x3(%rsp)
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
leaq 0x48(%rsp), %rax
movq %rsi, (%rax)
movq %rcx, 0x8(%rax)
movl $0x80, %edi
movq %rdi, 0x10(%rax)
movq %rcx, 0x18(%rax)
leaq 0x30(%rsp), %rax
movq %rsi, -0x8(%rax)
movq %rcx, (%rax)
movq %rdi, 0x8(%rax)
movq %rcx, 0x10(%rax)
movq 0x50(%r15), %rcx
movq 0x70(%r15), %rdi
cmoveq %rdx, %r12
movq (%rdi), %rdx
movq 0x10(%rdx), %rax
movq %rax, 0x10(%rsp)
subq $0x8, %rsp
leaq 0x30(%rsp), %rax
movl $0x1, %esi
movq %rbp, 0x20(%rsp)
movq %rbp, %rdx
pushq %r13
pushq 0x18(%rsp)
pushq %r12
pushq %rax
leaq 0x70(%rsp), %rax
pushq %rax
pushq %r10
pushq %r11
callq *0x50(%rsp)
addq $0x40, %rsp
cmpq $0x0, 0x60(%rsp)
setne %bpl
je 0x3e393
andb $0x1, %r14b
xorb 0x2(%rsp), %r14b
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x50(%rsp), %rsi
movb %r14b, 0x14(%rsi,%r13)
movl 0xc(%rsi,%r13), %eax
shll $0xe, %eax
orw %ax, 0x8(%rsi,%r13)
movb 0x15(%rbx), %al
xorb $0x1, %al
movb %al, 0x15(%rsi,%r13)
movq 0x30(%rsp), %rax
movl (%rax,%r12,4), %r8d
movl (%rbx), %eax
movl %eax, (%rsi,%r13)
movl 0x4(%rbx), %eax
movl %eax, 0x4(%rsi,%r13)
movb $0x1, %al
movb $0x1, %cl
cmpb $0x0, 0x1(%rsp)
jne 0x3e319
movq 0x58(%rbx), %rcx
movb 0x10(%rcx), %cl
addq %r13, %rsi
cmpb $0x0, 0x1(%rsp)
je 0x3e337
movq 0x58(%rbx), %rax
movb 0x10(%rax), %al
movq 0x8(%rsp), %rdx
movl %edx, %r9d
movq %rbx, %rdx
jmp 0x3e348
movl %r8d, %r9d
movq 0x8(%rsp), %rdx
movl %edx, %r8d
movq %rsi, %rdx
movq %rbx, %rsi
xorl %r10d, %r10d
movl 0x4(%rsp), %edi
cmpb %dil, 0x3(%rsp)
sete %r10b
movzbl %al, %eax
movzbl %cl, %r11d
movq %r15, %rdi
movq 0x18(%rsp), %rcx
pushq %rax
pushq %r11
pushq %r10
pushq 0x38(%rsp)
callq 0x3e57c
addq $0x20, %rsp
testb %al, %al
jne 0x3e393
incq %r12
addq $0x60, %r13
cmpq 0x60(%rsp), %r12
setb %bpl
jb 0x3e2ce
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3e3b5
callq 0x95e0
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rax
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x48(%rsp), %rdi
callq 0x3874e
andb $0x1, %bpl
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3e3d6
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3e3fb
callq 0x95e0
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rax
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x48(%rsp), %rdi
callq 0x3874e
movq %rbx, %rdi
callq 0x9930
nop