// File: BenLangmead[P]bowtie/./ls.h
// Function: LarssonSadakane<int>::suffixsort(int*, int*, int, int, int)
void suffixsort(T *x, T *p, T n, T k, T l)
	{
	   T *pi, *pk;
	   T i, j, s, sl;

	   V=x;                         /* set global values.*/
	   I=p;

	   if (n>=k-l) {                /* if bucketing possible,*/
		  j=transform(V, I, n, k, l, n);
		  bucketsort(V, I, n, j);   /* bucketsort on first r positions.*/
	   } else {
		  transform(V, I, n, k, l, std::numeric_limits<T>::max());
		  for (i=0; i<=n; ++i)
			 I[i]=i;                /* initialize I with suffix numbers.*/
		  h=0;
		  sort_split(I, n+1);       /* quicksort on first r positions.*/
	   }
	   h=r;                         /* number of symbols aggregated by transform.*/

	   while (*I>=-n) {
		  pi=I;                     /* pi is first position of group.*/
		  sl=0;                     /* sl is negated length of sorted groups.*/
		  do {
			 if ((s=*pi) <= 0 && (s=*pi) != 0) {
				pi-=s;              /* skip over sorted group.*/
				sl+=s;              /* add negated length to sl.*/
			 } else {
				if (sl) {
				   *(pi+sl)=sl;     /* combine sorted groups before pi.*/
				   sl=0;
				}
				pk=I+V[s]+1;        /* pk-1 is last position of unsorted group.*/
				sort_split(pi, (T)(pk-pi));
				pi=pk;              /* next group.*/
			 }
		  } while (pi<=I+n);
		  if (sl)                   /* if the array ends with a sorted group.*/
			 *(pi+sl)=sl;           /* combine sorted groups at end of I.*/
		  h=2*h;                    /* double sorted-depth.*/
	   }

	   for (i=0; i<=n; ++i)         /* reconstruct suffix array from inverse.*/
		  I[V[i]]=i;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2ac96
movq -0x50(%rbp), %rdi
movq 0x8(%rdi), %rsi
movq (%rdi), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movl -0x24(%rbp), %r9d
movl -0x1c(%rbp), %eax
movl %eax, (%rsp)
callq 0x2cd60
movq -0x50(%rbp), %rdi
movl %eax, -0x40(%rbp)
movq 0x8(%rdi), %rsi
movq (%rdi), %rdx
movl -0x1c(%rbp), %ecx
movl -0x40(%rbp), %r8d
callq 0x2d170
jmp 0x2ad23
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
callq 0x2d310
movq -0x50(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movl -0x5c(%rbp), %ecx
movl -0x58(%rbp), %r8d
movl -0x54(%rbp), %r9d
movl %eax, (%rsp)
callq 0x2cd60
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x2ad0a
movq -0x50(%rbp), %rax
movl -0x3c(%rbp), %edx
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2ace6
movq -0x50(%rbp), %rdi
movl $0x0, 0x14(%rdi)
movq (%rdi), %rsi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
callq 0x2d320
movq -0x50(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, 0x14(%rax)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
xorl %ecx, %ecx
subl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2ae3b
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
jg 0x2ad96
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0x2ad96
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x2adf5
cmpl $0x0, -0x48(%rbp)
je 0x2adb1
movl -0x48(%rbp), %edx
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movslq -0x44(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movl %eax, %edx
callq 0x2d320
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x2adf7
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rcx), %rcx
movslq -0x1c(%rbp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x2ad55
cmpl $0x0, -0x48(%rbp)
je 0x2ae2a
movl -0x48(%rbp), %edx
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movl 0x14(%rax), %ecx
shll %ecx
movl %ecx, 0x14(%rax)
jmp 0x2ad2d
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x2ae6e
movq -0x50(%rbp), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movslq -0x3c(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2ae42
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)