// File: /workspace/github_cpp_makefile_star2_O3/dgboy2000[P]compress/compress.cpp
// Function: SuffixArray::doSuffixArrayComputation(int*, int*, int, int)
void SuffixArray::doSuffixArrayComputation(int* s, int* SA, int n, int K) {
    int n0=(n+2)/3, n1=(n+1)/3, n2=n/3, n02=n0+n2;
    int* s12 = new int[n02 + 3]; s12[n02]= s12[n02+1]= s12[n02+2]=0;
    int* SA12 = new int[n02 + 3]; SA12[n02]=SA12[n02+1]=SA12[n02+2]=0;
    int* s0 = new int[n0];
    int* SA0 = new int[n0];
// generate positions of mod 1 and mod 2 suffixes
// the "+(n0-n1)" adds a dummy mod 1 suffix if n%3 == 1
    for (int i=0, j=0; i < n+(n0-n1); i++) if (i%3 != 0) s12[j++] = i;
// lsb radix sort the mod 1 and mod 2 triples
    radixPass(s12 , SA12, s+2, n02, K);
    radixPass(SA12, s12 , s+1, n02, K);
    radixPass(s12 , SA12, s , n02, K);
// find lexicographic names of triples
    int name = 0, c0 = -1, c1 = -1, c2 = -1;
    for (int i = 0; i < n02; i++) {
        if (s[SA12[i]] != c0 || s[SA12[i]+1] != c1 || s[SA12[i]+2] != c2)
            {name++; c0 = s[SA12[i]]; c1 = s[SA12[i]+1]; c2 = s[SA12[i]+2]; }
        if (SA12[i] % 3 == 1) { s12[SA12[i]/3] = name; } // left half
        else {s12[SA12[i]/3 + n0] = name; } // right half
    }
// recurse if names are not yet unique
    if (name < n02) {
        doSuffixArrayComputation(s12, SA12, n02, name);
// store unique names in s12 using the suffix array
        for (int i = 0; i < n02; i++) s12[SA12[i]] = i + 1;
    } else // generate the suffix array of s12 directly
        for (int i = 0; i < n02; i++) SA12[s12[i] - 1] = i;
// stably sort the mod 0 suffixes from SA12 by their first character
    for (int i=0, j=0; i < n02; i++) if (SA12[i] < n0) s0[j++] = 3*SA12[i];
    radixPass(s0, SA0, s, n0, K);
// merge sorted SA0 suffixes and sorted SA12 suffixes
    for (int p=0, t=n0-n1, k=0; k < n; k++) {
#define GetI() (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2)
        int i = GetI(); // pos of current offset 12 suffix
        int j = SA0[p]; // pos of current offset 0 suffix
        if (SA12[t] < n0 ? // different compares for mod 1 and mod 2 suffixes
            leq(s[i], s12[SA12[t] + n0], s[j], s12[j/3]) :
            leq(s[i],s[i+1],s12[SA12[t]-n0+1], s[j],s[j+1],s12[j/3+n0]))
        {// suffix from SA12 is smaller
            SA[k] = i; t++;
            if (t == n02) // done --- only SA0 suffixes left
                for (k++; p < n0; p++, k++) SA[k] = SA0[p];
        } else {// suffix from SA0 is smaller
            SA[k] = j; p++;
            if (p == n0) // done --- only SA12 suffixes left
                for (k++; t < n02; t++, k++) SA[k] = GetI();
        }
    }
    delete [] s12; delete [] SA12; delete [] SA0; delete [] s0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, 0x20(%rsp)
movl %ecx, %r15d
movq %rdx, 0x38(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x58(%rsp)
leal 0x2(%r15), %eax
cltq
imulq $0x55555556, %rax, %r12 # imm = 0x55555556
movq %r12, %rax
shrq $0x3f, %rax
shrq $0x20, %r12
addl %eax, %r12d
leal 0x1(%r15), %eax
notl %ecx
cltq
imulq $0x55555555, %rax, %r13 # imm = 0x55555555
shrq $0x20, %r13
addl %ecx, %r13d
movl %r13d, %eax
shrl $0x1f, %eax
sarl %r13d
addl %eax, %r13d
movslq %r15d, %rax
movq %rax, 0x18(%rsp)
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
leal (%r12,%rcx), %ebp
movq %rcx, 0x60(%rsp)
leal (%r12,%rcx), %ebx
addl $0x3, %ebx
shlq $0x2, %rbx
cmpl $-0x3, %ebp
movq $-0x1, %rax
cmovlq %rax, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
movl %ebp, 0x4(%rsp)
movslq %ebp, %rbp
xorl %r14d, %r14d
movq %r14, 0x4(%rax,%rbp,4)
movl %r14d, (%rax,%rbp,4)
movq %rbx, %rdi
callq 0x2030
movq %r14, 0x4(%rax,%rbp,4)
movl %r14d, (%rax,%rbp,4)
movq %rax, %rbp
movslq %r12d, %rax
movq %rax, 0x50(%rsp)
leaq (,%rax,4), %rbx
cmpl $-0x4, 0x18(%rsp)
movq $-0x1, %rax
cmovlq %rax, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2030
movq 0x8(%rsp), %rsi
movq %rax, 0x18(%rsp)
leal (%r12,%r13), %eax
movl %eax, 0x4c(%rsp)
movq %r15, 0x40(%rsp)
addl %r15d, %eax
jle 0x57b8
addl %r12d, %r13d
addl 0x40(%rsp), %r13d
movl $0xaaaaaaab, %eax       # imm = 0xAAAAAAAB
xorl %ecx, %ecx
movl %r14d, %edx
imulq %rax, %rdx
shrq $0x21, %rdx
leal (%rdx,%rdx,2), %edx
cmpl %r14d, %edx
je 0x57b0
movslq %ecx, %rdx
incl %ecx
movl %r14d, (%rsi,%rdx,4)
incl %r14d
cmpl %r14d, %r13d
jne 0x5794
movq 0x10(%rsp), %r15
leaq 0x8(%r15), %rcx
movq %rbp, %rdx
movl 0x4(%rsp), %ebx
movl %ebx, %r8d
movl 0x20(%rsp), %r13d
movl %r13d, %r9d
movq %rsi, %r14
callq 0x5ccc
leaq 0x4(%r15), %rcx
movq %rbp, %rsi
movq %r14, %rdx
movl %ebx, %r8d
movl %r13d, %r9d
callq 0x5ccc
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movl %ebx, %r8d
movl %r13d, %r9d
callq 0x5ccc
testl %ebx, %ebx
movq 0x38(%rsp), %r14
movq 0x28(%rsp), %rsi
jle 0x5935
movl 0x4(%rsp), %ebx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r15
movslq (%rbp,%rax,4), %rdi
movq 0x10(%rsp), %r10
movl (%r10,%rdi,4), %r11d
movl 0x4(%r10,%rdi,4), %r10d
cmpl %r9d, %r11d
jne 0x5865
cmpl %edx, %r10d
jne 0x5865
movl %edx, %r10d
cmpl %ecx, 0x8(%r15,%rdi,4)
jne 0x5865
movl %r9d, %r11d
jmp 0x5874
incl %r8d
movq 0x10(%rsp), %rcx
movl 0x8(%rcx,%rdi,4), %ecx
movl %r10d, %edx
imulq $0x55555556, %rdi, %r9  # imm = 0x55555556
movq %r9, %r10
shrq $0x3f, %r10
shrq $0x20, %r9
addl %r10d, %r9d
leal (%r9,%r9,2), %r10d
subl %r10d, %edi
xorl %r10d, %r10d
cmpl $0x1, %edi
je 0x589b
movl %r12d, %r10d
addl %r10d, %r9d
movslq %r9d, %rdi
movl %r8d, (%rsi,%rdi,4)
incq %rax
movl %r11d, %r9d
cmpq %rax, %rbx
jne 0x5839
movl 0x4(%rsp), %r13d
cmpl %r13d, %r8d
jge 0x58ed
movq 0x58(%rsp), %rdi
movq %rbp, %rdx
movl %r13d, %ecx
callq 0x5660
testl %r13d, %r13d
movq 0x28(%rsp), %rsi
jle 0x5935
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movslq (%rbp,%rax,4), %rcx
incq %rax
movl %eax, (%rdx,%rcx,4)
cmpq %rax, %rbx
jne 0x58db
jmp 0x590e
testl %r13d, %r13d
movq 0x28(%rsp), %rsi
jle 0x5935
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movslq (%rdx,%rax,4), %rcx
movl %eax, -0x4(%rbp,%rcx,4)
incq %rax
cmpq %rax, %rbx
jne 0x58fe
cmpl $0x0, 0x4(%rsp)
jle 0x5935
xorl %eax, %eax
xorl %ecx, %ecx
movl (%rbp,%rax,4), %edx
cmpl %r12d, %edx
jge 0x592d
leal (%rdx,%rdx,2), %edx
movslq %ecx, %rdi
incl %ecx
movl %edx, (%rsi,%rdi,4)
incq %rax
cmpq %rax, %rbx
jne 0x5919
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movl %r12d, %r8d
movl 0x20(%rsp), %r9d
callq 0x5ccc
cmpl $0x0, 0x40(%rsp)
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %rdi
movl 0x4c(%rsp), %esi
jle 0x5c23
movslq 0x60(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
movq %rbp, 0x30(%rsp)
movl %esi, %r15d
movslq %esi, %rdx
movslq (%rbp,%rdx,4), %r9
movslq %eax, %rsi
movslq %ecx, %r13
cmpl %r12d, %r9d
jge 0x59f8
leaq (%r9,%r9,2), %r10
leaq (%r9,%r9,2), %rbp
incq %rbp
movq 0x18(%rsp), %rdi
movslq (%rdi,%r13,4), %r8
movq 0x10(%rsp), %rdi
movl 0x4(%rdi,%r10,4), %r10d
movl (%rdi,%r8,4), %r11d
cmpl %r11d, %r10d
jl 0x5a47
jne 0x5b94
movslq %r8d, %r10
imulq $0x55555556, %r10, %r10 # imm = 0x55555556
movq %r10, %r11
shrq $0x3f, %r11
shrq $0x20, %r10
addl %r11d, %r10d
movslq %r10d, %r10
movq 0x8(%rsp), %rdi
movl (%rdi,%r10,4), %r10d
addl %r12d, %r9d
movslq %r9d, %r9
cmpl %r10d, (%rdi,%r9,4)
jle 0x5a4c
jmp 0x5b99
subl %r12d, %r9d
leal (%r9,%r9,2), %r10d
leal (%r9,%r9,2), %ebp
addl $0x2, %ebp
movq 0x18(%rsp), %rdi
movslq (%rdi,%r13,4), %r8
movslq %r10d, %r11
movq 0x10(%rsp), %rdi
movl (%rdi,%r8,4), %r14d
imulq $0x55555556, %r8, %r10  # imm = 0x55555556
movq %r10, %rbx
shrq $0x3f, %rbx
shrq $0x20, %r10
addl %ebx, %r10d
addl %r12d, %r10d
cmpl %r14d, 0x8(%rdi,%r11,4)
jge 0x5b52
movq 0x38(%rsp), %r14
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %rdi
movl %ebp, (%r14,%rsi,4)
movl %r15d, %esi
incl %esi
cmpl %ebx, %esi
jne 0x5b48
incl %eax
cmpl %r12d, %ecx
movq 0x30(%rsp), %rbp
jge 0x5c03
movslq %eax, %rbx
leaq (%r14,%rbx,4), %rdi
movq 0x18(%rsp), %rax
leaq (%rax,%r13,4), %rsi
notl %ecx
addl %r12d, %ecx
leaq 0x4(,%rcx,4), %rdx
callq 0x2170
pcmpeqd %xmm3, %xmm3
movq 0x50(%rsp), %rcx
subq %r13, %rcx
leaq 0x1(%rcx), %rax
andq $-0x2, %rax
decq %rcx
movq %rbx, %xmm0
movq %rcx, %xmm1
pshufd $0x44, %xmm1, %xmm2     # xmm2 = xmm1[0,1,0,1]
movl $0x2, %ecx
movdqa %xmm0, %xmm1
psubq %xmm3, %xmm0
leaq (%rax,%rcx), %rdx
addq $-0x2, %rdx
addq $-0x2, %rcx
cmpq $0x2, %rdx
jne 0x5aba
negq %rcx
movq %rcx, %xmm3
pshufd $0x44, %xmm3, %xmm3     # xmm3 = xmm3[0,1,0,1]
por 0x2547(%rip), %xmm3     # 0x8030
movdqa 0x254f(%rip), %xmm4     # 0x8040
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm2, %xmm4
pshufd $0xa0, %xmm4, %xmm5     # xmm5 = xmm4[0,0,2,2]
pcmpeqd %xmm2, %xmm3
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
pand %xmm5, %xmm2
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm2, %xmm3
pand %xmm3, %xmm1
pandn %xmm0, %xmm3
por %xmm1, %xmm3
pshufd $0xee, %xmm3, %xmm0     # xmm0 = xmm3[2,3,2,3]
paddq %xmm3, %xmm0
movd %xmm0, %eax
movl %r12d, %ecx
movl 0x4(%rsp), %ebx
movl %ebx, %esi
movq 0x8(%rsp), %rdi
jmp 0x5c17
movq 0x30(%rsp), %rbp
jmp 0x5c17
movq 0x38(%rsp), %r14
jne 0x5b90
movq 0x10(%rsp), %rdi
movl 0x4(%rdi,%r8,4), %ebx
cmpl %ebx, 0xc(%rdi,%r11,4)
jl 0x5a43
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %rdi
jne 0x5b99
movslq %r9d, %r9
movslq %r10d, %r10
movl (%rdi,%r10,4), %r10d
cmpl %r10d, 0x4(%rdi,%r9,4)
jle 0x5a4c
jmp 0x5b99
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %rdi
movl %r8d, (%r14,%rsi,4)
incl %ecx
cmpl %r12d, %ecx
jne 0x5c07
incl %eax
cmpl %ebx, %r15d
movq 0x30(%rsp), %rbp
jge 0x5c11
movslq %eax, %r8
leaq (,%rdx,4), %rcx
addq %rbp, %rcx
movq 0x20(%rsp), %rsi
subq %rdx, %rsi
leaq (%r14,%r8,4), %r11
xorl %edx, %edx
xorl %r15d, %r15d
movl (%rcx,%rdx,4), %r8d
xorl %r9d, %r9d
cmpl %r12d, %r8d
movl %r12d, %r10d
cmovll %r15d, %r10d
setl %r9b
subl %r10d, %r8d
leal (%r8,%r8,2), %r8d
subl %r9d, %r8d
addl $0x2, %r8d
movl %r8d, (%r11,%rdx,4)
incq %rdx
cmpq %rdx, %rsi
jne 0x5bcf
addl %edx, %eax
movl %r12d, %ecx
movl %ebx, %esi
jmp 0x5c17
movq 0x30(%rsp), %rbp
movl %r15d, %esi
jmp 0x5c17
movl %r15d, %esi
movl %r12d, %ecx
incl %eax
cmpl 0x40(%rsp), %eax
jl 0x597c
callq 0x2210
movq %rbp, %rdi
callq 0x2210
movq 0x18(%rsp), %rdi
callq 0x2210
movq 0x28(%rsp), %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2210