// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movl %r8d, 0x38(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
movq %rcx, %rdx
leal 0x2(%rcx), %eax
cltq
imulq $0x55555556, %rax, %r12 # imm = 0x55555556
movq %r12, %rax
shrq $0x3f, %rax
shrq $0x20, %r12
addl %eax, %r12d
leal 0x1(%rcx), %eax
movq %rcx, 0x18(%rsp)
notl %ecx
cltq
imulq $0x55555555, %rax, %rbp # imm = 0x55555555
shrq $0x20, %rbp
addl %ecx, %ebp
movl %ebp, %eax
shrl $0x1f, %eax
sarl %ebp
addl %eax, %ebp
movslq %edx, %rax
movq %rax, 0x8(%rsp)
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
addl %r12d, %ecx
movq %rcx, 0x40(%rsp)
movslq %ecx, %r13
leaq 0xc(,%r13,4), %r14
cmpl $-0x3, %r13d
movq $-0x1, %rax
cmovlq %rax, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, (%rsp)
xorl %ebx, %ebx
movq %rbx, 0x4(%rax,%r13,4)
movl %ebx, (%rax,%r13,4)
movq %r14, %rdi
callq 0x2030
movq %rbx, 0x4(%rax,%r13,4)
movq %rax, 0x48(%rsp)
movl %ebx, (%rax,%r13,4)
movslq %r12d, %r13
shlq $0x2, %r13
cmpl $-0x4, 0x8(%rsp)
movq $-0x1, %rax
cmovlq %rax, %r13
movq %r13, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movq %r13, %rdi
callq 0x2030
movq (%rsp), %rsi
movq %rax, 0x28(%rsp)
leal (%r12,%rbp), %eax
movl %eax, 0x8(%rsp)
addl 0x18(%rsp), %eax
jle 0x5648
addl %r12d, %ebp
addl 0x18(%rsp), %ebp
xorl %eax, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
xorl %edx, %edx
movl %eax, %edi
imulq %rcx, %rdi
shrq $0x21, %rdi
leal (%rdi,%rdi,2), %edi
cmpl %eax, %edi
je 0x5642
movslq %edx, %rdi
incl %edx
movl %eax, (%rsi,%rdi,4)
incl %eax
cmpl %eax, %ebp
jne 0x5629
leaq 0x8(%r15), %rcx
movq 0x48(%rsp), %r13
movq %r13, %rdx
movq 0x40(%rsp), %r14
movl %r14d, %r8d
movl 0x38(%rsp), %ebp
movl %ebp, %r9d
callq 0x5a94
leaq 0x4(%r15), %rcx
movq %r13, %rsi
movq (%rsp), %rdx
movl %r14d, %r8d
movl %ebp, %r9d
callq 0x5a94
movq (%rsp), %rsi
movq %r13, %rdx
movq %r15, %rcx
movl %r14d, %r8d
movl %ebp, %r9d
callq 0x5a94
movq (%rsp), %rsi
testl %r14d, %r14d
jle 0x5722
movl %r14d, %eax
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movslq (%r13,%rcx,4), %r8
movl (%r15,%r8,4), %edi
cmpl %r9d, %edi
jne 0x56d9
cmpl %r11d, 0x4(%r15,%r8,4)
jne 0x56d9
cmpl %edx, 0x8(%r15,%r8,4)
jne 0x56d9
movl %r9d, %edi
jmp 0x56e5
incl %ebx
movl 0x4(%r15,%r8,4), %r11d
movl 0x8(%r15,%r8,4), %edx
imulq $0x55555556, %r8, %r9   # imm = 0x55555556
movq %r9, %r10
shrq $0x3f, %r10
shrq $0x20, %r9
addl %r10d, %r9d
leal (%r9,%r9,2), %r10d
subl %r10d, %r8d
xorl %r10d, %r10d
cmpl $0x1, %r8d
je 0x570d
movl %r12d, %r10d
addl %r10d, %r9d
movslq %r9d, %r8
movl %ebx, (%rsi,%r8,4)
incq %rcx
movl %edi, %r9d
cmpq %rcx, %rax
jne 0x56b8
cmpl %r14d, %ebx
jge 0x575f
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
callq 0x550c
movq (%rsp), %rsi
testl %r14d, %r14d
movq 0x30(%rsp), %r8
jle 0x577f
movl %r14d, %eax
xorl %ecx, %ecx
movslq (%r13,%rcx,4), %rdx
incq %rcx
movl %ecx, (%rsi,%rdx,4)
cmpq %rcx, %rax
jne 0x574d
jmp 0x577f
testl %r14d, %r14d
movq 0x30(%rsp), %r8
jle 0x577f
movl %r14d, %eax
xorl %ecx, %ecx
movslq (%rsi,%rcx,4), %rdx
movl %ecx, -0x4(%r13,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x576e
testl %r14d, %r14d
jle 0x57a9
movl %r14d, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movl (%r13,%rcx,4), %esi
cmpl %r12d, %esi
jge 0x57a1
leal (%rsi,%rsi,2), %esi
movslq %edx, %rdi
incl %edx
movl %esi, (%r8,%rdi,4)
incq %rcx
cmpq %rcx, %rax
jne 0x578b
movq %r8, %rsi
movq 0x28(%rsp), %rdx
movq %r15, 0x10(%rsp)
movq %r15, %rcx
movl %r12d, %r8d
movl %ebp, %r9d
callq 0x5a94
cmpl $0x0, 0x18(%rsp)
movl 0x8(%rsp), %esi
jle 0x59e7
movl %r14d, %eax
movl %r12d, %ecx
negq %rax
movq %rax, 0x50(%rsp)
negq %rcx
movq %rcx, 0x38(%rsp)
xorl %ebx, %ebx
xorl %eax, %eax
xorl %ebp, %ebp
movl %esi, 0x8(%rsp)
movslq %esi, %rcx
movl (%r13,%rcx,4), %r8d
xorl %esi, %esi
cmpl %r12d, %r8d
setl %sil
movl %r12d, %edx
cmovll %ebx, %edx
movl %r8d, %edi
subl %edx, %edi
leal (%rdi,%rdi,2), %edx
subl %esi, %edx
addl $0x2, %edx
movl %r8d, %r9d
movl %ebp, %r15d
movslq %ebp, %rbx
movq 0x28(%rsp), %rsi
movl (%rsi,%rbx,4), %esi
movslq %esi, %r10
movslq %edx, %r11
movq 0x10(%rsp), %rbp
movl (%rbp,%r11,4), %r13d
movslq %eax, %rdi
subl %r12d, %r9d
jge 0x5881
movl (%rbp,%r10,4), %r9d
cmpl %r9d, %r13d
jl 0x58a5
jne 0x5956
imulq $0x55555556, %r10, %r9  # imm = 0x55555556
movq %r9, %r10
shrq $0x3f, %r10
shrq $0x20, %r9
addl %r10d, %r9d
movslq %r9d, %r9
movq (%rsp), %r10
movl (%r10,%r9,4), %r9d
addl %r12d, %r8d
movslq %r8d, %r8
cmpl %r9d, (%r10,%r8,4)
jle 0x58a5
jmp 0x5956
imulq $0x55555556, %r10, %r8  # imm = 0x55555556
movq %r8, %r14
shrq $0x3f, %r14
shrq $0x20, %r8
addl %r14d, %r8d
movq 0x40(%rsp), %r14
addl %r12d, %r8d
cmpl (%rbp,%r10,4), %r13d
jge 0x5924
movq 0x20(%rsp), %rcx
movl %edx, (%rcx,%rdi,4)
movl 0x8(%rsp), %esi
incl %esi
cmpl %r14d, %esi
movq 0x48(%rsp), %r13
movl %r15d, %ebp
jne 0x5911
incl %eax
cmpl %r12d, %ebp
jge 0x5911
movl %esi, %r15d
movslq %eax, %r14
movq 0x20(%rsp), %rax
leaq (%rax,%r14,4), %rdi
movq 0x28(%rsp), %rax
leaq (%rax,%rbx,4), %rsi
movl %ebp, %eax
notl %eax
addl %r12d, %eax
leaq 0x4(,%rax,4), %rdx
callq 0x2170
movl %r14d, %eax
addq 0x38(%rsp), %rbx
xorl %ecx, %ecx
decq %rcx
cmpq %rcx, %rbx
jne 0x58fd
subl %ecx, %ebp
subl %ecx, %eax
movq 0x40(%rsp), %r14
movl %r15d, %esi
xorl %ebx, %ebx
incl %eax
cmpl 0x18(%rsp), %eax
jl 0x57ef
jmp 0x59e7
jne 0x5956
movq 0x10(%rsp), %r13
movl 0x4(%r13,%r10,4), %r10d
cmpl %r10d, 0x4(%r13,%r11,4)
jl 0x58a5
jne 0x5956
movslq %r9d, %r9
movslq %r8d, %r8
movq (%rsp), %r10
movl (%r10,%r8,4), %r8d
cmpl %r8d, 0x4(%r10,%r9,4)
jle 0x58a5
movq 0x20(%rsp), %rdx
movl %esi, (%rdx,%rdi,4)
movl %r15d, %ebp
incl %ebp
cmpl %r12d, %ebp
movq 0x48(%rsp), %r13
movl $0x0, %ebx
jne 0x59de
incl %eax
movl 0x8(%rsp), %esi
cmpl %r14d, %esi
jge 0x5913
movslq %eax, %rdx
leaq (,%rcx,4), %rsi
addq %r13, %rsi
addq 0x50(%rsp), %rcx
movq 0x20(%rsp), %rdi
leaq (%rdi,%rdx,4), %rdi
xorl %edx, %edx
xorl %r8d, %r8d
movl (%rsi,%r8), %r9d
xorl %r10d, %r10d
cmpl %r12d, %r9d
setl %r10b
movl %r12d, %r11d
cmovll %ebx, %r11d
subl %r11d, %r9d
leal (%r9,%r9,2), %r9d
subl %r10d, %r9d
addl $0x2, %r9d
movl %r9d, (%rdi,%r8)
addq $0x4, %r8
decq %rdx
cmpq %rdx, %rcx
jne 0x599e
movl 0x8(%rsp), %esi
subl %edx, %esi
subl %edx, %eax
jmp 0x5913
movl 0x8(%rsp), %esi
jmp 0x5913
movq (%rsp), %rdi
callq 0x2210
movq %r13, %rdi
callq 0x2210
movq 0x28(%rsp), %rdi
callq 0x2210
movq 0x30(%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2210