// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, %r14
movq %rdx, %r15
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x120(%rsp), %rbx
movq 0x118(%rsp), %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq $0x80, 0x10(%rcx)
movq %rax, 0x18(%rcx)
leaq -0x4(%r8), %rax
movq %rax, 0x58(%rsp)
leaq -0x4(%rdx), %rax
movq %rax, 0x50(%rsp)
xorl %esi, %esi
movq $0x0, 0x8(%rsp)
testq %rsi, %rsi
je 0x1d242
movq 0x18(%rsp), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
cmpq $0x0, -0x8(%rax,%rcx)
je 0x1d261
addq %rcx, %rax
movq -0x18(%rax), %rcx
movq (%rcx), %r9
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rsp)
movq -0x18(%rax), %rcx
movq 0x10(%rcx), %r8
cmpq $0x1, -0x8(%rax)
jne 0x1d282
xorl %esi, %esi
jmp 0x1d2b0
movq 0x108(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x110(%rsp), %r8
movq 0x100(%rsp), %r9
jmp 0x1d2b4
decq %rsi
leaq 0x10(%rsp), %rdi
callq 0x1d8cc
cmpq $0x0, 0x28(%rsp)
je 0x1d87c
xorl %r8d, %r8d
xorl %r9d, %r9d
jmp 0x1d2b4
xorl %ecx, %ecx
xorl %edx, %edx
movq -0x18(%rax), %rsi
incq %rdx
movq 0x28(%rsi,%rcx), %rdi
movq %rdi, 0x10(%rsi,%rcx)
movups 0x18(%rsi,%rcx), %xmm0
movups %xmm0, (%rsi,%rcx)
movq -0x8(%rax), %rsi
decq %rsi
addq $0x18, %rcx
cmpq %rsi, %rdx
jb 0x1d286
movq %rsi, -0x8(%rax)
cmpq %r12, %r8
jne 0x1d2d4
testq %rbx, %rbx
je 0x1d79b
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x11c8a
jmp 0x1d79b
movq 0x8(%rsp), %rax
movq %rax, %rcx
subq %r9, %rcx
cmpq $0x1, %rcx
ja 0x1d30a
testq %rbx, %rbx
je 0x1d79b
cmpq $0x1, %rcx
jne 0x1d79b
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x11c8a
jmp 0x1d79b
cmpq $0x5, %rcx
jb 0x1d36a
leaq 0x1(%r9), %rcx
movl 0x4(%r15,%r9,4), %edx
movq %rdx, %rsi
addq %r8, %rsi
cmpq 0x38(%rsp), %rsi
jae 0x1d33a
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rdi
movsbl (%rdi,%rsi), %esi
cmpl $0x1, %esi
jne 0x1d345
jmp 0x1d34e
movl 0x4(%rsp), %edi
movl %edi, %esi
cmpl $0x1, %edi
je 0x1d34e
cmpl $0x2, %esi
jne 0x1d7a5
movl (%r15,%r9,4), %esi
movl %edx, (%r15,%r9,4)
movl %esi, (%r15,%rcx,4)
movl (%r14,%r9,4), %edx
movl (%r14,%rcx,4), %esi
movl %esi, (%r14,%r9,4)
movl %edx, (%r14,%rcx,4)
movl (%r15,%r9,4), %edx
addq %r8, %rdx
movl 0x4(%rsp), %ecx
cmpq 0x38(%rsp), %rdx
jae 0x1d389
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx,%rdx), %ecx
leaq -0x1(%rax), %r13
movq %r9, %rbp
movq %r9, %r12
movq %r13, %rbx
cmpq %r13, %r12
ja 0x1d409
movl (%r15,%r12,4), %edx
leaq (%r8,%rdx), %rsi
movl 0x4(%rsp), %edi
cmpq 0x38(%rsp), %rsi
jae 0x1d3bb
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rdi
movsbl (%rdi,%rsi), %edi
cmpl %edi, %ecx
jl 0x1d409
jne 0x1d3e0
movl (%r15,%rbp,4), %esi
movl %edx, (%r15,%rbp,4)
movl %esi, (%r15,%r12,4)
movl (%r14,%rbp,4), %edx
movl (%r14,%r12,4), %esi
movl %esi, (%r14,%rbp,4)
movl %edx, (%r14,%r12,4)
incq %rbp
incq %r12
jmp 0x1d396
jne 0x1d406
movl (%r15,%rbx,4), %esi
movl %esi, (%r15,%r13,4)
movl %edx, (%r15,%rbx,4)
movl (%r14,%r13,4), %edx
movl (%r14,%rbx,4), %esi
movl %esi, (%r14,%r13,4)
movl %edx, (%r14,%rbx,4)
decq %rbx
decq %r13
cmpq %r13, %r12
ja 0x1d459
movl (%r15,%r13,4), %edx
leaq (%r8,%rdx), %rdi
movl 0x4(%rsp), %esi
cmpq 0x38(%rsp), %rdi
jae 0x1d42e
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdi), %esi
cmpl %esi, %ecx
jle 0x1d3e5
movl (%r15,%r12,4), %esi
movl %edx, (%r15,%r12,4)
movl %esi, (%r15,%r13,4)
movl (%r14,%r12,4), %edx
movl (%r14,%r13,4), %esi
movl %esi, (%r14,%r12,4)
movl %edx, (%r14,%r13,4)
incq %r12
decq %r13
jmp 0x1d396
movq %r8, 0x40(%rsp)
movq %rbp, %rcx
movq %r9, 0x48(%rsp)
subq %r9, %rcx
movq %r12, %rdx
subq %rbp, %rdx
cmpq %rcx, %rdx
movq %rdx, 0x70(%rsp)
cmovbq %rdx, %rcx
testq %rcx, %rcx
je 0x1d4d0
movq 0x58(%rsp), %rdi
leaq (%rdi,%r12,4), %rdx
movq 0x50(%rsp), %r9
leaq (%r9,%r12,4), %rsi
movq 0x48(%rsp), %r8
addq %rcx, %r8
negq %rcx
leaq (%rdi,%r8,4), %rdi
leaq (%r9,%r8,4), %r8
xorl %r9d, %r9d
movl (%r8,%r9,4), %r10d
movl (%rsi,%r9,4), %r11d
movl %r11d, (%r8,%r9,4)
movl %r10d, (%rsi,%r9,4)
movl (%rdi,%r9,4), %r10d
movl (%rdx,%r9,4), %r11d
movl %r11d, (%rdi,%r9,4)
movl %r10d, (%rdx,%r9,4)
decq %r9
cmpq %r9, %rcx
jne 0x1d4a8
movq %rbx, %rcx
subq %r13, %rcx
movq %rbx, %rdx
notq %rdx
movq %rdx, 0x68(%rsp)
leaq (%rax,%rdx), %rdi
cmpq %rcx, %rdi
movq %rcx, 0x60(%rsp)
cmovaeq %rcx, %rdi
testq %rdi, %rdi
je 0x1d544
movq %rdi, %rcx
negq %rcx
movq 0x58(%rsp), %rsi
leaq (%rsi,%rax,4), %rdx
movq 0x50(%rsp), %r8
leaq (%r8,%rax,4), %rax
addq %r12, %rdi
leaq (%rsi,%rdi,4), %rsi
leaq (%r8,%rdi,4), %rdi
xorl %r8d, %r8d
movl (%rdi,%r8,4), %r9d
movl (%rax,%r8,4), %r10d
movl %r10d, (%rdi,%r8,4)
movl %r9d, (%rax,%r8,4)
movl (%rsi,%r8,4), %r9d
movl (%rdx,%r8,4), %r10d
movl %r10d, (%rsi,%r8,4)
movl %r9d, (%rdx,%r8,4)
decq %r8
cmpq %r8, %rcx
jne 0x1d51c
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x78(%rsp)
xorl %eax, %eax
movq %rax, 0x80(%rsp)
movq $0x80, 0x88(%rsp)
movq %rax, 0x90(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1d932
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq $0x0, -0x8(%rax,%rcx)
cmpq %rbp, %r12
movq 0x70(%rsp), %rbp
je 0x1d639
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1d9b4
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
movq -0x8(%rax,%rcx), %rax
leaq (%rax,%rax,2), %rax
movq 0x48(%rsp), %rcx
movq %rcx, -0x18(%rdx,%rax,8)
leaq (%rcx,%rbp), %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
movq -0x8(%rcx,%rdx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rax, -0x10(%rsi,%rcx,8)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
movq -0x8(%rax,%rcx), %rax
leaq (%rax,%rax,2), %rax
movq 0x40(%rsp), %rcx
movq %rcx, -0x8(%rdx,%rax,8)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1d9b4
addq 0x48(%rsp), %rbp
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
movq -0x8(%rax,%rcx), %rax
leaq (%rax,%rax,2), %rax
movq %rbp, -0x18(%rdx,%rax,8)
addq 0x68(%rsp), %r12
addq 0x8(%rsp), %r12
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
movq -0x8(%rax,%rcx), %rax
leaq (%rax,%rax,2), %rax
movq %r12, -0x10(%rdx,%rax,8)
movq 0x40(%rsp), %rax
incq %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
movq -0x8(%rcx,%rdx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rax, -0x8(%rsi,%rcx,8)
cmpq %r13, %rbx
movq 0x120(%rsp), %rbx
movq 0x118(%rsp), %r12
je 0x1d789
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x1d9b4
movq 0x8(%rsp), %rax
subq 0x60(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
movq -0x8(%rcx,%rdx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rax, -0x18(%rsi,%rcx,8)
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq $0x5, %rdx
movq -0x18(%rcx,%rdx), %rsi
movq -0x8(%rcx,%rdx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rax, -0x10(%rsi,%rcx,8)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
movq -0x18(%rax,%rcx), %rdx
movq -0x8(%rax,%rcx), %rax
leaq (%rax,%rax,2), %rax
movq 0x40(%rsp), %rcx
movq %rcx, -0x8(%rdx,%rax,8)
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1d79b
callq 0x5440
movq 0x28(%rsp), %rsi
jmp 0x1d1fa
leaq 0x2(%r9), %rcx
movl 0x8(%r15,%r9,4), %edx
movq %rdx, %rsi
addq %r8, %rsi
cmpq 0x38(%rsp), %rsi
jae 0x1d7d3
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rdi
movsbl (%rdi,%rsi), %esi
cmpl $0x1, %esi
je 0x1d34e
jmp 0x1d7e2
movl 0x4(%rsp), %edi
movl %edi, %esi
cmpl $0x1, %edi
je 0x1d34e
cmpl $0x2, %esi
je 0x1d34e
leaq 0x3(%r9), %rcx
movl 0xc(%r15,%r9,4), %edx
movq %rdx, %rsi
addq %r8, %rsi
cmpq 0x38(%rsp), %rsi
jae 0x1d819
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rdi
movsbl (%rdi,%rsi), %esi
cmpl $0x1, %esi
je 0x1d34e
jmp 0x1d828
movl 0x4(%rsp), %edi
movl %edi, %esi
cmpl $0x1, %edi
je 0x1d34e
cmpl $0x2, %esi
je 0x1d34e
leaq 0x4(%r9), %rcx
movl 0x10(%r15,%r9,4), %edx
movq %rdx, %rsi
addq %r8, %rsi
cmpq 0x38(%rsp), %rsi
jae 0x1d85f
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rdi
movsbl (%rdi,%rsi), %esi
cmpl $0x1, %esi
je 0x1d34e
jmp 0x1d86e
movl 0x4(%rsp), %edi
movl %edi, %esi
cmpl $0x1, %edi
je 0x1d34e
cmpl $0x2, %esi
je 0x1d34e
jmp 0x1d36a
leaq 0x10(%rsp), %rdi
callq 0x1dbf8
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d8a0
jmp 0x1d8a0
jmp 0x1d8b7
jmp 0x1d8a0
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1d8ba
callq 0x5440
jmp 0x1d8ba
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1dbf8
movq %rbx, %rdi
callq 0x5680