// File: /workspace/github_c_makefile_star2_O1/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 %rcx, %rbp
movq %rdi, 0x8(%rsp)
movq %rdx, %rax
movq %rdx, 0x20(%rsp)
subq %r8, %rax
movq %rsi, 0x18(%rsp)
jge 0x4e7b
leaq (,%r15,8), %rdi
leaq 0x201af(%rip), %rsi     # 0x25004
leaq 0x201b4(%rip), %rcx     # 0x25010
movl $0x71, %edx
callq 0x22d2b
movq 0x18(%rsp), %rsi
movq %rax, %rbx
movq %rax, %r14
testq %rax, %rax
jne 0x4e8c
jmp 0x5351
leaq (%rsi,%rbp,8), %r14
xorl %ecx, %ecx
cmpq %r15, %rax
cmovgeq %r15, %rcx
leaq (%r14,%rcx,8), %rbx
testq %r15, %r15
jle 0x4ea8
leaq (,%r15,8), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x3140
movq 0x18(%rsp), %rsi
testq %rbp, %rbp
movq 0x8(%rsp), %rdi
jle 0x4ed0
xorl %eax, %eax
cmpq $0x8, %r12
jne 0x4ec0
movq (%rdi,%rax,8), %rcx
jmp 0x4ec4
movzbl (%rdi,%rax), %ecx
incq (%r14,%rcx,8)
incq %rax
cmpq %rax, %rbp
jne 0x4eb4
testq %r15, %r15
jle 0x4ee9
xorl %eax, %eax
xorl %ecx, %ecx
addq (%r14,%rcx,8), %rax
movq %rax, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x4ed9
testq %rbp, %rbp
jle 0x4f0a
leaq (,%rbp,8), %rdx
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3140
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
cmpq $0x8, %r12
jne 0x4f17
movq -0x8(%rdi,%rbp,8), %r13
jmp 0x4f1d
movzbl -0x1(%rdi,%rbp), %r13d
cmpq $0x2, %rbp
jl 0x4f72
leaq -0x1(%rbp), %rax
xorl %ecx, %ecx
movq %r13, %rdx
cmpq $0x8, %r12
jne 0x4f39
movq -0x8(%rdi,%rax,8), %r13
jmp 0x4f3f
movzbl -0x1(%rdi,%rax), %r13d
leaq (%rdx,%rcx), %r9
movl $0x1, %r8d
cmpq %r9, %r13
jl 0x4f67
testq %rcx, %rcx
je 0x4f64
movq (%rbx,%rdx,8), %rcx
leaq -0x1(%rcx), %r8
movq %r8, (%rbx,%rdx,8)
movq %rax, -0x8(%rsi,%rcx,8)
xorl %r8d, %r8d
decq %rax
movq %r8, %rcx
testq %rax, %rax
jg 0x4f29
movq %r12, (%rsp)
movq %r14, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x553f
cmpq %r15, 0x20(%rsp)
jge 0x4f96
movq %r14, %rdi
callq 0x3390
testq %rbp, %rbp
jle 0x505c
movl $0x1, %eax
subq %rbp, %rax
movq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %r11
movq (%rsi,%rcx,8), %rdx
testq %rdx, %rdx
jle 0x504e
cmpq $0x8, %r12
jne 0x4fd6
movq -0x8(%r11,%rdx,8), %rdi
jmp 0x4fdc
movzbl -0x1(%r11,%rdx), %edi
cmpq $0x8, %r12
jne 0x4fe8
movq (%r11,%rdx,8), %r10
jmp 0x4fed
movzbl (%r11,%rdx), %r10d
cmpq %r10, %rdi
jle 0x504e
leaq 0x1(%rdx), %rdi
cmpq %rbp, %rdi
setl %dil
jge 0x5032
leaq 0x2(%rdx), %r8
cmpq $0x8, %r12
jne 0x5010
movq -0x8(%r11,%r8,8), %r13
jmp 0x5016
movzbl -0x1(%r11,%r8), %r13d
cmpq %r13, %r10
jne 0x5032
cmpq %rbp, %r8
setl %dil
leaq (%rax,%r8), %r9
incq %r9
incq %r8
cmpq $0x2, %r9
jne 0x5003
testb $0x1, %dil
je 0x504e
cmpq %r13, %r10
jge 0x504e
movq 0x10(%rsp), %rdi
movq %rdx, (%rsi,%rdi,8)
incq %rdi
movq %rdi, 0x10(%rsp)
incq %rcx
cmpq %rbp, %rcx
jne 0x4fbc
jmp 0x506f
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %r11
movq %rbp, %rdx
subq 0x10(%rsp), %rdx
jle 0x5097
movq 0x10(%rsp), %rax
leaq (%rsi,%rax,8), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3140
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %rsi
cmpq $0x8, %r12
jne 0x50a4
movq -0x8(%r11,%rbp,8), %rax
jmp 0x50aa
movzbl -0x1(%r11,%rbp), %eax
cmpq $0x2, %rbp
jl 0x5120
movq 0x10(%rsp), %rcx
leaq (%rsi,%rcx,8), %rcx
leaq -0x1(%rbp), %rdx
movl $0x1, %r11d
subq %rbp, %r11
xorl %r8d, %r8d
movq %rbp, %rdi
movq %rax, %r10
cmpq $0x8, %r12
jne 0x50e1
movq 0x8(%rsp), %rax
movq -0x8(%rax,%rdx,8), %rax
jmp 0x50eb
movq 0x8(%rsp), %rax
movzbl -0x1(%rax,%rdx), %eax
addq %r8, %r10
movl $0x1, %r9d
cmpq %r10, %rax
jl 0x5112
testq %r8, %r8
je 0x510f
addq %r11, %rdi
movq %rdx, %r8
andq $-0x2, %r8
movq %rdi, (%rcx,%r8,4)
movq %rdx, %rdi
xorl %r9d, %r9d
decq %rdx
incq %r11
movq %r9, %r8
testq %rdx, %rdx
jg 0x50cc
movq 0x10(%rsp), %r11
testq %r11, %r11
jle 0x51fb
leaq (%rsi,%r11,8), %rax
xorl %ebx, %ebx
xorl %r8d, %r8d
movq %rbp, 0x40(%rsp)
xorl %ecx, %ecx
movq 0x8(%rsp), %rdi
movq %r15, 0x30(%rsp)
movq %rbp, 0x28(%rsp)
movq (%rsi,%rcx,8), %rdx
movq %rdx, %r9
sarq %r9
movq (%rax,%r9,8), %r10
cmpq %r8, %r10
jne 0x51de
testq %r10, %r10
jle 0x51c7
movq %rbx, 0x38(%rsp)
leaq (%rdi,%rdx), %rbx
leaq (%rdi,%rdx,8), %r13
movq 0x40(%rsp), %rsi
leaq (%rdi,%rsi), %r15
leaq (%rdi,%rsi,8), %rbp
xorl %r11d, %r11d
cmpq $0x8, %r12
jne 0x518f
movq (%r13,%r11,8), %r14
jmp 0x5194
movzbl (%rbx,%r11), %r14d
cmpq $0x8, %r12
jne 0x51a1
movq (%rbp,%r11,8), %rsi
jmp 0x51a6
movzbl (%r15,%r11), %esi
cmpq %rsi, %r14
jne 0x51b6
incq %r11
cmpq %r11, %r10
jne 0x5182
movq %r10, %r11
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %rbp
movq 0x38(%rsp), %rbx
jmp 0x51ca
xorl %r11d, %r11d
cmpq %r10, %r11
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %r11
je 0x51e9
incq %rbx
movq %r10, %r8
movq %rdx, 0x40(%rsp)
movq %rbx, (%rax,%r9,8)
incq %rcx
cmpq %r11, %rcx
jne 0x514d
jmp 0x5202
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
cmpq %r11, %rbx
jge 0x530d
movq %rbx, %r8
leaq (%rsi,%rbp,8), %rax
movq 0x20(%rsp), %rcx
leaq (%rax,%rcx,8), %rbx
leaq (,%r11,8), %rax
subq %rax, %rbx
leaq -0x1(%r11), %r13
cmpq %r11, %rbp
jle 0x5251
movq %rbp, %rax
movq %r13, %rcx
movq -0x8(%rsi,%rax,8), %rdx
testq %rdx, %rdx
je 0x5249
decq %rdx
movq %rdx, (%rbx,%rcx,8)
decq %rcx
decq %rax
cmpq %rax, %r11
jl 0x5235
movq 0x20(%rsp), %rax
leaq (%rax,%rbp), %rdx
subq %r11, %rdx
subq %r11, %rdx
movl $0x8, %r9d
movq %rbx, %rdi
movq %r11, %rcx
callq 0x4e18
movq %rax, %rcx
movq $-0x2, %rax
testq %rcx, %rcx
jne 0x5465
leaq -0x1(%rbp), %rax
cmpq $0x8, %r12
jne 0x529a
movq 0x8(%rsp), %rdi
movq -0x8(%rdi,%rbp,8), %rcx
jmp 0x52a3
movq 0x8(%rsp), %rdi
movzbl (%rdi,%rax), %ecx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %r11
cmpq $0x2, %rbp
jl 0x52f2
xorl %edx, %edx
movq %rcx, %r8
cmpq $0x8, %r12
jne 0x52c5
movq -0x8(%rdi,%rax,8), %rcx
jmp 0x52ca
movzbl -0x1(%rdi,%rax), %ecx
addq %rdx, %r8
movl $0x1, %r9d
cmpq %r8, %rcx
jl 0x52e7
testq %rdx, %rdx
je 0x52e4
movq %rax, (%rbx,%r13,8)
decq %r13
xorl %r9d, %r9d
decq %rax
movq %r9, %rdx
testq %rax, %rax
jg 0x52b5
testq %r11, %r11
jle 0x530d
xorl %eax, %eax
movq (%rsi,%rax,8), %rcx
movq (%rbx,%rcx,8), %rcx
movq %rcx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %r11
jne 0x52f9
movq 0x20(%rsp), %rax
subq %r15, %rax
jge 0x535d
leaq (,%r15,8), %rdi
leaq 0x1fcde(%rip), %rsi     # 0x25004
leaq 0x1fce3(%rip), %rcx     # 0x25010
movl $0xab, %edx
callq 0x22d2b
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rax, %rbx
movq %rax, %r13
testq %rax, %rax
jne 0x5375
movq $-0x2, %rax
jmp 0x5465
leaq (%rsi,%rbp,8), %r13
xorl %ecx, %ecx
cmpq %r15, %rax
cmovgeq %r15, %rcx
leaq (,%rcx,8), %rbx
addq %r13, %rbx
testq %r15, %r15
jle 0x539b
leaq (,%r15,8), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3140
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
testq %rbp, %rbp
jle 0x53bf
xorl %eax, %eax
cmpq $0x8, %r12
jne 0x53ae
movq (%rdi,%rax,8), %rcx
jmp 0x53b2
movzbl (%rdi,%rax), %ecx
incq (%r13,%rcx,8)
incq %rax
cmpq %rax, %rbp
jne 0x53a2
testq %r15, %r15
jle 0x53d9
xorl %eax, %eax
xorl %ecx, %ecx
addq (%r13,%rcx,8), %rax
movq %rax, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x53c8
movq %rbp, %rdx
subq %r11, %rdx
jle 0x53ff
leaq (%rsi,%r11,8), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3140
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
testq %r11, %r11
jle 0x543f
incq %r11
movq -0x10(%rsi,%r11,8), %rax
movq $0x0, -0x10(%rsi,%r11,8)
cmpq $0x8, %r12
jne 0x5421
movq (%rdi,%rax,8), %rcx
jmp 0x5425
movzbl (%rdi,%rax), %ecx
movq (%rbx,%rcx,8), %rdx
leaq -0x1(%rdx), %r8
movq %r8, (%rbx,%rcx,8)
movq %rax, -0x8(%rsi,%rdx,8)
decq %r11
cmpq $0x1, %r11
jg 0x5407
movq %r12, (%rsp)
movq %r13, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x553f
cmpq %r15, 0x20(%rsp)
jge 0x5463
movq %r13, %rdi
callq 0x3390
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq