// File: BenLangmead[P]bowtie/./range_cache.h
// Function: RangeCache::tunnel(unsigned int, unsigned int, RangeCacheEntry&)
bool tunnel(TIndexOffU top, TIndexOffU bot, RangeCacheEntry& ent) {
		assert_gt(bot, top);
		TUVec tops;
		const TIndexOffU spread = bot - top;
		SideLocus tloc, bloc;
		SideLocus::initFromTopBot(top, bot, ebwt_->_eh, ebwt_->_ebwt, tloc, bloc);
		TIndexOffU newtop = top, newbot = bot;
		TIndexOffU jumps = 0;
		// Walk left through the tunnel
		while(true) {
			if(ebwt_->rowL(tloc) != ebwt_->rowL(bloc)) {
				// Different characters at top and bot positions of
				// BWT; this means that the calls to mapLF below are
				// guaranteed to yield rows in two different character-
				// sections of the BWT.
				break;
			}
			// Advance top and bot
			newtop = ebwt_->mapLF(tloc);
			newbot = ebwt_->mapLF(bloc);
			assert_geq(newbot, newtop);
			assert_leq(newbot - newtop, spread);
			// If the new spread is the same as the old spread, we can
			// be confident that the new range includes all of the same
			// suffixes as the last range (though longer by 1 char)
			if((newbot - newtop) == spread) {
				// Check if newtop is already cached
				TMapItr itr = map_.find(newtop);
				jumps++;
				if(itr != map_.end()) {
					// This range, which is further to the left in the
					// same tunnel as the query range, has a cache
					// entry already, so use that
					TIndexOffU idx = itr->second;
					TIndexOffU *ents = pool_.get(idx);
					if((ents[0] & CACHE_WRAPPER_BIT) != 0) {
						// The cache entry we found was a wrapper; make
						// a new wrapper that points to that wrapper's
						// target, with the appropriate number of jumps
						jumps += (ents[0] & ~CACHE_WRAPPER_BIT);
						idx = ents[1];
					}
					// Allocate a new wrapper
					TIndexOffU newentIdx = pool_.alloc(2);
					if(newentIdx != RANGE_CACHE_BAD_ALLOC) {
						// We successfully made a new wrapper entry;
						// now populate it and install it in map_
						TIndexOffU *newent = pool_.get(newentIdx); // get ptr to it
						assert_eq(0, newent[0]);
						newent[0] = CACHE_WRAPPER_BIT | jumps; // set jumps
						newent[1] = idx;                // set target
						assert(map_.find(top) == map_.end());
						map_[top] = newentIdx;
						if(sanity_) assert(repOk());
					}
					// Initialize the entry
					ent.init(pool_, top, jumps, idx, ebwt_);
					return true;
				}
				// Save this range
				tops.push_back(newtop);
				SideLocus::initFromTopBot(newtop, newbot, ebwt_->_eh, ebwt_->_ebwt, tloc, bloc);
			} else {
				// Not all the suffixes were preserved, so we can't
				// link the source range's cached result to this
				// range's cached results
				break;
			}
			assert_eq(jumps, tops.size());
		}
		assert_eq(jumps, tops.size());
		// Try to create a new cache entry for the leftmost range in
		// the tunnel (which might be the query range)
		TIndexOffU newentIdx = pool_.alloc(spread + 1);
		if(newentIdx != RANGE_CACHE_BAD_ALLOC) {
			// Successfully allocated new range cache entry; install it
			TIndexOffU *newent = pool_.get(newentIdx);
			assert_eq(0, newent[0]);
			// Store cache-range length in first word
			newent[0] = spread;
			assert_lt(newent[0], CACHE_WRAPPER_BIT);
			assert_eq(spread, newent[0]);
			TIndexOffU entTop = top;
			TIndexOffU jumps = 0;
			if(tops.size() > 0) {
				entTop = tops.back();
				jumps = (TIndexOff)tops.size();
			}
			// Cache the entry for the end of the tunnel
			assert(map_.find(entTop) == map_.end());
			map_[entTop] = newentIdx;
			if(sanity_) assert(repOk());
			ent.init(pool_, entTop, jumps, newentIdx, ebwt_);
			assert_eq(spread, newent[0]);
			if(jumps > 0) {
				assert_neq(entTop, top);
				// Cache a wrapper entry for the query range (if possible)
				TIndexOffU wrapentIdx = pool_.alloc(2);
				if(wrapentIdx != RANGE_CACHE_BAD_ALLOC) {
					TIndexOffU *wrapent = pool_.get(wrapentIdx);
					assert_eq(0, wrapent[0]);
					wrapent[0] = CACHE_WRAPPER_BIT | jumps;
					wrapent[1] = newentIdx;
					assert(map_.find(top) == map_.end());
					map_[top] = wrapentIdx;
					if(sanity_) assert(repOk());
				}
			}
			return true;
		} else {
			// Could not allocate new range cache entry
			return false;
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x31f40
movl -0x18(%rbp), %eax
movl -0x14(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x44(%rbp)
leaq -0x54(%rbp), %rdi
callq 0x4b6d0
jmp 0x4dd63
leaq -0x74(%rbp), %rdi
callq 0x4b6d0
jmp 0x4dd6e
movq -0xe0(%rbp), %rax
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
movq 0x58(%rax), %rdx
addq $0xf8, %rdx
movq 0x58(%rax), %rax
movq 0xb8(%rax), %rcx
leaq -0x54(%rbp), %r8
leaq -0x74(%rbp), %r9
callq 0x419e0
movl -0x14(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
jmp 0x4ddb3
movq -0xe0(%rbp), %rax
movq 0x58(%rax), %rdi
leaq -0x54(%rbp), %rsi
callq 0x24f10
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movl %ecx, -0xe4(%rbp)
movq 0x58(%rax), %rdi
leaq -0x74(%rbp), %rsi
callq 0x24f10
movl %eax, %ecx
movl -0xe4(%rbp), %eax
cmpl %ecx, %eax
je 0x4de0e
jmp 0x4e09a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x322a0
jmp 0x4e304
movq -0xe0(%rbp), %rax
movq 0x58(%rax), %rdi
leaq -0x54(%rbp), %rsi
callq 0x24e80
movl %eax, -0xe8(%rbp)
jmp 0x4de2a
movq -0xe0(%rbp), %rax
movl -0xe8(%rbp), %ecx
movl %ecx, -0x78(%rbp)
movq 0x58(%rax), %rdi
leaq -0x74(%rbp), %rsi
callq 0x24e80
movl %eax, -0xec(%rbp)
jmp 0x4de4f
movl -0xec(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
subl -0x78(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x4e093
movq -0xe0(%rbp), %rdi
addq $0x8, %rdi
leaq -0x78(%rbp), %rsi
callq 0x4dc70
movq %rax, -0xf8(%rbp)
jmp 0x4de84
movq -0xe0(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
addq $0x8, %rdi
callq 0x4dcd0
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4e720
testb $0x1, %al
jne 0x4dece
jmp 0x4e052
leaq -0x88(%rbp), %rdi
callq 0x4e310
movq -0xe0(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x94(%rbp)
addq $0x38, %rdi
movl -0x94(%rbp), %esi
callq 0x4e750
movq %rax, -0x100(%rbp)
jmp 0x4df02
movq -0x100(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movl (%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x4df47
movq -0xa0(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x94(%rbp)
movq -0xe0(%rbp), %rdi
addq $0x38, %rdi
movl $0x2, %esi
callq 0x4e780
movl %eax, -0x104(%rbp)
jmp 0x4df64
movl -0x104(%rbp), %eax
movl %eax, -0xa4(%rbp)
cmpl $-0x1, -0xa4(%rbp)
je 0x4e015
movq -0xe0(%rbp), %rdi
addq $0x38, %rdi
movl -0xa4(%rbp), %esi
callq 0x4e750
movq %rax, -0x110(%rbp)
jmp 0x4df9c
movq -0xe0(%rbp), %rdi
movq -0x110(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x80(%rbp), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movq -0xb0(%rbp), %rax
movl %ecx, (%rax)
movl -0x94(%rbp), %ecx
movq -0xb0(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0xa4(%rbp), %eax
movl %eax, -0x11c(%rbp)
addq $0x8, %rdi
leaq -0x14(%rbp), %rsi
callq 0x4e7f0
movq %rax, -0x118(%rbp)
jmp 0x4dff5
movq -0xe0(%rbp), %rax
movq -0x118(%rbp), %rcx
movl -0x11c(%rbp), %edx
movl %edx, (%rcx)
testb $0x1, 0x60(%rax)
je 0x4e013
jmp 0x4e013
jmp 0x4e015
movq -0xe0(%rbp), %rax
movq -0x20(%rbp), %rdi
movq %rax, %rsi
addq $0x38, %rsi
movl -0x14(%rbp), %edx
movl -0x80(%rbp), %ecx
movl -0x94(%rbp), %r8d
movq 0x58(%rax), %r9
callq 0x4e8d0
jmp 0x4e03f
movb $0x1, -0x1(%rbp)
movl $0x1, -0xb4(%rbp)
jmp 0x4e2ed
leaq -0x40(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x32160
jmp 0x4e061
movq -0xe0(%rbp), %rax
movl -0x78(%rbp), %edi
movl -0x7c(%rbp), %esi
movq 0x58(%rax), %rdx
addq $0xf8, %rdx
movq 0x58(%rax), %rax
movq 0xb8(%rax), %rcx
leaq -0x54(%rbp), %r8
leaq -0x74(%rbp), %r9
callq 0x419e0
jmp 0x4e095
jmp 0x4e09a
jmp 0x4ddb1
movq -0xe0(%rbp), %rdi
addq $0x38, %rdi
movl -0x44(%rbp), %esi
incl %esi
callq 0x4e780
movl %eax, -0x120(%rbp)
jmp 0x4e0b7
movl -0x120(%rbp), %eax
movl %eax, -0xb8(%rbp)
cmpl $-0x1, -0xb8(%rbp)
je 0x4e2df
movq -0xe0(%rbp), %rdi
addq $0x38, %rdi
movl -0xb8(%rbp), %esi
callq 0x4e750
movq %rax, -0x128(%rbp)
jmp 0x4e0ef
movq -0x128(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl -0x44(%rbp), %ecx
movq -0xc0(%rbp), %rax
movl %ecx, (%rax)
movl -0x14(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl $0x0, -0xc8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x24960
movq %rax, -0x130(%rbp)
jmp 0x4e12e
movq -0x130(%rbp), %rax
cmpq $0x0, %rax
jbe 0x4e175
leaq -0x40(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x45be0
movq -0x140(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
callq 0x24960
movq %rax, -0x138(%rbp)
jmp 0x4e168
movq -0x138(%rbp), %rax
movl %eax, -0xc8(%rbp)
movq -0xe0(%rbp), %rdi
movl -0xb8(%rbp), %eax
movl %eax, -0x14c(%rbp)
addq $0x8, %rdi
leaq -0xc4(%rbp), %rsi
callq 0x4e7f0
movq %rax, -0x148(%rbp)
jmp 0x4e1a1
movq -0xe0(%rbp), %rax
movq -0x148(%rbp), %rcx
movl -0x14c(%rbp), %edx
movl %edx, (%rcx)
testb $0x1, 0x60(%rax)
je 0x4e1bf
jmp 0x4e1bf
movq -0xe0(%rbp), %rax
movq -0x20(%rbp), %rdi
movq %rax, %rsi
addq $0x38, %rsi
movl -0xc4(%rbp), %edx
movl -0xc8(%rbp), %ecx
movl -0xb8(%rbp), %r8d
movq 0x58(%rax), %r9
callq 0x4e8d0
jmp 0x4e1ef
cmpl $0x0, -0xc8(%rbp)
jbe 0x4e2cf
movq -0xe0(%rbp), %rdi
addq $0x38, %rdi
movl $0x2, %esi
callq 0x4e780
movl %eax, -0x150(%rbp)
jmp 0x4e219
movl -0x150(%rbp), %eax
movl %eax, -0xcc(%rbp)
cmpl $-0x1, -0xcc(%rbp)
je 0x4e2cd
movq -0xe0(%rbp), %rdi
addq $0x38, %rdi
movl -0xcc(%rbp), %esi
callq 0x4e750
movq %rax, -0x158(%rbp)
jmp 0x4e251
movq -0xe0(%rbp), %rdi
movq -0x158(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl -0xc8(%rbp), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movq -0xd8(%rbp), %rax
movl %ecx, (%rax)
movl -0xb8(%rbp), %ecx
movq -0xd8(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0xcc(%rbp), %eax
movl %eax, -0x164(%rbp)
addq $0x8, %rdi
leaq -0x14(%rbp), %rsi
callq 0x4e7f0
movq %rax, -0x160(%rbp)
jmp 0x4e2ad
movq -0xe0(%rbp), %rax
movq -0x160(%rbp), %rcx
movl -0x164(%rbp), %edx
movl %edx, (%rcx)
testb $0x1, 0x60(%rax)
je 0x4e2cb
jmp 0x4e2cb
jmp 0x4e2cd
jmp 0x4e2cf
movb $0x1, -0x1(%rbp)
movl $0x1, -0xb4(%rbp)
jmp 0x4e2ed
movb $0x0, -0x1(%rbp)
movl $0x1, -0xb4(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x322a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0xab60
nopl (%rax)