// File: /workspace/github_cpp_makefile_star2_O1/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), %r9b
movl %esi, %eax
movb 0xb4(%rdi,%rax), %dil
movq 0x58(%r15), %rax
movq 0x50(%rax), %rcx
movb %dil, 0x5(%rsp)
cmpb %r9b, %dil
je 0x3d223
imulq $0x268, %rcx, %r8       # imm = 0x268
testb %sil, %sil
je 0x3d22e
addq 0x38(%rax), %r8
jmp 0x3d247
testb %sil, %sil
je 0x3d234
movq 0x38(%rax), %rax
jmp 0x3d238
addq 0x18(%rax), %r8
jmp 0x3d247
movq 0x18(%rax), %rax
imulq $0x268, %rcx, %rcx      # imm = 0x268
leaq (%rax,%rcx), %r8
addq $0x30, %r8
movq 0x58(%r15), %rcx
movq 0x50(%rcx), %rax
cmpb %r9b, 0x5(%rsp)
movb %r9b, 0x6(%rsp)
je 0x3d266
testb %sil, %sil
je 0x3d271
movq 0x38(%rcx), %rcx
jmp 0x3d275
testb %sil, %sil
je 0x3d286
movq 0x38(%rcx), %rcx
jmp 0x3d28a
movq 0x18(%rcx), %rcx
imulq $0x268, %rax, %rax      # imm = 0x268
leaq (%rcx,%rax), %r9
addq $0x60, %r9
jmp 0x3d29c
movq 0x18(%rcx), %rcx
imulq $0x268, %rax, %rax      # imm = 0x268
leaq (%rcx,%rax), %r9
addq $0xf0, %r9
movl 0x20(%r8), %eax
movq 0x58(%r15), %r10
movl %esi, %ecx
xorb $0x1, %cl
movb %cl, 0x7(%rsp)
movzbl %cl, %ecx
shll $0x5, %ecx
imulq $0x268, 0x50(%r10), %r11 # imm = 0x268
movq 0x18(%r10,%rcx), %rcx
movl 0x20(%rcx,%r11), %r14d
movl 0x98(%r15), %ecx
movl 0x9c(%r15), %edi
movzbl 0xb4(%r15), %r12d
movq 0x18(%r10), %r13
addq %r11, %r13
xorl $0x1, %r12d
movl 0x1a8(%r13,%r12,4), %r12d
subl %r12d, %ecx
xorl %ebp, %ebp
testl %ecx, %ecx
cmovlel %ebp, %ecx
subl %r12d, %edi
testl %edi, %edi
cmovlel %ebp, %edi
addq 0x38(%r10), %r11
movzbl 0xb5(%r15), %r10d
movl 0x1a8(%r11,%r10,4), %r10d
subl %r10d, %ecx
testl %ecx, %ecx
cmovlel %ebp, %ecx
subl %r10d, %edi
testl %edi, %edi
cmovlel %ebp, %edi
cmpl %r14d, %eax
movl %r14d, %r10d
cmoval %eax, %r10d
cmpl %r10d, %edi
jbe 0x3d5ad
movq %r9, 0x8(%rsp)
movb 0x6(%rsp), %r9b
movl %r9d, %r12d
xorb %sil, %r12b
movl (%rdx), %ebp
movl 0x4(%rdx), %r13d
movzbl 0x30e7c(%rip), %edx     # 0x6e1d0
je 0x3d3ad
movl %r14d, %esi
subl %eax, %esi
xorl %r10d, %r10d
testl %edx, %edx
cmovnel %r10d, %esi
cmpl %eax, %r14d
cmovbel %r10d, %esi
leal (%rdi,%r13), %r10d
subl %ecx, %edi
xorl $0x1, %edx
addl %r13d, %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(%r15), %rcx
movq 0x428(%rcx), %rcx
movl (%rcx,%rbp,4), %ecx
cmpl %ecx, %r10d
cmovael %ecx, %r10d
cmpl %ecx, %r11d
cmovael %ecx, %r11d
jmp 0x3d3e6
leal (%r14,%r13), %r10d
xorl %esi, %esi
movl %r10d, %r11d
subl %edi, %r11d
cmovbl %esi, %r11d
testl %edx, %edx
jne 0x3d3e6
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, %esi
movl %esi, %r10d
movl %r10d, %ecx
subl %r11d, %ecx
cmpl %eax, %ecx
jae 0x3d3f7
xorl %ebp, %ebp
jmp 0x3d5ad
xorl %r14d, %r14d
cmpb %r9b, 0x5(%rsp)
setne %r14b
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq 0x48(%rsp), %rax
movq %rcx, (%rax)
xorl %edx, %edx
movq %rdx, 0x8(%rax)
movl $0x80, %esi
movq %rsi, 0x10(%rax)
movq %rdx, 0x18(%rax)
leaq 0x30(%rsp), %rax
movq %rcx, -0x8(%rax)
movq %rdx, (%rax)
movq %rsi, 0x8(%rax)
movq %rdx, 0x10(%rax)
movq 0x50(%r15), %rcx
movq 0x78(%r15), %rdi
movq %r13, %rax
leaq 0x2248(%r15), %r13
leaq 0x2278(%r15), %rdx
testb %r9b, %r9b
cmovneq %rdx, %r13
movq (%rdi), %rdx
movq 0x10(%rdx), %rdx
movq %rdx, 0x10(%rsp)
subq $0x8, %rsp
movl $0x1, %esi
movq %rbp, 0x20(%rsp)
movq %rbp, %rdx
movq 0x10(%rsp), %r9
pushq %r14
movq %rax, 0x18(%rsp)
pushq %rax
pushq %r13
leaq 0x48(%rsp), %rax
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 0x3d581
movb 0x5(%rsp), %al
andb $0x1, %al
xorb 0x6(%rsp), %al
movb %al, 0x5(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x50(%rsp), %rsi
movb 0x5(%rsp), %al
movb %al, 0x14(%rsi,%r13)
movl 0xc(%rsi,%r13), %eax
shll $0xe, %eax
orw %ax, 0x8(%rsi,%r13)
movb 0x7(%rsp), %al
movb %al, 0x15(%rsi,%r13)
movq 0x30(%rsp), %rax
movl (%rax,%r14,4), %r8d
movl (%rbx), %eax
movl %eax, (%rsi,%r13)
movl 0x4(%rbx), %eax
movl %eax, 0x4(%rsi,%r13)
movb $0x1, %al
movb $0x1, %cl
testb %r12b, %r12b
je 0x3d510
movq 0x58(%rbx), %rcx
movb 0x10(%rcx), %cl
addq %r13, %rsi
testb %r12b, %r12b
je 0x3d52b
movl %r8d, %r9d
movq 0x8(%rsp), %rdx
movl %edx, %r8d
movq %rsi, %rdx
movq %rbx, %rsi
jmp 0x3d53d
movq 0x58(%rbx), %rax
movb 0x10(%rax), %al
movq 0x8(%rsp), %rdx
movl %edx, %r9d
movq %rbx, %rdx
movzbl 0x68(%r15), %r10d
movzbl %al, %eax
movzbl %cl, %r11d
xorl $0x1, %r10d
movq %r15, %rdi
movq 0x18(%rsp), %rcx
pushq %rax
pushq %r11
pushq %r10
pushq 0x38(%rsp)
callq 0x3d5fc
addq $0x20, %rsp
testb %al, %al
jne 0x3d581
incq %r14
addq $0x60, %r13
cmpq 0x60(%rsp), %r14
setb %bpl
jb 0x3d4c4
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3d5a3
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 0x3d5c4
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3d5e9
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