// File: 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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movl %ecx, 0x30(%rsp)
movl %r8d, 0x2c(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x25279(%rip)     # 0x97500
movq 0x38(%rsp), %rax
movq %rax, 0x25275(%rip)     # 0x97508
movl 0x34(%rsp), %eax
movl 0x30(%rsp), %ecx
subl 0x2c(%rsp), %ecx
cmpl %ecx, %eax
jl 0x722e9
movq 0x25256(%rip), %rdi     # 0x97500
movq 0x25257(%rip), %rsi     # 0x97508
movl 0x34(%rsp), %edx
movl 0x30(%rsp), %ecx
movl 0x2c(%rsp), %r8d
movl 0x34(%rsp), %r9d
callq 0x724d0
movl %eax, 0x10(%rsp)
movq 0x2522d(%rip), %rdi     # 0x97500
movq 0x2522e(%rip), %rsi     # 0x97508
movl 0x34(%rsp), %edx
movl 0x10(%rsp), %ecx
callq 0x72960
jmp 0x7235e
movq 0x25210(%rip), %rdi     # 0x97500
movq 0x25211(%rip), %rsi     # 0x97508
movl 0x34(%rsp), %edx
movl 0x30(%rsp), %ecx
movl 0x2c(%rsp), %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
callq 0x724d0
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x34(%rsp), %eax
jg 0x72341
movl 0x14(%rsp), %edx
movq 0x251dc(%rip), %rax     # 0x97508
movslq 0x14(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x72317
movl $0x0, 0x251c5(%rip)     # 0x97510
movq 0x251b6(%rip), %rdi     # 0x97508
movl 0x34(%rsp), %esi
addl $0x1, %esi
callq 0x72b10
movl 0x251b0(%rip), %eax     # 0x97514
movl %eax, 0x251a6(%rip)     # 0x97510
movq 0x25197(%rip), %rax     # 0x97508
movl (%rax), %eax
xorl %ecx, %ecx
subl 0x34(%rsp), %ecx
cmpl %ecx, %eax
jl 0x7248c
movq 0x25180(%rip), %rax     # 0x97508
movq %rax, 0x20(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, %eax
jge 0x723d0
movl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %eax
addl 0x8(%rsp), %eax
movl %eax, 0x8(%rsp)
jmp 0x7243e
cmpl $0x0, 0x8(%rsp)
je 0x723f0
movl 0x8(%rsp), %edx
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, 0x8(%rsp)
movq 0x25111(%rip), %rax     # 0x97508
movq 0x25102(%rip), %rcx     # 0x97500
movslq 0xc(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
addq $0x4, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movl %eax, %esi
callq 0x72b10
movq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x72440
movq 0x20(%rsp), %rax
movq 0x250bc(%rip), %rcx     # 0x97508
movslq 0x34(%rsp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x72395
cmpl $0x0, 0x8(%rsp)
je 0x72479
movl 0x8(%rsp), %edx
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x25091(%rip), %eax     # 0x97510
shll %eax
movl %eax, 0x25089(%rip)     # 0x97510
jmp 0x7236a
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x34(%rsp), %eax
jg 0x724c9
movl 0x14(%rsp), %edx
movq 0x2505f(%rip), %rax     # 0x97508
movq 0x25050(%rip), %rcx     # 0x97500
movslq 0x14(%rsp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x72494
addq $0x48, %rsp
retq
nop