// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movl %ecx, %r14d
movq %rdx, 0x50(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x38(%rsp)
leal 0x2(%r14), %eax
pushq $0x3
popq %rsi
cltd
idivl %esi
movl %eax, %r12d
leal 0x1(%r14), %eax
pushq $-0x3
popq %rcx
cltd
idivl %ecx
movq %rax, 0x40(%rsp)
movl %r14d, %eax
cltd
idivl %esi
leal (%r12,%rax), %r13d
leal (%r12,%rax), %ebx
addl $0x3, %ebx
shlq $0x2, %rbx
cmpl $-0x3, %r13d
pushq $-0x1
popq %r15
cmovlq %r15, %rbx
movq %rbx, %rdi
callq 0x2030
movl %r13d, %ebp
movslq %r13d, %r13
andl $0x0, 0x8(%rax,%r13,4)
movq %rax, 0x18(%rsp)
andq $0x0, (%rax,%r13,4)
movq %rbx, %rdi
callq 0x2030
andl $0x0, 0x8(%rax,%r13,4)
movq %r13, 0x60(%rsp)
movq %rax, 0x28(%rsp)
andq $0x0, (%rax,%r13,4)
movslq %r12d, %r13
leaq (,%r13,4), %rbx
cmpl $-0x4, %r14d
cmovlq %r15, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x48(%rsp)
movq %rbx, %rdi
callq 0x2030
movq %rax, %rbx
movq 0x40(%rsp), %rax
addl %r13d, %eax
movq %rax, 0x30(%rsp)
leal (%rax,%r14), %esi
xorl %edi, %edi
testl %esi, %esi
cmovlel %edi, %esi
xorl %ecx, %ecx
pushq $0x3
popq %r8
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
cmpl %ecx, %esi
je 0x4935
leal (%rax,%rax,2), %eax
cmpl %ecx, %eax
je 0x4931
movslq %edi, %rax
incl %edi
movq 0x18(%rsp), %rdx
movl %ecx, (%rdx,%rax,4)
incl %ecx
jmp 0x4912
movq 0x20(%rsp), %rax
leaq 0x8(%rax), %rcx
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %r15
movq %r15, %rdx
movl %ebp, %r8d
movl 0x8(%rsp), %r9d
callq 0x4d86
movq 0x20(%rsp), %rax
leaq 0x4(%rax), %rcx
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movl %ebp, %r8d
movl 0x8(%rsp), %r9d
callq 0x4d86
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq 0x20(%rsp), %rcx
movl %ebp, %r8d
movl 0x8(%rsp), %r9d
callq 0x4d86
xorl %ecx, %ecx
testl %ebp, %ebp
movl %ebp, %eax
movl $0x0, %ebp
movl %eax, 0x14(%rsp)
cmovgl %eax, %ebp
pushq $-0x1
popq %rdi
xorl %esi, %esi
xorl %r8d, %r8d
movl %edi, %r10d
movl %edi, %r9d
cmpq %rsi, %rbp
je 0x4a1a
movslq (%r15,%rsi,4), %rax
movq 0x20(%rsp), %r11
movl (%r11,%rax,4), %edx
movl 0x4(%r11,%rax,4), %r11d
cmpl %edi, %edx
jne 0x49e4
cmpl %r10d, %r11d
jne 0x49e4
movl %r10d, %r11d
movq 0x20(%rsp), %r15
cmpl %r9d, 0x8(%r15,%rax,4)
movq 0x28(%rsp), %r15
je 0x49f6
incl %r8d
movq 0x20(%rsp), %rdi
movl 0x8(%rdi,%rax,4), %r9d
movl %r11d, %r10d
movl %edx, %edi
cltd
pushq $0x3
popq %r11
idivl %r11d
cmpl $0x1, %edx
movl %r12d, %edx
cmovel %ecx, %edx
addl %eax, %edx
movslq %edx, %rax
movq 0x18(%rsp), %rdx
movl %r8d, (%rdx,%rax,4)
incq %rsi
jmp 0x49b0
movl 0x14(%rsp), %ecx
cmpl %ecx, %r8d
jge 0x4a52
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x482c
xorl %eax, %eax
movq 0x48(%rsp), %rsi
movq 0x18(%rsp), %rdx
cmpq %rax, %rbp
je 0x4a71
movslq (%r15,%rax,4), %rcx
incq %rax
movl %eax, (%rdx,%rcx,4)
jmp 0x4a41
xorl %eax, %eax
movq 0x48(%rsp), %rsi
cmpq %rax, %rbp
je 0x4a71
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
movl %eax, -0x4(%r15,%rcx,4)
incq %rax
jmp 0x4a59
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %rbp
je 0x4a93
movl (%r15,%rax,4), %edx
cmpl %r12d, %edx
jge 0x4a8e
leal (%rdx,%rdx,2), %edx
movslq %ecx, %rdi
incl %ecx
movl %edx, (%rsi,%rdi,4)
incq %rax
jmp 0x4a75
movq %rbx, %rdx
movq 0x20(%rsp), %rcx
movl %r12d, %r8d
movl 0x8(%rsp), %r9d
callq 0x4d86
movq 0x50(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x58(%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
movl 0x14(%rsp), %ebp
movq 0x30(%rsp), %rsi
cmpl %r14d, %r8d
jge 0x4ce2
movslq %esi, %r10
movslq (%r15,%r10,4), %rdi
movslq %r8d, %rax
movq %rax, 0x8(%rsp)
movslq %ecx, %r11
cmpl %r12d, %edi
movl %ecx, 0x38(%rsp)
jge 0x4b19
leaq (%rdi,%rdi,2), %rax
leaq (%rdi,%rdi,2), %rdx
incq %rdx
movq %rdx, 0x40(%rsp)
movslq %ecx, %rcx
movslq (%rbx,%rcx,4), %rcx
movq 0x20(%rsp), %rdx
movl 0x4(%rdx,%rax,4), %r15d
movl (%rdx,%rcx,4), %r9d
cmpl %r9d, %r15d
jge 0x4b73
movq 0x28(%rsp), %r15
jmp 0x4b6c
movq %rsi, 0x30(%rsp)
movq %r14, %rsi
subl %r12d, %edi
leal (%rdi,%rdi,2), %eax
leal (%rdi,%rdi,2), %ecx
addl $0x2, %ecx
movq %rcx, 0x40(%rsp)
movslq (%rbx,%r11,4), %rcx
movslq %eax, %r15
movq 0x20(%rsp), %rax
movl 0x8(%rax,%r15,4), %r9d
movl (%rax,%rcx,4), %r14d
movl %ecx, %eax
cltd
pushq $0x3
popq %rbp
idivl %ebp
addl %r12d, %eax
cmpl %r14d, %r9d
jge 0x4c06
movq %rsi, %r14
movl 0x14(%rsp), %ebp
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rsi
movq 0x8(%rsp), %rdx
jmp 0x4bbd
movq %r14, %rbp
movq %rsi, %r14
movl %ecx, %eax
cltd
pushq $0x3
popq %rsi
idivl %esi
cmpl %r9d, %r15d
jne 0x4c62
cltq
movq 0x18(%rsp), %rsi
movl (%rsi,%rax,4), %eax
addl %r12d, %edi
movslq %edi, %rdx
cmpl %eax, (%rsi,%rdx,4)
movq 0x28(%rsp), %r15
movq %r14, %rsi
movq %rbp, %r14
movl $0x0, %r9d
movl 0x14(%rsp), %ebp
movq 0x8(%rsp), %rdx
jg 0x4c79
movq 0x50(%rsp), %rax
movq 0x40(%rsp), %rcx
movl %ecx, (%rax,%rdx,4)
incl %esi
cmpl %ebp, %esi
jne 0x4bf3
incl %r8d
movq 0x58(%rsp), %rax
leaq (%rax,%rdx,4), %rax
cmpq %r13, %r11
jge 0x4bfc
movl (%rbx,%r11,4), %ecx
movl %ecx, (%rax)
incq %r11
incl %r8d
addq $0x4, %rax
jmp 0x4bdc
movl 0x38(%rsp), %ecx
jmp 0x4cd3
movl %r11d, %ecx
movl %ebp, %esi
jmp 0x4cd3
movl 0x14(%rsp), %ebp
jne 0x4c50
movq 0x20(%rsp), %r9
movl 0x4(%r9,%rcx,4), %edx
cmpl %edx, 0xc(%r9,%r15,4)
movq %rsi, %r14
movl $0x0, %r9d
jl 0x4b62
movq 0x28(%rsp), %r15
jne 0x4cdb
movslq %edi, %rdx
cltq
movq 0x18(%rsp), %rsi
movl (%rsi,%rax,4), %eax
cmpl %eax, 0x4(%rsi,%rdx,4)
movq 0x30(%rsp), %rsi
jmp 0x4bb2
movq %rsi, %r14
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rsi
xorl %r9d, %r9d
jmp 0x4c74
movq 0x28(%rsp), %r15
movq %r14, %rsi
movq %rbp, %r14
xorl %r9d, %r9d
movl 0x14(%rsp), %ebp
movq 0x8(%rsp), %rdx
movq 0x50(%rsp), %rax
movl %ecx, (%rax,%rdx,4)
movl 0x38(%rsp), %ecx
incl %ecx
cmpl %r12d, %ecx
movq 0x60(%rsp), %rdi
jne 0x4cd3
incl %r8d
movq 0x58(%rsp), %rax
leaq (%rax,%rdx,4), %rax
cmpq %rdi, %r10
jge 0x4ccd
movl (%r15,%r10,4), %ecx
xorl %edx, %edx
cmpl %r12d, %ecx
setl %dl
movl %r12d, %esi
cmovll %r9d, %esi
subl %esi, %ecx
leal (%rcx,%rcx,2), %ecx
subl %edx, %ecx
addl $0x2, %ecx
movl %ecx, (%rax)
incq %r10
incl %r8d
addq $0x4, %rax
jmp 0x4c9d
movl %r12d, %ecx
movl %r10d, %esi
incl %r8d
jmp 0x4ac4
movq 0x30(%rsp), %rsi
jmp 0x4c74
movq 0x18(%rsp), %rdi
callq 0x21f0
movq %r15, %rdi
callq 0x21f0
movq %rbx, %rdi
callq 0x21f0
movq 0x48(%rsp), %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21f0