// File: /workspace/github_cpp_makefile_star2_O3/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 %ebp, %ebp
subl %r8d, %eax
je 0x3e43a
movl %eax, %edx
movl %eax, %ecx
incl %ebp
sarl %ecx
cmpl $0x1, %edx
movl %ecx, %edx
ja 0x3e42f
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %ebp, %ecx
shrl %cl, %esi
movl (%rsp), %edi
testl %edi, %edi
jle 0x3e48a
movl %edi, %edx
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 0x3e498
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 %rdx, %r12
jae 0x3e49b
movl %r14d, %edi
cmpl %esi, %r14d
jle 0x3e457
jmp 0x3e49b
movslq %edi, %rdx
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
jmp 0x3e49e
movl %edi, %r14d
movl (%rsp), %edi
movl %r12d, 0x15f9f(%rip)    # 0x54444
leal -0x1(%r12), %r15d
movl %r15d, %ecx
imull %ebp, %ecx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
shll %cl, %r11d
notl %r11d
leal -0x1(%r8), %eax
leaq (%rbx,%rdx,4), %r9
movl %eax, (%r9)
cmpl %edi, %r14d
jle 0x3e4dd
cmpl %edi, %r12d
jle 0x3e5ca
movl %r13d, %eax
jmp 0x3e60a
movslq %r14d, %rax
testl %r14d, %r14d
movq %rax, 0x8(%rsp)
js 0x3e547
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), %edi
movl 0x4(%rsp), %r11d
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r8
movl %r12d, %eax
movl %r13d, %edx
cmpl %edi, %r12d
jg 0x3e57d
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 0x3e559
cmpl $0x2, %r12d
jb 0x3e59a
movslq %edx, %rdx
movl $0x1, (%r10,%rdx,4)
andl %r11d, %edx
movl %ebp, %ecx
shll %cl, %edx
decl %r15d
jne 0x3e583
testl %r14d, %r14d
movq 0x8(%rsp), %rcx
js 0x3e614
leaq (%r10,%rcx,4), %rcx
movl $0x1, %r14d
movq %r10, %rdx
movl (%rsp), %esi
cmpl $0x0, (%rdx)
je 0x3e5bf
movl %r14d, (%rdx)
incl %r14d
addq $0x4, %rdx
cmpq %rcx, %rdx
jbe 0x3e5b4
jmp 0x3e61d
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 0x3e5d1
jmp 0x3e60a
movl %eax, (%rbx)
addq $0x4, %rbx
andl %r11d, %eax
movl %ebp, %ecx
shll %cl, %eax
cmpq %r9, %rbx
jb 0x3e5fd
incl %r14d
jmp 0x3e670
movl $0x1, %r14d
movl (%rsp), %esi
cmpl %esi, %r12d
jg 0x3e66b
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 0x3e626
jmp 0x3e66b
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 0x3e656
movl $0x0, (%r9)
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq