// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r9, %r12
movq %r8, %r15
movq %rdi, %r13
movq %rdx, %rax
movq %rdx, 0x30(%rsp)
subq %r8, %rax
movq %rcx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
jge 0x4eab
leaq (,%r15,8), %rdi
leaq 0x2017f(%rip), %rsi     # 0x25004
leaq 0x20184(%rip), %rcx     # 0x25010
movl $0x71, %edx
callq 0x23213
movq 0x18(%rsp), %r9
movq %rax, %rbx
movq %rax, %r14
testq %rax, %rax
jne 0x4ebf
jmp 0x5340
movq %rcx, %r9
leaq (%rsi,%rcx,8), %r14
xorl %ecx, %ecx
cmpq %r15, %rax
cmovgeq %r15, %rcx
leaq (%r14,%rcx,8), %rbx
testq %r15, %r15
jle 0x4edb
leaq (,%r15,8), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x3140
movq 0x18(%rsp), %r9
testq %r9, %r9
jle 0x4f01
xorl %eax, %eax
cmpq $0x8, %r12
jne 0x4eef
movq (%r13,%rax,8), %rcx
jmp 0x4ef5
movzbl (%r13,%rax), %ecx
incq (%r14,%rcx,8)
incq %rax
cmpq %rax, %r9
jne 0x4ee2
testq %r15, %r15
jle 0x4f1a
xorl %eax, %eax
xorl %ecx, %ecx
addq (%r14,%rcx,8), %rax
movq %rax, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x4f0a
testq %r9, %r9
jle 0x4f38
leaq (,%r9,8), %rdx
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x3140
movq 0x18(%rsp), %r9
cmpq $0x8, %r12
jne 0x4f45
movq -0x8(%r13,%r9,8), %rax
jmp 0x4f4b
movzbl -0x1(%r13,%r9), %eax
cmpq $0x2, %r9
jl 0x4fa3
leaq -0x1(%r9), %rcx
xorl %edx, %edx
movq %rax, %rsi
cmpq $0x8, %r12
jne 0x4f67
movq -0x8(%r13,%rcx,8), %rax
jmp 0x4f6d
movzbl -0x1(%r13,%rcx), %eax
leaq (%rsi,%rdx), %r8
movl $0x1, %edi
cmpq %r8, %rax
jl 0x4f98
testq %rdx, %rdx
je 0x4f96
movq (%rbx,%rsi,8), %rdx
leaq -0x1(%rdx), %rdi
movq %rdi, (%rbx,%rsi,8)
movq 0x20(%rsp), %rsi
movq %rcx, -0x8(%rsi,%rdx,8)
xorl %edi, %edi
decq %rcx
movq %rdi, %rdx
testq %rcx, %rcx
jg 0x4f57
movq %r12, (%rsp)
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq %r9, %r8
movq %r15, %r9
callq 0x5542
cmpq %r15, 0x30(%rsp)
jge 0x4fcf
movq %r14, %rdi
callq 0x3390
movq 0x18(%rsp), %r11
xorl %r8d, %r8d
testq %r11, %r11
jle 0x504d
xorl %eax, %eax
movq 0x20(%rsp), %r14
movq (%r14,%rax,8), %rcx
testq %rcx, %rcx
jle 0x5043
cmpq $0x8, %r12
jne 0x4ffe
movq -0x8(%r13,%rcx,8), %rsi
movq (%r13,%rcx,8), %rdx
jmp 0x500a
movzbl -0x1(%r13,%rcx), %esi
movzbl (%r13,%rcx), %edx
cmpq %rdx, %rsi
jle 0x5043
leaq 0x1(%rcx), %rsi
cmpq %r11, %rsi
jge 0x5043
cmpq $0x8, %r12
jne 0x5025
movq (%r13,%rsi,8), %rdi
jmp 0x502b
movzbl (%r13,%rsi), %edi
cmpq %rdi, %rdx
jne 0x503a
incq %rsi
cmpq %rsi, %r11
jne 0x5018
jmp 0x5043
jge 0x5043
movq %rcx, (%r14,%r8,8)
incq %r8
incq %rax
cmpq %r11, %rax
jne 0x4fe3
jmp 0x5052
movq 0x20(%rsp), %r14
movq %r11, %rdx
subq %r8, %rdx
movq %r8, 0x28(%rsp)
jle 0x5073
leaq (%r14,%r8,8), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3140
movq 0x18(%rsp), %r11
cmpq $0x8, %r12
jne 0x5080
movq -0x8(%r13,%r11,8), %rax
jmp 0x5086
movzbl -0x1(%r13,%r11), %eax
cmpq $0x2, %r11
jl 0x50f2
movq 0x28(%rsp), %rcx
leaq (%r14,%rcx,8), %rcx
leaq -0x1(%r11), %rdx
movl $0x1, %esi
subq %r11, %rsi
xorl %r8d, %r8d
movq %r11, %rdi
movq %rax, %r10
cmpq $0x8, %r12
jne 0x50b7
movq -0x8(%r13,%rdx,8), %rax
jmp 0x50bd
movzbl -0x1(%r13,%rdx), %eax
addq %r8, %r10
movl $0x1, %r9d
cmpq %r10, %rax
jl 0x50e4
testq %r8, %r8
je 0x50e1
addq %rsi, %rdi
movq %rdx, %r8
andq $-0x2, %r8
movq %rdi, (%rcx,%r8,4)
movq %rdx, %rdi
xorl %r9d, %r9d
decq %rdx
incq %rsi
movq %r9, %r8
testq %rdx, %rdx
jg 0x50a7
movq 0x28(%rsp), %rax
testq %rax, %rax
movq %r13, 0x10(%rsp)
jle 0x51de
leaq (%r14,%rax,8), %r8
xorl %eax, %eax
xorl %esi, %esi
movq %r11, %r10
xorl %ecx, %ecx
movq %r15, 0x38(%rsp)
movq (%r14,%rcx,8), %rdx
movq %rdx, %rdi
sarq %rdi
movq (%r8,%rdi,8), %r9
cmpq %rsi, %r9
jne 0x51c1
testq %rsi, %rsi
jle 0x5196
movq %rax, 0x40(%rsp)
leaq (%rdx,%r13), %rbx
movq %r13, %rax
addq %r10, %r13
leaq (%rax,%rdx,8), %r15
leaq (%rax,%r10,8), %r14
xorl %r11d, %r11d
cmpq $0x8, %r12
jne 0x515d
movq (%r15,%r11,8), %rbp
movq (%r14,%r11,8), %rax
jmp 0x5168
movzbl (%rbx,%r11), %ebp
movzbl (%r13,%r11), %eax
cmpq %rax, %rbp
jne 0x519b
incq %r11
cmpq %r11, %rsi
jne 0x514d
movq %r10, %rdx
movq %rsi, %r9
movq 0x38(%rsp), %r15
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %r13
movq 0x40(%rsp), %rax
jmp 0x51c4
xorl %r11d, %r11d
jmp 0x51af
movq 0x38(%rsp), %r15
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %r13
movq 0x40(%rsp), %rax
cmpq %rsi, %r11
movq 0x18(%rsp), %r11
jne 0x51c1
movq %r10, %rdx
movq %rsi, %r9
jmp 0x51c4
incq %rax
movq %rax, (%r8,%rdi,8)
incq %rcx
movq %r9, %rsi
movq %rdx, %r10
cmpq 0x28(%rsp), %rcx
jne 0x5117
jmp 0x51e0
xorl %eax, %eax
movq 0x28(%rsp), %r10
cmpq %r10, %rax
jge 0x5301
movq %rax, %r8
leaq (%r14,%r11,8), %rax
movq 0x30(%rsp), %rcx
leaq (%rax,%rcx,8), %rbx
leaq (,%r10,8), %rax
subq %rax, %rbx
leaq -0x1(%r10), %r13
cmpq %r10, %r11
jle 0x5234
movq %r11, %rax
movq %r13, %rcx
movq -0x8(%r14,%rax,8), %rdx
testq %rdx, %rdx
je 0x522c
decq %rdx
movq %rdx, (%rbx,%rcx,8)
decq %rcx
decq %rax
cmpq %rax, %r10
jl 0x5218
movq 0x30(%rsp), %rax
leaq (%r11,%rax), %rdx
subq %r10, %rdx
subq %r10, %rdx
movl $0x8, %r9d
movq %rbx, %rdi
movq %r14, %rsi
movq %r10, %rcx
movq %r11, %r14
callq 0x4e48
movq %rax, %rcx
movq $-0x2, %rax
testq %rcx, %rcx
jne 0x5466
leaq -0x1(%r14), %rax
cmpq $0x8, %r12
movq %r14, %r11
jne 0x5286
movq 0x10(%rsp), %rcx
movq -0x8(%rcx,%r11,8), %rcx
jmp 0x528f
movq 0x10(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %r10
cmpq $0x2, %r11
jl 0x52e6
xorl %edx, %edx
movq %rcx, %rsi
cmpq $0x8, %r12
jne 0x52b6
movq 0x10(%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rcx
jmp 0x52c0
movq 0x10(%rsp), %rcx
movzbl -0x1(%rcx,%rax), %ecx
addq %rdx, %rsi
movl $0x1, %edi
cmpq %rsi, %rcx
jl 0x52db
testq %rdx, %rdx
je 0x52d9
movq %rax, (%rbx,%r13,8)
decq %r13
xorl %edi, %edi
decq %rax
movq %rdi, %rdx
testq %rax, %rax
jg 0x52a1
testq %r10, %r10
jle 0x5301
xorl %eax, %eax
movq (%r14,%rax,8), %rcx
movq (%rbx,%rcx,8), %rcx
movq %rcx, (%r14,%rax,8)
incq %rax
cmpq %rax, %r10
jne 0x52ed
movq 0x30(%rsp), %rax
subq %r15, %rax
jge 0x534c
leaq (,%r15,8), %rdi
leaq 0x1fcea(%rip), %rsi     # 0x25004
leaq 0x1fcef(%rip), %rcx     # 0x25010
movl $0xab, %edx
callq 0x23213
movq 0x28(%rsp), %r10
movq 0x18(%rsp), %r11
movq %rax, %rbx
movq %rax, %r13
testq %rax, %rax
jne 0x5364
movq $-0x2, %rax
jmp 0x5466
leaq (%r14,%r11,8), %r13
xorl %ecx, %ecx
cmpq %r15, %rax
cmovgeq %r15, %rcx
leaq (,%rcx,8), %rbx
addq %r13, %rbx
testq %r15, %r15
jle 0x5385
leaq (,%r15,8), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3140
movq 0x28(%rsp), %r10
movq 0x18(%rsp), %r11
testq %r11, %r11
jle 0x53b3
xorl %eax, %eax
cmpq $0x8, %r12
jne 0x539d
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
jmp 0x53a6
movq 0x10(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
incq (%r13,%rcx,8)
incq %rax
cmpq %rax, %r11
jne 0x538c
testq %r15, %r15
jle 0x53cd
xorl %eax, %eax
xorl %ecx, %ecx
addq (%r13,%rcx,8), %rax
movq %rax, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x53bc
movq %r11, %rdx
subq %r10, %rdx
jle 0x53ee
leaq (%r14,%r10,8), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3140
movq 0x28(%rsp), %r10
movq 0x18(%rsp), %r11
testq %r10, %r10
jle 0x5438
incq %r10
movq -0x10(%r14,%r10,8), %rax
movq $0x0, -0x10(%r14,%r10,8)
cmpq $0x8, %r12
jne 0x5415
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
jmp 0x541e
movq 0x10(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
movq (%rbx,%rcx,8), %rdx
leaq -0x1(%rdx), %rsi
movq %rsi, (%rbx,%rcx,8)
movq %rax, -0x8(%r14,%rdx,8)
decq %r10
cmpq $0x1, %r10
ja 0x53f6
movq %r12, (%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbx, %rcx
movq %r11, %r8
movq %r15, %r9
callq 0x5542
cmpq %r15, 0x30(%rsp)
jge 0x5464
movq %r13, %rdi
callq 0x3390
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq