// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/is.c
// Function: sais_main
static int64_t sais_main(const unsigned char *T, int64_t *SA, int64_t fs, int64_t n, int64_t k, int64_t cs)
{
	int64_t *C, *B, *RA;
	int64_t  i, j, c, m, p, q, plen, qlen, name;
	int64_t  c0, c1;
	int64_t  diff;

	/* stage 1: reduce the problem by at least 1/2 sort all the
	 * S-substrings */
	if (k <= fs) {
		C = SA + n;
		B = (k <= (fs - k)) ? C + k : C;
	} else if ((C = B = (int64_t *) malloc(k * sizeof(int64_t))) == NULL) return -2;
	getCounts(T, C, n, k, cs);
	getBuckets(C, B, k, 1);	/* find ends of buckets */
	for (i = 0; i < n; ++i) SA[i] = 0;
	for (i = n - 2, c = 0, c1 = chr(n - 1); 0 <= i; --i, c1 = c0) {
		if ((c0 = chr(i)) < (c1 + c)) c = 1;
		else if (c != 0) SA[--B[c1]] = i + 1, c = 0;
	}
	induceSA(T, SA, C, B, n, k, cs);
	if (fs < k) free(C);
	/* compact all the sorted substrings into the first m items of SA
	 * 2*m must be not larger than n (proveable) */
	for (i = 0, m = 0; i < n; ++i) {
		p = SA[i];
		if ((0 < p) && (chr(p - 1) > (c0 = chr(p)))) {
			for (j = p + 1; (j < n) && (c0 == (c1 = chr(j))); ++j);
			if ((j < n) && (c0 < c1)) SA[m++] = p;
		}
	}
	for (i = m; i < n; ++i) SA[i] = 0;	/* init the name array buffer */
	/* store the length of all substrings */
	for (i = n - 2, j = n, c = 0, c1 = chr(n - 1); 0 <= i; --i, c1 = c0) {
		if ((c0 = chr(i)) < (c1 + c)) c = 1;
		else if (c != 0) {
			SA[m + ((i + 1) >> 1)] = j - i - 1;
			j = i + 1;
			c = 0;
		}
	}
	/* find the lexicographic names of all substrings */
	for (i = 0, name = 0, q = n, qlen = 0; i < m; ++i) {
		p = SA[i], plen = SA[m + (p >> 1)], diff = 1;
		if (plen == qlen) {
			for (j = 0; (j < plen) && (chr(p + j) == chr(q + j)); j++);
			if (j == plen) diff = 0;
		}
		if (diff != 0) ++name, q = p, qlen = plen;
		SA[m + (p >> 1)] = name;
	}

	/* stage 2: solve the reduced problem recurse if names are not yet
	 * unique */
	if (name < m) {
		RA = SA + n + fs - m;
		for (i = n - 1, j = m - 1; m <= i; --i) {
			if (SA[i] != 0) RA[j--] = SA[i] - 1;
		}
		if (sais_main((unsigned char *) RA, SA, fs + n - m * 2, m, name, sizeof(int64_t)) != 0) return -2;
		for (i = n - 2, j = m - 1, c = 0, c1 = chr(n - 1); 0 <= i; --i, c1 = c0) {
			if ((c0 = chr(i)) < (c1 + c)) c = 1;
			else if (c != 0) RA[j--] = i + 1, c = 0; /* get p1 */
		}
		for (i = 0; i < m; ++i) SA[i] = RA[SA[i]]; /* get index */
	}
	/* stage 3: induce the result for the original problem */
	if (k <= fs) {
		C = SA + n;
		B = (k <= (fs - k)) ? C + k : C;
	} else if ((C = B = (int64_t *) malloc(k * sizeof(int64_t))) == NULL) return -2;
	/* put all left-most S characters into their buckets */
	getCounts(T, C, n, k, cs);
	getBuckets(C, B, k, 1);	/* find ends of buckets */
	for (i = m; i < n; ++i) SA[i] = 0; /* init SA[m..n-1] */
	for (i = m - 1; 0 <= i; --i) {
		j = SA[i], SA[i] = 0;
		SA[--B[chr(j)]] = j;
	}
	induceSA(T, SA, C, B, n, k, cs);
	if (fs < k) free(C);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %rbp
movq %rcx, %r15
movq %rsi, %r13
movq %rdx, 0x30(%rsp)
movq %rdx, %rax
subq %r8, %rax
movq %r8, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
jge 0x3956
leaq (,%r8,8), %rdi
leaq 0x1c6d7(%rip), %rsi     # 0x20004
leaq 0x1c6dc(%rip), %rcx     # 0x20010
pushq $0x71
popq %rdx
callq 0x1e045
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r8
movq %rax, %r12
movq %rax, %rbx
testq %rax, %rax
jne 0x396e
jmp 0x3cd5
leaq (,%r15,8), %rbx
addq %r13, %rbx
xorl %ecx, %ecx
cmpq %r8, %rax
cmovgeq %r8, %rcx
leaq (%rbx,%rcx,8), %r12
movq %rbx, %rsi
movq %r15, %rdx
movq %r8, %rcx
movq %rbp, %r8
callq 0x3f4c
pushq $0x1
popq %r14
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
movq %r12, 0x18(%rsp)
movq %r12, %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rcx
callq 0x3f8c
xorl %eax, %eax
testq %r15, %r15
movl $0x0, %ebx
cmovgq %r15, %rbx
cmpq %rax, %rbx
je 0x39be
andq $0x0, (%r13,%rax,8)
incq %rax
jmp 0x39ae
cmpq $0x8, %rbp
jne 0x39d0
movq 0x10(%rsp), %rdi
movq -0x8(%rdi,%r15,8), %r11
jmp 0x39db
movq 0x10(%rsp), %rdi
movzbl -0x1(%rdi,%r15), %r11d
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %r12
leaq -0x2(%r15), %r10
xorl %edx, %edx
movq %r10, %rax
testq %rax, %rax
js 0x3a37
cmpq $0x8, %rbp
jne 0x39ff
movq (%rdi,%rax,8), %rsi
jmp 0x3a03
movzbl (%rdi,%rax), %esi
leaq (%r11,%rdx), %r8
movq %r14, %r9
cmpq %r8, %rsi
jl 0x3a2c
testq %rdx, %rdx
je 0x3a29
leaq 0x1(%rax), %rdx
movq (%rcx,%r11,8), %r9
leaq -0x1(%r9), %r8
movq %r8, (%rcx,%r11,8)
movq %rdx, -0x8(%r13,%r9,8)
xorl %r9d, %r9d
decq %rax
movq %r9, %rdx
movq %rsi, %r11
jmp 0x39ee
movq %r10, 0x38(%rsp)
movq %rbp, (%rsp)
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %r8
movq 0x20(%rsp), %r14
movq %r14, %r9
callq 0x3fcd
cmpq %r14, 0x30(%rsp)
jge 0x3a65
movq %r12, %rdi
callq 0x3390
xorl %eax, %eax
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %r10
cmpq %rbx, %rax
je 0x3ad3
movq (%r13,%rax,8), %rcx
testq %rcx, %rcx
jle 0x3ace
cmpq $0x8, %rbp
jne 0x3a94
movq -0x8(%rdi,%rcx,8), %rsi
movq (%rdi,%rcx,8), %rdx
jmp 0x3a9d
movzbl -0x1(%rdi,%rcx), %esi
movzbl (%rdi,%rcx), %edx
cmpq %rdx, %rsi
jle 0x3ace
leaq 0x1(%rcx), %rsi
cmpq %r15, %rsi
jge 0x3ace
cmpq $0x8, %rbp
jne 0x3ab7
movq (%rdi,%rsi,8), %r8
jmp 0x3abc
movzbl (%rdi,%rsi), %r8d
incq %rsi
cmpq %r8, %rdx
je 0x3aa6
jge 0x3ace
movq %rcx, (%r13,%r14,8)
incq %r14
incq %rax
jmp 0x3a74
movq %r14, %rax
cmpq %r15, %rax
jge 0x3ae6
andq $0x0, (%r13,%rax,8)
incq %rax
jmp 0x3ad6
cmpq $0x8, %rbp
jne 0x3af3
movq -0x8(%rdi,%r15,8), %r9
jmp 0x3af9
movzbl -0x1(%rdi,%r15), %r9d
leaq (,%r14,8), %rax
addq %r13, %rax
movq %rax, 0x40(%rsp)
pushq $0x1
popq %rcx
movq %rcx, %rdx
subq %r15, %rdx
xorl %r8d, %r8d
movq %r10, %rsi
movq %r15, %r11
testq %rsi, %rsi
js 0x3b6b
cmpq $0x8, %rbp
jne 0x3b2c
movq (%rdi,%rsi,8), %r10
jmp 0x3b31
movzbl (%rdi,%rsi), %r10d
addq %r8, %r9
cmpq %r9, %r10
jge 0x3b3e
movq %rcx, %r8
jmp 0x3b60
testq %r8, %r8
je 0x3b5d
addq %rdx, %r11
leaq 0x1(%rsi), %rax
movq %rax, %r8
andq $-0x2, %r8
movq 0x40(%rsp), %r9
movq %r11, (%r9,%r8,4)
movq %rax, %r11
xorl %r8d, %r8d
decq %rsi
incq %rdx
movq %r10, %r9
jmp 0x3b1b
xorl %ecx, %ecx
testq %r14, %r14
movl $0x0, %ebx
cmovgq %r14, %rbx
movq %r15, %rdx
xorl %esi, %esi
xorl %r8d, %r8d
movq %r14, 0x48(%rsp)
movq 0x40(%rsp), %rax
movq %rbp, 0x18(%rsp)
movq %r15, 0x60(%rsp)
movq %r13, 0x58(%rsp)
movq %rbx, 0x50(%rsp)
cmpq %rbx, %rcx
je 0x3c58
movq (%r13,%rcx,8), %r12
movq %r12, %r9
sarq %r9
movq (%rax,%r9,8), %r10
cmpq %rsi, %r10
jne 0x3c43
leaq (%rdi,%r12), %rbx
leaq (%rdi,%rdx), %r14
leaq (%rdi,%r12,8), %r15
movq %rdx, 0x28(%rsp)
leaq (%rdi,%rdx,8), %r13
testq %rsi, %rsi
movl $0x0, %eax
cmovgq %rsi, %rax
xorl %r11d, %r11d
cmpq %r11, %rax
je 0x3c1b
cmpq $0x8, %rbp
jne 0x3bfa
movq (%r15,%r11,8), %rbp
movq (%r13,%r11,8), %rdx
jmp 0x3c04
movzbl (%rbx,%r11), %ebp
movzbl (%r14,%r11), %edx
cmpq %rdx, %rbp
jne 0x3c13
incq %r11
movq 0x18(%rsp), %rbp
jmp 0x3be4
movq %r11, %rax
movq 0x18(%rsp), %rbp
cmpq %rsi, %rax
movq 0x60(%rsp), %r15
movq 0x58(%rsp), %r13
movq 0x10(%rsp), %rdi
movq 0x48(%rsp), %r14
movq 0x50(%rsp), %rbx
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rdx
je 0x3c4c
incq %r8
movq %r12, %rdx
movq %r10, %rsi
movq %r8, (%rax,%r9,8)
incq %rcx
jmp 0x3b9f
cmpq %r14, %r8
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %r11
jge 0x3d70
leaq (,%r15,8), %rax
addq %r13, %rax
leaq (%rax,%r11,8), %rbp
leaq (,%r14,8), %rax
subq %rax, %rbp
leaq -0x1(%r15), %rax
leaq -0x1(%r14), %r12
movq %rax, 0x28(%rsp)
movq %r12, %rcx
cmpq %rax, %r14
jg 0x3cb4
movq (%r13,%rax,8), %rdx
testq %rdx, %rdx
je 0x3caf
decq %rdx
movq %rdx, (%rbp,%rcx,8)
decq %rcx
decq %rax
jmp 0x3c95
leaq (%r15,%r11), %rdx
subq %r14, %rdx
subq %r14, %rdx
pushq $0x8
popq %r9
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
callq 0x38f0
testq %rax, %rax
je 0x3cdd
pushq $-0x2
popq %rax
jmp 0x3e81
cmpq $0x8, 0x18(%rsp)
jne 0x3cf1
movq 0x10(%rsp), %rdi
movq -0x8(%rdi,%r15,8), %rdx
jmp 0x3cff
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rax
movzbl (%rdi,%rax), %edx
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %r11
movq 0x38(%rsp), %r10
xorl %r9d, %r9d
pushq $0x1
popq %rax
testq %r10, %r10
js 0x3d55
cmpq $0x8, 0x18(%rsp)
jne 0x3d27
movq (%rdi,%r10,8), %rsi
jmp 0x3d2c
movzbl (%rdi,%r10), %esi
addq %r9, %rdx
cmpq %rdx, %rsi
jge 0x3d39
movq %rax, %r9
jmp 0x3d4d
testq %r9, %r9
je 0x3d4a
leaq 0x1(%r10), %rdx
movq %rdx, (%rbp,%r12,8)
decq %r12
xorl %r9d, %r9d
decq %r10
movq %rsi, %rdx
jmp 0x3d14
xorl %eax, %eax
cmpq %rax, %rbx
je 0x3d70
movq (%r13,%rax,8), %rdx
movq (%rbp,%rdx,8), %rdx
movq %rdx, (%r13,%rax,8)
incq %rax
jmp 0x3d57
movq %r11, %rax
subq %rcx, %rax
jge 0x3dba
leaq (,%rcx,8), %rdi
leaq 0x1c27d(%rip), %rsi     # 0x20004
leaq 0x1c282(%rip), %rcx     # 0x20010
movl $0xab, %edx
callq 0x1e045
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq %rax, %rbx
movq %rax, %rbp
testq %rax, %rax
pushq $-0x2
popq %rax
movq 0x18(%rsp), %r12
jne 0x3dde
jmp 0x3e81
leaq (,%r15,8), %rbp
addq %r13, %rbp
xorl %edx, %edx
cmpq %rcx, %rax
cmovgeq %rcx, %rdx
leaq (,%rdx,8), %rbx
addq %rbp, %rbx
movq 0x18(%rsp), %r12
movq %rbp, %rsi
movq %r15, %rdx
movq %rcx, %r14
movq %r12, %r8
callq 0x3f4c
pushq $0x1
popq %rcx
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq 0x48(%rsp), %r14
callq 0x3f8c
movq %r14, %rax
cmpq %r15, %rax
jge 0x3e18
andq $0x0, (%r13,%rax,8)
incq %rax
jmp 0x3e08
movq 0x10(%rsp), %rdi
testq %r14, %r14
jle 0x3e53
movq -0x8(%r13,%r14,8), %rax
andq $0x0, -0x8(%r13,%r14,8)
cmpq $0x8, %r12
jne 0x3e39
movq (%rdi,%rax,8), %rcx
jmp 0x3e3d
movzbl (%rdi,%rax), %ecx
movq (%rbx,%rcx,8), %rdx
leaq -0x1(%rdx), %rsi
movq %rsi, (%rbx,%rcx,8)
movq %rax, -0x8(%r13,%rdx,8)
decq %r14
jmp 0x3e1d
movq %r12, (%rsp)
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq 0x20(%rsp), %rbx
movq %rbx, %r9
callq 0x3fcd
cmpq %rbx, 0x30(%rsp)
jge 0x3e7f
movq %rbp, %rdi
callq 0x3390
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq