// File: /workspace/github_cpp_makefile_star2_O2/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
movl %ecx, %r10d
subl %r8d, %r10d
xorl %r11d, %r11d
movl %r10d, %eax
testl %eax, %eax
je 0x2fb24
sarl %eax
decl %r11d
jmp 0x2fb19
movl %r11d, %ebx
negl %ebx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl %ebx, %ecx
shrl %cl, %ebp
movslq %edx, %r12
xorl %r15d, %r15d
movq %rdi, %r14
xorl %eax, %eax
xorl %edx, %edx
cmpq %r12, %r15
jge 0x2fb75
cmpl %ebp, %eax
jg 0x2fb75
movl %eax, %r13d
movl %ebx, %ecx
shll %cl, %r13d
orl %r10d, %r13d
cmpl %r9d, %r13d
jg 0x2fb75
movl %ebx, %ecx
shll %cl, %edx
movl (%r14), %eax
subl %r8d, %eax
incl %eax
orl %eax, %edx
incq %r15
addl %ebx, %r11d
addq $0x4, %r14
movl %r13d, %eax
jmp 0x2fb3f
movl %r15d, 0x1a8c0(%rip)    # 0x4a43c
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %r11d, %ecx
shll %cl, %r10d
notl %r10d
leal -0x1(%r8), %ecx
leaq (%rdi,%r12,4), %r9
movl %ecx, (%r9)
cmpl %r12d, %eax
jle 0x2fbd6
cmpq %r9, %r14
ja 0x2fbca
movl %edx, (%rdi)
andl %r10d, %edx
movl %ebx, %ecx
shll %cl, %edx
movl (%r14), %ecx
subl %r8d, %ecx
incl %ecx
orl %ecx, %edx
addq $0x4, %rdi
addq $0x4, %r14
jmp 0x2fb9b
movl %edx, (%rdi)
addq $0x4, %rdi
andl %r10d, %edx
movl %ebx, %ecx
shll %cl, %edx
cmpq %r9, %rdi
jb 0x2fbbd
incl %eax
jmp 0x2fc99
cltq
leaq (%rsi,%rax,4), %r11
movq %rsi, %rax
cmpq %r11, %rax
ja 0x2fbed
andl $0x0, (%rax)
addq $0x4, %rax
jmp 0x2fbdf
movl %edx, %eax
movq %r14, %r12
cmpq %r9, %r12
ja 0x2fc1c
movslq %eax, %r13
movl $0x1, (%rsi,%r13,4)
andl %r10d, %r13d
movl %ebx, %ecx
shll %cl, %r13d
movl (%r12), %eax
subl %r8d, %eax
incl %eax
orl %r13d, %eax
addq $0x4, %r12
jmp 0x2fbf2
movl $0x1, %ebp
cmpl %r15d, %ebp
jae 0x2fc3a
cltq
movl $0x1, (%rsi,%rax,4)
andl %r10d, %eax
movl %ebx, %ecx
shll %cl, %eax
incl %ebp
jmp 0x2fc21
movl $0x1, %eax
movq %rsi, %rcx
cmpq %r11, %rcx
ja 0x2fc7a
cmpl $0x0, (%rcx)
je 0x2fc50
movl %eax, (%rcx)
incl %eax
addq $0x4, %rcx
jmp 0x2fc42
movslq %edx, %r11
movl (%rsi,%r11,4), %edx
andl %r10d, %r11d
movl %ebx, %ecx
shll %cl, %r11d
movl %edx, (%rdi)
movl (%r14), %edx
subl %r8d, %edx
incl %edx
orl %r11d, %edx
addq $0x4, %rdi
addq $0x4, %r14
cmpq %r9, %r14
jbe 0x2fc56
jmp 0x2fc94
movslq %edx, %rdx
movl (%rsi,%rdx,4), %ecx
movl %ecx, (%rdi)
addq $0x4, %rdi
andl %r10d, %edx
movl %ebx, %ecx
shll %cl, %edx
cmpq %r9, %rdi
jb 0x2fc81
andl $0x0, (%r9)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq