// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/qsufsort.c
// Function: transform
static int transform(int *x, int *p, int n, int k, int l, int q)
{
   int b, c, d, e, i, j, m, s;
   int *pi, *pj;

   for (s=0, i=k-l; i; i>>=1)
      ++s;                      /* s is number of bits in old symbol.*/
   e=INT_MAX>>s;                /* e is for overflow checking.*/
   for (b=d=r=0; r<n && d<=e && (c=d<<s|(k-l))<=q; ++r) {
      b=b<<s|(x[r]-l+1);        /* b is start of x in chunk alphabet.*/
      d=c;                      /* d is max symbol in chunk alphabet.*/
   }
   m=(1<<(r-1)*s)-1;            /* m masks off top old symbol from chunk.*/
   x[n]=l-1;                    /* emulate zero terminator.*/
   if (d<=n) {                  /* if bucketing possible, compact alphabet.*/
      for (pi=p; pi<=p+d; ++pi)
         *pi=0;                 /* zero transformation table.*/
      for (pi=x+r, c=b; pi<=x+n; ++pi) {
         p[c]=1;                /* mark used chunk symbol.*/
         c=(c&m)<<s|(*pi-l+1);  /* shift in next old symbol in chunk.*/
      }
      for (i=1; i<r; ++i) {     /* handle last r-1 positions.*/
         p[c]=1;                /* mark used chunk symbol.*/
         c=(c&m)<<s;            /* shift in next old symbol in chunk.*/
      }
      for (pi=p, j=1; pi<=p+d; ++pi)
         if (*pi)
            *pi=j++;            /* j is new alphabet size.*/
      for (pi=x, pj=x+r, c=b; pj<=x+n; ++pi, ++pj) {
         *pi=p[c];              /* transform to new alphabet.*/
         c=(c&m)<<s|(*pj-l+1);  /* shift in next old symbol in chunk.*/
      }
      while (pi<x+n) {          /* handle last r-1 positions.*/
         *pi++=p[c];            /* transform to new alphabet.*/
         c=(c&m)<<s;            /* shift right-end zero in chunk.*/
      }
   } else {                     /* bucketing not possible, don't compact.*/
      for (pi=x, pj=x+r, c=b; pj<=x+n; ++pi, ++pj) {
         *pi=c;                 /* transform to new alphabet.*/
         c=(c&m)<<s|(*pj-l+1);  /* shift in next old symbol in chunk.*/
      }
      while (pi<x+n) {          /* handle last r-1 positions.*/
         *pi++=c;               /* transform to new alphabet.*/
         c=(c&m)<<s;            /* shift right-end zero in chunk.*/
      }
      j=d+1;                    /* new alphabet size.*/
   }
   x[n]=0;                      /* end-of-string symbol is zero.*/
   return j;                    /* return new alphabet size.*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %eax
movl %edx, (%rsp)
movq %rsi, %r10
movq %rdi, %rbx
xorl %r12d, %r12d
movl $0x0, %ebp
subl %r8d, %eax
je 0x3e5b7
xorl %ebp, %ebp
movl %eax, %edx
movl %eax, %ecx
incl %ebp
sarl %ecx
cmpl $0x1, %edx
movl %ecx, %edx
ja 0x3e5ac
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %ebp, %ecx
shrl %cl, %edx
movl $0x0, %r14d
movl $0x0, %r13d
movl (%rsp), %esi
testl %esi, %esi
jle 0x3e619
movl %esi, %esi
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %edi, %edi
movl %edi, %r14d
movl %ebp, %ecx
shll %cl, %r14d
orl %eax, %r14d
cmpl %r9d, %r14d
jg 0x3e613
movl %r13d, %edi
movl %ebp, %ecx
shll %cl, %edi
movl (%rbx,%r12,4), %r13d
subl %r8d, %r13d
incl %r13d
orl %edi, %r13d
incq %r12
cmpq %rsi, %r12
jae 0x3e616
movl %r14d, %edi
cmpl %edx, %r14d
jle 0x3e5e0
jmp 0x3e616
movl %edi, %r14d
movl (%rsp), %esi
leal -0x1(%r12), %r15d
movl %r15d, %ecx
imull %ebp, %ecx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
shll %cl, %r11d
movl %r12d, 0x15e10(%rip)    # 0x54444
notl %r11d
leal -0x1(%r8), %eax
movslq %esi, %rcx
leaq (%rbx,%rcx,4), %r9
movl %eax, (%r9)
cmpl %esi, %r14d
jle 0x3e65b
cmpl %esi, %r12d
jle 0x3e748
movl %r13d, %eax
jmp 0x3e788
movslq %r14d, %rax
testl %r14d, %r14d
movq %rax, 0x8(%rsp)
js 0x3e6c5
movq 0x8(%rsp), %rax
leaq (%r10,%rax,4), %rax
incq %rax
leaq 0x4(%r10), %rcx
cmpq %rcx, %rax
cmovaq %rax, %rcx
movq %r10, %rdx
notq %rdx
addq %rcx, %rdx
andq $-0x4, %rdx
addq $0x4, %rdx
movq %r10, %rdi
xorl %esi, %esi
movq %r8, 0x20(%rsp)
movq %r10, 0x18(%rsp)
movq %r9, 0x10(%rsp)
movl %r11d, 0x4(%rsp)
callq 0x7180
movl (%rsp), %esi
movl 0x4(%rsp), %r11d
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r8
movl %r12d, %eax
movl %r13d, %edx
cmpl %esi, %r12d
jg 0x3e6fb
leaq (%rbx,%rax,4), %rsi
movl %r13d, %edx
movslq %edx, %rdi
movl $0x1, (%r10,%rdi,4)
andl %r11d, %edi
movl %ebp, %ecx
shll %cl, %edi
movl (%rsi), %edx
subl %r8d, %edx
incl %edx
orl %edi, %edx
addq $0x4, %rsi
cmpq %r9, %rsi
jbe 0x3e6d7
cmpl $0x2, %r12d
jb 0x3e718
movslq %edx, %rdx
movl $0x1, (%r10,%rdx,4)
andl %r11d, %edx
movl %ebp, %ecx
shll %cl, %edx
decl %r15d
jne 0x3e701
testl %r14d, %r14d
movq 0x8(%rsp), %rcx
js 0x3e792
leaq (%r10,%rcx,4), %rcx
movl $0x1, %r14d
movq %r10, %rdx
movl (%rsp), %esi
cmpl $0x0, (%rdx)
je 0x3e73d
movl %r14d, (%rdx)
incl %r14d
addq $0x4, %rdx
cmpq %rcx, %rdx
jbe 0x3e732
jmp 0x3e79b
movl %r12d, %edx
shlq $0x2, %rdx
movl %r13d, (%rbx)
andl %r11d, %r13d
movl %ebp, %ecx
shll %cl, %r13d
leaq (%rbx,%rdx), %rcx
addq $0x4, %rcx
movl -0x4(%rcx), %eax
subl %r8d, %eax
incl %eax
orl %r13d, %eax
addq $0x4, %rbx
movl %eax, %r13d
cmpq %r9, %rcx
jbe 0x3e74f
jmp 0x3e788
movl %eax, (%rbx)
addq $0x4, %rbx
andl %r11d, %eax
movl %ebp, %ecx
shll %cl, %eax
cmpq %r9, %rbx
jb 0x3e77b
incl %r14d
jmp 0x3e7ee
movl $0x1, %r14d
movl (%rsp), %esi
cmpl %esi, %r12d
jg 0x3e7e9
shlq $0x2, %rax
movslq %r13d, %rdx
movl (%r10,%rdx,4), %esi
andl %r11d, %edx
movl %ebp, %ecx
shll %cl, %edx
movl %esi, (%rbx)
leaq (%rbx,%rax), %rcx
addq $0x4, %rcx
movl -0x4(%rcx), %r13d
subl %r8d, %r13d
incl %r13d
orl %edx, %r13d
addq $0x4, %rbx
cmpq %r9, %rcx
jbe 0x3e7a4
jmp 0x3e7e9
movslq %r13d, %r13
movl (%r10,%r13,4), %eax
movl %eax, (%rbx)
addq $0x4, %rbx
andl %r11d, %r13d
movl %ebp, %ecx
shll %cl, %r13d
cmpq %r9, %rbx
jb 0x3e7d4
movl $0x0, (%r9)
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq