// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./multikey_qsort.h
// Function: void mkeyQSortSuf2<SString<char>>(SString<char> const&, unsigned long, unsigned int*, unsigned long, unsigned int*, int, unsigned long, unsigned long, unsigned long, unsigned long, EList<unsigned long, 128>*)
void mkeyQSortSuf2(
	const T& host,
	size_t hlen,
	TIndexOffU *s,
	size_t slen,
	TIndexOffU *s2,
	int hi,
	size_t _begin,
	size_t _end,
	size_t _depth,
	size_t upto = OFF_MASK,
	EList<size_t>* boundaries = NULL)
{
	EList<EList<QSortRange> > block_list;
	while(true) {
		size_t begin = 0, end = 0, depth = 0;
		if(block_list.size() == 0) {
			begin = _begin;
			end = _end;
			depth = _depth;
		} else {
			if(block_list.back().size() > 0) {
				begin = block_list.back()[0].begin;
				end = block_list.back()[0].end;
				depth = block_list.back()[0].depth;
				block_list.back().erase(0);
			} else {
				block_list.resize(block_list.size() - 1);
				if(block_list.size() == 0) {
					break;
				}
			}
		}
		if(depth == upto) {
			if(boundaries != NULL) {
				(*boundaries).push_back(end);
			}
			continue;
		}
		assert_leq(begin, slen);
		assert_leq(end, slen);
		size_t a, b, c, d, /*e,*/ r;
		size_t n = end - begin;
		if(n <= 1) { // 1-element list already sorted
			if(n == 1 && boundaries != NULL) {
				boundaries->push_back(end);
			}
			continue;
		}
		CHOOSE_AND_SWAP_PIVOT(SWAP2, CHAR_AT_SUF); // pick pivot, swap it into [begin]
		int v = CHAR_AT_SUF(begin, depth); // v <- randomly-selected pivot value
#ifndef NDEBUG
		{
			bool stillInBounds = false;
			for(size_t i = begin; i < end; i++) {
				if(depth < (hlen-s[i])) {
					stillInBounds = true;
					break;
				} else { /* already fell off this suffix */ }
			}
			assert(stillInBounds); // >=1 suffix must still be in bounds
		}
#endif
		a = b = begin;
		c = d = /*e =*/ end-1;
		while(true) {
			// Invariant: everything before a is = pivot, everything
			// between a and b is <
			int bc = 0; // shouldn't have to init but gcc on Mac complains
			while(b <= c && v >= (bc = CHAR_AT_SUF(b, depth))) {
			if(v == bc) {
				SWAP2(s, s2, a, b); a++;
			}
			b++;
		}
		// Invariant: everything after d is = pivot, everything
		// between c and d is >
		int cc = 0; // shouldn't have to init but gcc on Mac complains
		while(b <= c && v <= (cc = CHAR_AT_SUF(c, depth))) {
			if(v == cc) {
				SWAP2(s, s2, c, d); d--; /*e--;*/
			}
			//else if(c == e && v == hi) e--;
			c--;
		}
		if(b > c) break;
			SWAP2(s, s2, b, c);
			b++;
			c--;
		}
		assert(a > begin || c < end-1);                      // there was at least one =s
		assert_lt(/*e*/d-c, n); // they can't all have been > pivot
		assert_lt(b-a, n); // they can't all have been < pivot
		assert(assertPartitionedSuf(host, s, slen, hi, v, begin, end, depth));  // check pre-=-swap invariant
		r = min(a-begin, b-a); VECSWAP2(s, s2, begin, b-r,   r);  // swap left = to center
		r = min(d-c, end-d-1); VECSWAP2(s, s2, b,     end-r, r);  // swap right = to center
		assert(assertPartitionedSuf2(host, s, slen, hi, v, begin, end, depth)); // check post-=-swap invariant
		r = b-a; // r <- # of <'s
		EList<QSortRange> tmp1;
		block_list.push_back(tmp1);
		block_list.back().clear();
		if(r > 0) { // recurse on <'s
			QSortRange tmp2;
			block_list.back().push_back(tmp2);
			block_list.back().back().begin = begin;
			block_list.back().back().end = begin + r;
			block_list.back().back().depth = depth;
		}
		// Do not recurse on ='s if the pivot was the off-the-end value;
		// they're already fully sorted
		//if(v != hi) { // recurse on ='s
			QSortRange tmp3;
			block_list.back().push_back(tmp3);
			block_list.back().back().begin = begin + r;
			block_list.back().back().end = begin + r + (a-begin) + (end-d-1);
			block_list.back().back().depth = depth + 1;
			//}
		r = d-c;   // r <- # of >'s excluding those exhausted
		if(r > 0 /*&& v < hi-1*/) { // recurse on >'s
			QSortRange tmp4;
			block_list.back().push_back(tmp4);
			block_list.back().back().begin = end - r;
			block_list.back().back().end = end;
			block_list.back().back().depth = depth;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, %r14
movq %rdx, %r15
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x100(%rsp), %rbx
movq 0xf8(%rsp), %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
andq $0x0, 0x8(%rcx)
movq $0x80, 0x10(%rcx)
andq $0x0, 0x18(%rcx)
xorl %esi, %esi
andq $0x0, 0x8(%rsp)
testq %rsi, %rsi
je 0x16d15
movq 0x18(%rsp), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
cmpq $0x0, -0x8(%rax,%rcx)
je 0x16d34
addq %rcx, %rax
leaq -0x20(%rax), %rdi
movq -0x18(%rax), %rcx
movq (%rcx), %rbp
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rsp)
movq -0x18(%rax), %rax
movq 0x10(%rax), %r13
xorl %esi, %esi
callq 0x172c4
movq %r13, %rdi
jmp 0x16d51
movq 0xe8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xf0(%rsp), %rdi
movq 0xe0(%rsp), %rbp
jmp 0x16d51
decq %rsi
leaq 0x10(%rsp), %rdi
callq 0x172fa
cmpq $0x0, 0x28(%rsp)
je 0x1727c
xorl %edi, %edi
xorl %ebp, %ebp
cmpq %r12, %rdi
jne 0x16d71
testq %rbx, %rbx
je 0x1719b
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0xe4ba
jmp 0x1719b
movq 0x8(%rsp), %r9
movq %r9, %rax
subq %rbp, %rax
cmpq $0x1, %rax
ja 0x16da7
testq %rbx, %rbx
je 0x1719b
cmpq $0x1, %rax
jne 0x1719b
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0xe4ba
jmp 0x1719b
cmpq $0x5, %rax
jb 0x16e07
leaq 0x1(%rbp), %rax
movl 0x4(%r15,%rbp,4), %ecx
movq %rcx, %rdx
addq %rdi, %rdx
cmpq 0x38(%rsp), %rdx
jae 0x16dd7
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %edx
cmpl $0x1, %edx
jne 0x16de2
jmp 0x16deb
movl 0x4(%rsp), %esi
movl %esi, %edx
cmpl $0x1, %esi
je 0x16deb
cmpl $0x2, %edx
jne 0x171a5
movl (%r15,%rbp,4), %edx
movl %ecx, (%r15,%rbp,4)
movl %edx, (%r15,%rax,4)
movl (%r14,%rbp,4), %ecx
movl (%r14,%rax,4), %edx
movl %edx, (%r14,%rbp,4)
movl %ecx, (%r14,%rax,4)
movl (%r15,%rbp,4), %ecx
addq %rdi, %rcx
movl 0x4(%rsp), %eax
cmpq 0x38(%rsp), %rcx
jae 0x16e26
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movsbl (%rax,%rcx), %eax
leaq -0x1(%r9), %rbx
movq %rbp, %r13
movq %rbp, 0x48(%rsp)
movq %rbx, %r12
cmpq %rbx, %rbp
ja 0x16ea8
movl (%r15,%rbp,4), %ecx
leaq (%rdi,%rcx), %rdx
movl 0x4(%rsp), %esi
cmpq 0x38(%rsp), %rdx
jae 0x16e5a
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %esi
cmpl %esi, %eax
jl 0x16ea8
jne 0x16e7f
movl (%r15,%r13,4), %edx
movl %ecx, (%r15,%r13,4)
movl %edx, (%r15,%rbp,4)
movl (%r14,%r13,4), %ecx
movl (%r14,%rbp,4), %edx
movl %edx, (%r14,%r13,4)
movl %ecx, (%r14,%rbp,4)
incq %r13
incq %rbp
jmp 0x16e35
jne 0x16ea5
movl (%r15,%r12,4), %edx
movl %edx, (%r15,%rbx,4)
movl %ecx, (%r15,%r12,4)
movl (%r14,%rbx,4), %ecx
movl (%r14,%r12,4), %edx
movl %edx, (%r14,%rbx,4)
movl %ecx, (%r14,%r12,4)
decq %r12
decq %rbx
cmpq %rbx, %rbp
ja 0x16ef8
movl (%r15,%rbx,4), %ecx
leaq (%rdi,%rcx), %rsi
movl 0x4(%rsp), %edx
cmpq 0x38(%rsp), %rsi
jae 0x16ecd
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rdx
movsbl (%rdx,%rsi), %edx
cmpl %edx, %eax
jle 0x16e84
movl (%r15,%rbp,4), %edx
movl %ecx, (%r15,%rbp,4)
movl %edx, (%r15,%rbx,4)
movl (%r14,%rbp,4), %ecx
movl (%r14,%rbx,4), %edx
movl %edx, (%r14,%rbp,4)
movl %ecx, (%r14,%rbx,4)
incq %rbp
decq %rbx
jmp 0x16e35
movq %rdi, 0x40(%rsp)
movq %r13, %rax
movq 0x48(%rsp), %rdx
subq %rdx, %rax
movq %rbp, %rsi
subq %r13, %rsi
cmpq %rax, %rsi
movq %rax, %r8
cmovbq %rsi, %r8
testq %r8, %r8
je 0x16f3f
cmpq %rsi, %rax
cmovbq %rax, %rsi
movq %rbp, %rcx
subq %rsi, %rcx
movq %r15, %rdi
movq %r14, %rsi
movq %r9, 0x50(%rsp)
callq 0xb220
movq 0x50(%rsp), %r9
movq %r12, %rax
subq %rbx, %rax
movq %r12, %r8
notq %r8
addq %r9, %r8
cmpq %rax, %r8
cmovaeq %rax, %r8
testq %r8, %r8
je 0x16f6e
subq %r8, %r9
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r9, %rcx
callq 0xb220
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x58(%rsp)
andq $0x0, 0x60(%rsp)
movq $0x80, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1733c
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
andq $0x0, -0x8(%rax,%rcx)
cmpq %r13, %rbp
je 0x1704b
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x78(%rsp), %rsi
callq 0x17390
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
imulq $0x18, -0x8(%rax,%rcx), %rax
movq 0x48(%rsp), %rcx
movq %rcx, -0x18(%rdx,%rax)
movq %rcx, %rax
subq %r13, %rax
addq %rbp, %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
imulq $0x18, -0x8(%rcx,%rdx), %rcx
movq %rax, -0x10(%rsi,%rcx)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
imulq $0x18, -0x8(%rax,%rcx), %rax
movq 0x40(%rsp), %rcx
movq %rcx, -0x8(%rdx,%rax)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x78(%rsp), %rsi
callq 0x17390
movq 0x48(%rsp), %rsi
subq %r13, %rsi
addq %rbp, %rsi
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
imulq $0x18, -0x8(%rax,%rcx), %rax
movq %rsi, -0x18(%rdx,%rax)
movq 0x8(%rsp), %rax
subq %r12, %rax
addq %rbp, %rax
decq %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
imulq $0x18, -0x8(%rcx,%rdx), %rcx
movq %rax, -0x10(%rsi,%rcx)
movq 0x40(%rsp), %rax
incq %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
imulq $0x18, -0x8(%rcx,%rdx), %rcx
movq %rax, -0x8(%rsi,%rcx)
cmpq %rbx, %r12
je 0x17181
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x90(%rsp), %rsi
callq 0x17390
movq 0x8(%rsp), %rax
subq %r12, %rax
addq %rbx, %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
imulq $0x18, -0x8(%rcx,%rdx), %rcx
movq %rax, -0x18(%rsi,%rcx)
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
imulq $0x18, -0x8(%rcx,%rdx), %rcx
movq %rax, -0x10(%rsi,%rcx)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
imulq $0x18, -0x8(%rax,%rcx), %rax
movq 0x40(%rsp), %rcx
movq %rcx, -0x8(%rdx,%rax)
leaq 0x58(%rsp), %rdi
callq 0x1767c
movq 0x100(%rsp), %rbx
movq 0xf8(%rsp), %r12
movq 0x28(%rsp), %rsi
jmp 0x16ccb
leaq 0x2(%rbp), %rax
movl 0x8(%r15,%rbp,4), %ecx
movq %rcx, %rdx
addq %rdi, %rdx
cmpq 0x38(%rsp), %rdx
jae 0x171d3
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %edx
cmpl $0x1, %edx
je 0x16deb
jmp 0x171e2
movl 0x4(%rsp), %esi
movl %esi, %edx
cmpl $0x1, %esi
je 0x16deb
cmpl $0x2, %edx
je 0x16deb
leaq 0x3(%rbp), %rax
movl 0xc(%r15,%rbp,4), %ecx
movq %rcx, %rdx
addq %rdi, %rdx
cmpq 0x38(%rsp), %rdx
jae 0x17219
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %edx
cmpl $0x1, %edx
je 0x16deb
jmp 0x17228
movl 0x4(%rsp), %esi
movl %esi, %edx
cmpl $0x1, %esi
je 0x16deb
cmpl $0x2, %edx
je 0x16deb
leaq 0x4(%rbp), %rax
movl 0x10(%r15,%rbp,4), %ecx
movq %rcx, %rdx
addq %rdi, %rdx
cmpq 0x38(%rsp), %rdx
jae 0x1725f
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %edx
cmpl $0x1, %edx
je 0x16deb
jmp 0x1726e
movl 0x4(%rsp), %esi
movl %esi, %edx
cmpl $0x1, %esi
je 0x16deb
cmpl $0x2, %edx
je 0x16deb
jmp 0x16e07
leaq 0x10(%rsp), %rdi
callq 0x1758e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x172a0
jmp 0x172a0
jmp 0x172af
jmp 0x172a0
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x1767c
jmp 0x172b2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1758e
movq %rbx, %rdi
callq 0x5680