// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x120(%rsp), %rbx
movq 0x118(%rsp), %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x20(%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)
movq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
je 0x1d457
movq 0x28(%rsp), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
cmpq $0x0, -0x8(%rax,%rcx)
je 0x1d476
addq %rcx, %rax
movq -0x18(%rax), %rcx
movq (%rcx), %r10
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movq -0x18(%rax), %rcx
movq -0x8(%rax), %rsi
movq 0x10(%rcx), %r9
decq %rsi
je 0x1d451
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 0x1d427
movq %rsi, -0x8(%rax)
jmp 0x1d495
movq 0x108(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x110(%rsp), %r9
movq 0x100(%rsp), %r10
jmp 0x1d495
decq %rsi
leaq 0x20(%rsp), %rdi
callq 0x1db10
cmpq $0x0, 0x38(%rsp)
je 0x1daaf
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpq %r12, %r9
jne 0x1d4b5
testq %rbx, %rbx
je 0x1d3d8
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x11de4
jmp 0x1d3d8
movq 0x18(%rsp), %rax
movq %rax, %rcx
subq %r10, %rcx
cmpq $0x1, %rcx
ja 0x1d4eb
testq %rbx, %rbx
je 0x1d3d8
cmpq $0x1, %rcx
jne 0x1d3d8
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x11de4
jmp 0x1d3d8
cmpq $0x5, %rcx
jb 0x1d645
movl 0x4(%r15,%r10,4), %edx
addq %r9, %rdx
movl 0x4(%rsp), %esi
cmpq 0x10(%rsp), %rdx
jae 0x1d515
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx,%rdx), %esi
leaq 0x1(%r10), %rcx
cmpl $0x1, %esi
je 0x1d620
movl 0x4(%rsp), %esi
cmpq 0x10(%rsp), %rdx
jae 0x1d53a
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %esi
cmpl $0x2, %esi
je 0x1d620
movl 0x8(%r15,%r10,4), %edx
addq %r9, %rdx
movl 0x4(%rsp), %esi
cmpq 0x10(%rsp), %rdx
jae 0x1d563
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx,%rdx), %esi
leaq 0x2(%r10), %rcx
cmpl $0x1, %esi
je 0x1d620
movl 0x4(%rsp), %esi
cmpq 0x10(%rsp), %rdx
jae 0x1d588
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %esi
cmpl $0x2, %esi
je 0x1d620
movl 0xc(%r15,%r10,4), %edx
addq %r9, %rdx
movl 0x4(%rsp), %esi
cmpq 0x10(%rsp), %rdx
jae 0x1d5b1
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx,%rdx), %esi
leaq 0x3(%r10), %rcx
cmpl $0x1, %esi
je 0x1d620
movl 0x4(%rsp), %esi
cmpq 0x10(%rsp), %rdx
jae 0x1d5d2
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rsi
movsbl (%rsi,%rdx), %esi
cmpl $0x2, %esi
je 0x1d620
movl 0x10(%r15,%r10,4), %ecx
addq %r9, %rcx
movl 0x4(%rsp), %edx
cmpq 0x10(%rsp), %rcx
jae 0x1d5f7
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rdx
movsbl (%rdx,%rcx), %edx
cmpl $0x1, %edx
je 0x1d61c
movl 0x4(%rsp), %edx
cmpq 0x10(%rsp), %rcx
jae 0x1d614
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rdx
movsbl (%rdx,%rcx), %edx
movq %r10, %rcx
cmpl $0x2, %edx
jne 0x1d620
leaq 0x4(%r10), %rcx
cmpq %r10, %rcx
je 0x1d645
movl (%r15,%r10,4), %edx
movl (%r15,%rcx,4), %esi
movl %esi, (%r15,%r10,4)
movl %edx, (%r15,%rcx,4)
movl (%r14,%r10,4), %edx
movl (%r14,%rcx,4), %esi
movl %esi, (%r14,%r10,4)
movl %edx, (%r14,%rcx,4)
movl (%r15,%r10,4), %edx
addq %r9, %rdx
movl 0x4(%rsp), %ecx
cmpq 0x10(%rsp), %rdx
jae 0x1d664
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx,%rdx), %ecx
leaq -0x1(%rax), %r13
movq %r10, %rbp
movq %r10, %r12
movq %r13, %rbx
cmpq %r13, %r12
ja 0x1d6e4
movl (%r15,%r12,4), %edx
leaq (%r9,%rdx), %rsi
movl 0x4(%rsp), %edi
cmpq 0x10(%rsp), %rsi
jae 0x1d696
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rdi
movsbl (%rdi,%rsi), %edi
cmpl %edi, %ecx
jl 0x1d6e4
jne 0x1d6bb
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 0x1d671
jne 0x1d6e1
movl (%r15,%rbx,4), %edx
movl %edx, (%r15,%r13,4)
movl %esi, (%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
seta %dl
ja 0x1d718
movl (%r15,%r13,4), %esi
leaq (%r9,%rsi), %rdi
movl 0x4(%rsp), %r8d
cmpq 0x10(%rsp), %rdi
jae 0x1d70e
movq 0x8(%rsp), %r8
movq 0x8(%r8), %r8
movsbl (%r8,%rdi), %r8d
cmpl %r8d, %ecx
jle 0x1d6c0
testb $0x1, %dl
je 0x1d724
xorl %edx, %edx
testb %dl, %dl
jne 0x1d671
jmp 0x1d74e
movl (%r15,%r12,4), %edx
movl (%r15,%r13,4), %esi
movl %esi, (%r15,%r12,4)
movl %edx, (%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
movb $0x1, %dl
jmp 0x1d71a
movq %r9, 0x40(%rsp)
movq %rbp, %rcx
movq %r10, 0x48(%rsp)
subq %r10, %rcx
movq %r12, %rdx
subq %rbp, %rdx
cmpq %rcx, %rdx
movq %rdx, 0x90(%rsp)
cmovbq %rdx, %rcx
testq %rcx, %rcx
je 0x1d7c8
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 0x1d7a0
movq %rbx, %rdx
subq %r13, %rdx
movq %rbx, %rcx
notq %rcx
movq %rcx, 0x88(%rsp)
addq %rax, %rcx
cmpq %rdx, %rcx
movq %rdx, 0x80(%rsp)
cmovaeq %rdx, %rcx
testq %rcx, %rcx
je 0x1d83f
movq 0x58(%rsp), %rsi
leaq (%rsi,%rax,4), %rdx
movq 0x50(%rsp), %r8
leaq (%r8,%rax,4), %rax
leaq (%r12,%rcx), %rdi
negq %rcx
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 0x1d817
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x60(%rsp)
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movq $0x80, 0x70(%rsp)
movq %rax, 0x78(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x1db76
movq 0x28(%rsp), %rax
movq 0x38(%rsp), %rcx
shlq $0x5, %rcx
movq $0x0, -0x8(%rax,%rcx)
cmpq %rbp, %r12
movq 0x90(%rsp), %rbp
je 0x1d92e
movq 0x28(%rsp), %rax
movq 0x38(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1dbe8
movq 0x28(%rsp), %rax
movq 0x38(%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 0x28(%rsp), %rcx
movq 0x38(%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 0x28(%rsp), %rax
movq 0x38(%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 0x28(%rsp), %rax
movq 0x38(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1dbe8
addq 0x48(%rsp), %rbp
movq 0x28(%rsp), %rax
movq 0x38(%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 0x88(%rsp), %r12
addq 0x18(%rsp), %r12
movq 0x28(%rsp), %rax
movq 0x38(%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 0x28(%rsp), %rcx
movq 0x38(%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 0x1da84
movq 0x28(%rsp), %rax
movq 0x38(%rsp), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x20, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x1dbe8
movq 0x18(%rsp), %rax
subq 0x80(%rsp), %rax
movq 0x28(%rsp), %rcx
movq 0x38(%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 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
movq 0x38(%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 0x28(%rsp), %rax
movq 0x38(%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 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x1d3d8
callq 0x5450
leaq 0x68(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
jmp 0x1d3d8
leaq 0x20(%rsp), %rdi
callq 0x1de1a
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1dad3
jmp 0x1dafa
jmp 0x1dad3
jmp 0x1dad3
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x1dafd
callq 0x5450
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %rax
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
jmp 0x1dafd
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1de1a
movq %rbx, %rdi
callq 0x56a0
nop