// File: /workspace/github_cpp_makefile_star2_O2/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
movl %ecx, %eax
movl 0x38(%rsp), %ebp
subl %r9d, %r8d
xorl %r11d, %r11d
movl %r8d, %ecx
testl %ecx, %ecx
je 0x17878
sarl %ecx
decl %r11d
jmp 0x1786d
movl %r11d, %r10d
negl %r10d
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl %r10d, %ecx
shrl %cl, %r15d
movslq %eax, %r14
xorl %r12d, %r12d
xorl %eax, %eax
xorl %ebx, %ebx
movl %r12d, 0x10(%rdi)
cmpq %r14, %r12
jge 0x178ce
cmpl %r15d, %eax
jg 0x178ce
movl %eax, %r13d
movl %r10d, %ecx
shll %cl, %r13d
orl %r8d, %r13d
cmpl %ebp, %r13d
jg 0x178ce
movl %r10d, %ecx
shll %cl, %ebx
movl (%rsi,%r12,4), %eax
subl %r9d, %eax
incl %eax
orl %eax, %ebx
incq %r12
addl %r10d, %r11d
movl %r13d, %eax
jmp 0x17894
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %r11d, %ecx
shll %cl, %ebp
notl %ebp
leal -0x1(%r9), %ecx
leaq (%rsi,%r14,4), %r8
movl %ecx, (%r8)
cmpl %r14d, %eax
jle 0x1792c
movslq 0x10(%rdi), %rdx
shlq $0x2, %rdx
leaq (%rsi,%rdx), %rdi
cmpq %r8, %rdi
ja 0x17920
movl %ebx, (%rsi)
andl %ebp, %ebx
movl %r10d, %ecx
shll %cl, %ebx
movl (%rdi), %ecx
subl %r9d, %ecx
incl %ecx
orl %ecx, %ebx
addq $0x4, %rsi
jmp 0x178f2
movl %ebx, (%rsi)
addq $0x4, %rsi
andl %ebp, %ebx
movl %r10d, %ecx
shll %cl, %ebx
cmpq %r8, %rsi
jb 0x17913
incl %eax
jmp 0x17a00
cltq
leaq (%rdx,%rax,4), %r11
movq %rdx, %rax
cmpq %r11, %rax
ja 0x17943
andl $0x0, (%rax)
addq $0x4, %rax
jmp 0x17935
movslq 0x10(%rdi), %rax
leaq (%rsi,%rax,4), %r14
movl %ebx, %eax
cmpq %r8, %r14
ja 0x17977
movslq %eax, %r15
movl $0x1, (%rdx,%r15,4)
andl %ebp, %r15d
movl %r10d, %ecx
shll %cl, %r15d
movl (%r14), %eax
subl %r9d, %eax
incl %eax
orl %r15d, %eax
addq $0x4, %r14
jmp 0x1794d
movl $0x1, %r14d
cmpl 0x10(%rdi), %r14d
jge 0x17998
cltq
movl $0x1, (%rdx,%rax,4)
andl %ebp, %eax
movl %r10d, %ecx
shll %cl, %eax
incl %r14d
jmp 0x1797d
movl $0x1, %eax
movq %rdx, %rcx
cmpq %r11, %rcx
ja 0x179b4
cmpl $0x0, (%rcx)
je 0x179ae
movl %eax, (%rcx)
incl %eax
addq $0x4, %rcx
jmp 0x179a0
movslq 0x10(%rdi), %rdi
shlq $0x2, %rdi
leaq (%rsi,%rdi), %r11
cmpq %r8, %r11
ja 0x179fb
movslq %ebx, %r14
movl (%rdx,%r14,4), %ecx
movl %ecx, (%rsi)
andl %ebp, %r14d
movl %r10d, %ecx
shll %cl, %r14d
movl (%r11), %ebx
subl %r9d, %ebx
incl %ebx
orl %r14d, %ebx
addq $0x4, %rsi
jmp 0x179bc
movslq %ebx, %rbx
movl (%rdx,%rbx,4), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
andl %ebp, %ebx
movl %r10d, %ecx
shll %cl, %ebx
cmpq %r8, %rsi
jb 0x179e8
andl $0x0, (%r8)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop