// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/qsufsort.c
// Function: suffixsort
void suffixsort(int *x, int *p, int n, int k, int l)
{
   int *pi, *pk;
   int 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, INT_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) {
            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, 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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movq %rdi, 0x1aadd(%rip)     # 0x4a428
movq %rsi, 0x1aade(%rip)     # 0x4a430
movl %ecx, %eax
subl %r8d, %eax
cmpl %edx, %eax
jle 0x2f987
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
callq 0x2fb03
movq 0x1aabb(%rip), %rdi     # 0x4a430
movslq %ebx, %r12
xorl %eax, %eax
cmpq %r12, %rax
jg 0x2f9b2
movl %eax, (%rdi,%rax,4)
incq %rax
jmp 0x2f97a
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl %ebx, %r9d
callq 0x2fb03
cltq
leaq (%r14,%rax,4), %rax
movq %r14, %rcx
cmpq %rax, %rcx
jae 0x2fa82
orl $-0x1, (%rcx)
addq $0x4, %rcx
jmp 0x2f9a0
andl $0x0, 0x1aa7f(%rip)     # 0x4a438
leal 0x1(%rbx), %esi
callq 0x2fca8
movq 0x1aa68(%rip), %r14     # 0x4a430
movl 0x1aa6e(%rip), %eax     # 0x4a43c
negl %ebx
movl %eax, 0x1aa62(%rip)     # 0x4a438
movl (%r14), %ecx
cmpl %ebx, %ecx
jl 0x2fa5b
xorl %eax, %eax
movq %r14, %rdi
testl %ecx, %ecx
js 0x2fa2b
testl %eax, %eax
je 0x2f9f0
movslq %eax, %rdx
movl %eax, (%rdi,%rdx,4)
movq 0x1aa31(%rip), %rax     # 0x4a428
movl %ecx, %ecx
movslq (%rax,%rcx,4), %rax
leaq (%r14,%rax,4), %r15
addq $0x4, %r15
movq %r15, %rsi
subq %rdi, %rsi
shrq $0x2, %rsi
callq 0x2fca8
movq 0x1aa15(%rip), %r14     # 0x4a430
leaq (%r14,%r12,4), %rcx
xorl %eax, %eax
movq %r15, %rdi
cmpq %rcx, %r15
jbe 0x2fa40
jmp 0x2fa4e
movslq %ecx, %rdx
shlq $0x2, %rdx
subq %rdx, %rdi
addl %ecx, %eax
leaq (%r14,%r12,4), %rcx
cmpq %rcx, %rdi
ja 0x2fa44
movl (%rdi), %ecx
jmp 0x2f9e2
testl %eax, %eax
je 0x2fa4e
movslq %eax, %rcx
movl %eax, (%rdi,%rcx,4)
movl 0x1a9e4(%rip), %eax     # 0x4a438
addl %eax, %eax
jmp 0x2f9d0
movq 0x1a9c6(%rip), %rax     # 0x4a428
xorl %ecx, %ecx
cmpq %r12, %rcx
jg 0x2fa76
movslq (%rax,%rcx,4), %rdx
movl %ecx, (%r14,%rdx,4)
incq %rcx
jmp 0x2fa64
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movslq %ebx, %r12
testq %r12, %r12
pushq $-0x1
popq %rcx
cmovnsq %r12, %rcx
incq %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2faae
movslq (%r15,%rdx,4), %rsi
movl (%r14,%rsi,4), %edi
movl %edi, (%r15,%rdx,4)
movl %edx, (%r14,%rsi,4)
incq %rdx
jmp 0x2fa94
movl %ebx, %ecx
addq $-0x4, %rax
cmpq %r14, %rax
jb 0x2f9c8
movslq (%rax), %rdi
movl (%r15,%rdi,4), %esi
movl %ecx, (%r15,%rdi,4)
leal -0x1(%rcx), %edx
movslq %ecx, %r8
testl %esi, %esi
js 0x2fafa
movl %edi, (%r14,%r8,4)
movslq %edx, %rdi
leaq (%r14,%rdi,4), %rdi
movl %esi, %r8d
movl (%r15,%r8,4), %r9d
movl %ecx, (%r15,%r8,4)
movl %esi, (%rdi)
addq $-0x4, %rdi
decl %edx
movl %r9d, %esi
testl %r9d, %r9d
jns 0x2fadd
jmp 0x2faff
orl $-0x1, (%r14,%r8,4)
movl %edx, %ecx
jmp 0x2fab0