// File: /workspace/github_cpp_makefile_star2_O3/BenLangmead[P]bowtie/./ls.h
// Function: LarssonSadakane<int>::transform(int*, int*, int, int, int, int)
inline T transform(T *x, T *p, T n, T k, T l, T q)
	{
	   T b, c, d, e, i, j, m, s;
	   T *pi, *pj;

	   for (s=0, i=k-l; i; i>>=1)
		  ++s;                      /* s is number of bits in old symbol.*/
	   e=std::numeric_limits<T>::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=(((T)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, %r11d
movq %rdx, %r10
movq %rsi, %rbx
xorl %ebp, %ebp
subl %r9d, %r8d
je 0x1de41
movl %r8d, %ecx
movl %r8d, %eax
incl %ebp
sarl %eax
cmpl $0x1, %ecx
movl %eax, %ecx
ja 0x1de36
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %ebp, %ecx
shrl %cl, %esi
movl $0x0, 0x10(%rdi)
testl %r11d, %r11d
movq %r10, 0x8(%rsp)
jle 0x1deb2
movl 0x60(%rsp), %r15d
movl %r11d, %r12d
movl %r11d, %edx
xorl %eax, %eax
movl $0x1, %r11d
xorl %r13d, %r13d
xorl %r10d, %r10d
movl %r10d, %r14d
movl %ebp, %ecx
shll %cl, %r14d
orl %r8d, %r14d
cmpl %r15d, %r14d
jg 0x1dec2
movl %r13d, %r10d
movl %ebp, %ecx
shll %cl, %r10d
movl -0x4(%rbx,%r11,4), %r13d
subl %r9d, %r13d
incl %r13d
orl %r10d, %r13d
movl %r11d, 0x10(%rdi)
incl %eax
cmpq %rdx, %r11
jae 0x1dec5
incq %r11
movl %r14d, %r10d
cmpl %esi, %r14d
jle 0x1de77
jmp 0x1dec5
movslq %r11d, %rdx
xorl %r14d, %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
jmp 0x1decf
movl %r10d, %r14d
decl %eax
movq 0x8(%rsp), %r10
movl %r12d, %r11d
imull %ebp, %eax
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %eax, %ecx
shll %cl, %r15d
notl %r15d
leal -0x1(%r9), %eax
leaq (%rbx,%rdx,4), %r12
movl %eax, (%r12)
cmpl %r11d, %r14d
jle 0x1df02
movslq 0x10(%rdi), %rdx
cmpl %r11d, %edx
jle 0x1df71
movl %r13d, %eax
jmp 0x1dfae
movslq %r14d, %r8
testl %r14d, %r14d
js 0x1df64
leaq (%r10,%r8,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 %rdi, 0x18(%rsp)
movq %r10, %rdi
xorl %esi, %esi
movq %r9, 0x20(%rsp)
movl %r11d, 0x4(%rsp)
movq %r8, 0x10(%rsp)
callq 0x51b0
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rdi
movl 0x4(%rsp), %r11d
movq 0x8(%rsp), %r10
movq 0x20(%rsp), %r9
movl 0x10(%rdi), %ecx
cmpl %r11d, %ecx
jle 0x1dfbb
movl %r13d, %eax
jmp 0x1dfec
shlq $0x2, %rdx
movl %r13d, (%rbx)
andl %r15d, %r13d
movl %ebp, %ecx
shll %cl, %r13d
leaq (%rbx,%rdx), %rcx
addq $0x4, %rcx
movl -0x4(%rcx), %eax
subl %r9d, %eax
incl %eax
orl %r13d, %eax
addq $0x4, %rbx
movl %eax, %r13d
cmpq %r12, %rcx
jbe 0x1df75
jmp 0x1dfae
movl %eax, (%rbx)
addq $0x4, %rbx
andl %r15d, %eax
movl %ebp, %ecx
shll %cl, %eax
cmpq %r12, %rbx
jb 0x1dfa1
incl %r14d
jmp 0x1e097
movslq %ecx, %rax
leaq (%rbx,%rax,4), %rdx
movl %r13d, %eax
movslq %eax, %rsi
movl $0x1, (%r10,%rsi,4)
andl %r15d, %esi
movl %ebp, %ecx
shll %cl, %esi
movl (%rdx), %eax
subl %r9d, %eax
incl %eax
orl %esi, %eax
addq $0x4, %rdx
cmpq %r12, %rdx
jbe 0x1dfc5
movl 0x10(%rdi), %ecx
cmpl $0x2, %ecx
jl 0x1e010
movl $0x1, %edx
cltq
movl $0x1, (%r10,%rax,4)
andl %r15d, %eax
movl %ebp, %ecx
shll %cl, %eax
incl %edx
movl 0x10(%rdi), %ecx
cmpl %ecx, %edx
jl 0x1dff6
testl %r14d, %r14d
js 0x1e03b
leaq (%r10,%r8,4), %rax
movl $0x1, %r14d
movq %r10, %rcx
cmpl $0x0, (%rcx)
je 0x1e02d
movl %r14d, (%rcx)
incl %r14d
addq $0x4, %rcx
cmpq %rax, %rcx
jbe 0x1e022
movl 0x10(%rdi), %ecx
jmp 0x1e041
movl $0x1, %r14d
cmpl %r11d, %ecx
jg 0x1e092
movslq %ecx, %rax
shlq $0x2, %rax
movslq %r13d, %rdx
movl (%r10,%rdx,4), %esi
andl %r15d, %edx
movl %ebp, %ecx
shll %cl, %edx
movl %esi, (%rbx)
leaq (%rbx,%rax), %rcx
addq $0x4, %rcx
movl -0x4(%rcx), %r13d
subl %r9d, %r13d
incl %r13d
orl %edx, %r13d
addq $0x4, %rbx
cmpq %r12, %rcx
jbe 0x1e04d
jmp 0x1e092
movslq %r13d, %r13
movl (%r10,%r13,4), %eax
movl %eax, (%rbx)
addq $0x4, %rbx
andl %r15d, %r13d
movl %ebp, %ecx
shll %cl, %r13d
cmpq %r12, %rbx
jb 0x1e07d
movl $0x0, (%r12)
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop