// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./ebwt.h
// Function: Ebwt::joinedToTextOff(unsigned long, unsigned long, unsigned long&, unsigned long&, unsigned long&) const
void Ebwt::joinedToTextOff(TIndexOffU qlen, TIndexOffU off,
				 TIndexOffU& tidx,
				 TIndexOffU& textoff,
				 TIndexOffU& tlen) const
{
	TIndexOffU top = 0;
	TIndexOffU bot = _nFrag; // 1 greater than largest addressable element
	TIndexOffU elt = OFF_MASK;
	// Begin binary search
	while(true) {
		ASSERT_ONLY(TIndexOffU oldelt = elt);
		elt = top + ((bot - top) >> 1);
		assert_neq(oldelt, elt); // must have made progress
		TIndexOffU lower = _rstarts[elt*3];
		TIndexOffU upper;
		if(elt == _nFrag-1) {
			upper = _eh._len;
		} else {
			upper = _rstarts[((elt+1)*3)];
		}
		assert_gt(upper, lower);
		TIndexOffU fraglen = upper - lower;
		if(lower <= off) {
			if(upper > off) { // not last element, but it's within
				// off is in this range; check if it falls off
				if(off + qlen > upper) {
					// it falls off; signal no-go and return
					tidx = OFF_MASK;
					assert_lt(elt, _nFrag-1);
					return;
				}
				tidx = _rstarts[(elt*3)+1];
				assert_lt(tidx, this->_nPat);
				assert_leq(fraglen, this->_plen[tidx]);
				// it doesn't fall off; now calculate textoff.
				// Initially it's the number of characters that precede
				// the alignment in the fragment
				uint32_t fragoff = off - _rstarts[(elt*3)];
				if(!this->_fw) {
					fragoff = fraglen - fragoff - 1;
					fragoff -= (qlen-1);
				}
				// Add the alignment's offset into the fragment
				// ('fragoff') to the fragment's offset within the text
				textoff = fragoff + _rstarts[(elt*3)+2];
				assert_lt(textoff, this->_plen[tidx]);
				break; // done with binary search
			} else {
				// 'off' belongs somewhere in the region between elt
				// and bot
				top = elt;
			}
		} else {
			// 'off' belongs somewhere in the region between top and
			// elt
			bot = elt;
		}
		// continue with binary search
	}
	tlen = this->_plen[tidx];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %r9
movq %rdi, %rbx
movq 0x88(%rdi), %r8
movq 0x98(%rdi), %rax
leaq -0x1(%r8), %rdi
leaq 0x108(%rbx), %r10
leaq 0x18(%rax), %r11
pushq $-0x1
popq %r13
xorl %r14d, %r14d
movq %r13, %r12
movq %r8, %r13
subq %r14, %r13
shrq %r13
addq %r14, %r13
cmpq %r13, %r12
je 0x69c3
leaq (,%r13,2), %rcx
addq %r13, %rcx
imulq $0x18, %r13, %r15
addq %r11, %r15
cmpq %rdi, %r13
cmoveq %r10, %r15
movq (%rax,%rcx,8), %r12
movq (%r15), %r15
movq %r15, %rbp
subq %r12, %rbp
jbe 0x6920
cmpq %rdx, %r12
ja 0x67d0
movq %r13, %r12
movq %r13, %r14
cmpq %rdx, %r15
jbe 0x677d
jmp 0x67d5
movq %r13, %r8
jmp 0x677a
leaq (%rdx,%rsi), %rdi
cmpq %r15, %rdi
jbe 0x68a3
orq $-0x1, (%r9)
movq 0x88(%rbx), %rax
decq %rax
cmpq %rax, %r13
jb 0x6911
movq 0x2d7b8(%rip), %r14     # 0x33fb8
leaq 0x21a80(%rip), %rsi     # 0x28287
movq %r14, %rdi
callq 0x42d0
movq %rax, %rdi
movq %r13, %rsi
callq 0x40b0
leaq 0x21a7c(%rip), %rsi     # 0x2829d
movq %rax, %rdi
callq 0x42d0
movq 0x88(%rbx), %rsi
decq %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x23bd6(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x218a4(%rip), %rbx     # 0x280fd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0x22ed0(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xa25, %esi            # imm = 0xA25
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x22d8c(%rip), %rdi     # 0x2961b
leaq 0x21aaf(%rip), %rcx     # 0x28345
movq %rbx, %rsi
movl $0xa25, %edx            # imm = 0xA25
callq 0x4190
movq 0x8(%rax,%rcx,8), %rax
movq %r9, %r14
movq %rax, (%r9)
cmpq 0x80(%rbx), %rax
jae 0x6aed
movq 0x90(%rbx), %rdi
cmpq (%rdi,%rax,8), %rbp
ja 0x6b94
movq 0x98(%rbx), %rax
subq (%rax,%rcx,8), %rdx
addl %edx, %esi
subl %esi, %ebp
cmpb $0x0, 0x10(%rbx)
cmovneq %rdx, %rbp
movl %ebp, %edx
addq 0x10(%rax,%rcx,8), %rdx
movq 0x10(%rsp), %r15
movq %rdx, (%r15)
movq 0x90(%rbx), %rax
movq (%r14), %rcx
movq (%rax,%rcx,8), %rax
cmpq %rax, %rdx
jae 0x6c42
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2d691(%rip), %rbx     # 0x33fb8
leaq 0x2180a(%rip), %rsi     # 0x28138
movq %rbx, %rdi
callq 0x42d0
movq %rax, %rdi
movq %r15, %rsi
callq 0x40b0
leaq 0x21806(%rip), %rsi     # 0x2814e
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movq %r12, %rsi
callq 0x40b0
leaq 0x23ab6(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x21784(%rip), %r14     # 0x280fd
movq %rbx, %rdi
movq %r14, %rsi
callq 0x42d0
leaq 0x22db0(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xa1d, %esi            # imm = 0xA1D
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x22c6c(%rip), %rdi     # 0x2961b
leaq 0x2198f(%rip), %rcx     # 0x28345
movq %r14, %rsi
movl $0xa1d, %edx            # imm = 0xA1D
callq 0x4190
movq 0x2d5ee(%rip), %rbx     # 0x33fb8
leaq 0x21959(%rip), %rsi     # 0x2832a
movq %rbx, %rdi
callq 0x42d0
movq %rax, %rdi
movq %r12, %rsi
callq 0x40b0
leaq 0x21784(%rip), %r14     # 0x2816f
movq %rax, %rdi
movq %r14, %rsi
callq 0x42d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movq %r12, %rsi
callq 0x40b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x21742(%rip), %rsi     # 0x28174
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movq %r12, %rsi
callq 0x40b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x42d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movq %r12, %rsi
callq 0x40b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x2398c(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x2165a(%rip), %r14     # 0x280fd
movq %rbx, %rdi
movq %r14, %rsi
callq 0x42d0
leaq 0x22c86(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xa15, %esi            # imm = 0xA15
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x22b42(%rip), %rdi     # 0x2961b
leaq 0x21865(%rip), %rcx     # 0x28345
movq %r14, %rsi
movl $0xa15, %edx            # imm = 0xA15
callq 0x4190
movq 0x2d4c4(%rip), %r15     # 0x33fb8
leaq 0x2178c(%rip), %rsi     # 0x28287
movq %r15, %rdi
callq 0x42d0
movq (%r14), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x21788(%rip), %rsi     # 0x2829d
movq %rax, %rdi
callq 0x42d0
movq 0x80(%rbx), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x238e5(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x215b3(%rip), %rbx     # 0x280fd
movq %r15, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0x22bdf(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xa29, %esi            # imm = 0xA29
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x22a9b(%rip), %rdi     # 0x2961b
leaq 0x217be(%rip), %rcx     # 0x28345
movq %rbx, %rsi
movl $0xa29, %edx            # imm = 0xA29
callq 0x4190
movq 0x2d41d(%rip), %r15     # 0x33fb8
leaq 0x21641(%rip), %rsi     # 0x281e3
movq %r15, %rdi
callq 0x42d0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x40b0
leaq 0x2163e(%rip), %rsi     # 0x281fa
movq %rax, %rdi
callq 0x42d0
movq 0x90(%rbx), %rcx
movq (%r14), %rdx
movq (%rcx,%rdx,8), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x23837(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x21505(%rip), %rbx     # 0x280fd
movq %r15, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0x22b31(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xa2a, %esi            # imm = 0xA2A
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x229ed(%rip), %rdi     # 0x2961b
leaq 0x21710(%rip), %rcx     # 0x28345
movq %rbx, %rsi
movl $0xa2a, %edx            # imm = 0xA2A
callq 0x4190
movq 0x2d36f(%rip), %r12     # 0x33fb8
leaq 0x21637(%rip), %rsi     # 0x28287
movq %r12, %rdi
callq 0x42d0
movq (%r15), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x21633(%rip), %rsi     # 0x2829d
movq %rax, %rdi
callq 0x42d0
movq 0x90(%rbx), %rcx
movq (%r14), %rdx
movq (%rcx,%rdx,8), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x23789(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x21457(%rip), %rbx     # 0x280fd
movq %r12, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0x22a83(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xa36, %esi            # imm = 0xA36
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x2293f(%rip), %rdi     # 0x2961b
leaq 0x21662(%rip), %rcx     # 0x28345
movq %rbx, %rsi
movl $0xa36, %edx            # imm = 0xA36
callq 0x4190