#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int sais_main(unsigned char *, int *, int *, int /*<<< orphan*/, int, int, int,
              int /*<<< orphan*/, int);
int sais(unsigned char *T, int *SA, int *LCP, int n) {
  if ((T == NULL) || (SA == NULL) || (LCP == NULL) || (n < 0)) {
    return -1;
  }
  if (n <= 1) {
    if (n == 1) {
      SA[0] = 0;
      LCP[0] = 0;
    }
    return 0;
  }
  T[n - 1] = 0;
  return sais_main(T, SA, LCP, 0, n, 256, sizeof(unsigned char), 0, 1);
}


x86 assembly (clang, -O0):
<sais>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <sais+0x42>
cmpq   $0x0,-0x18(%rbp)
je     1152 <sais+0x42>
cmpq   $0x0,-0x20(%rbp)
je     1152 <sais+0x42>
cmpl   $0x0,-0x24(%rbp)
jge    115e <sais+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <sais+0xca>
cmpl   $0x1,-0x24(%rbp)
jg     1192 <sais+0x82>
cmpl   $0x1,-0x24(%rbp)
jne    1186 <sais+0x76>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11da <sais+0xca>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%r8d
xor    %ecx,%ecx
mov    $0x100,%r9d
movl   $0x1,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x1,0x10(%rsp)
call   1030 <sais_main@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sais>:
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     116b <sais+0x5b>
test   %rsi,%rsi
je     116b <sais+0x5b>
test   %rdx,%rdx
je     116b <sais+0x5b>
mov    %ecx,%r8d
test   %ecx,%ecx
js     116b <sais+0x5b>
cmp    $0x1,%r8d
ja     1148 <sais+0x38>
xor    %eax,%eax
cmp    $0x1,%r8d
jne    116b <sais+0x5b>
movl   $0x0,(%rsi)
movl   $0x0,(%rdx)
pop    %rcx
ret
lea    -0x1(%r8),%eax
movb   $0x0,(%rdi,%rax,1)
sub    $0x8,%rsp
xor    %ecx,%ecx
mov    $0x100,%r9d
push   $0x1
push   $0x0
push   $0x1
call   1030 <sais_main@plt>
add    $0x20,%rsp
pop    %rcx
ret

LLVM IR (-O0):
define i32 @sais(i8* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %4
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = load i32*, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %15, %12, %4
store i32 -1, i32* %5
br label %45
22: ; preds = %18
%23 = load i32, i32* %9
%24 = icmp sle i32 %23, 1
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32*, i32** %7
%30 = getelementptr inbounds i32, i32* %29, i64 0
store i32 0, i32* %30
%31 = load i32*, i32** %8
%32 = getelementptr inbounds i32, i32* %31, i64 0
store i32 0, i32* %32
br label %33
33: ; preds = %28, %25
store i32 0, i32* %5
br label %45
34: ; preds = %22
%35 = load i8*, i8** %6
%36 = load i32, i32* %9
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %6
%41 = load i32*, i32** %7
%42 = load i32*, i32** %8
%43 = load i32, i32* %9
%44 = call i32 @sais_main(i8* %40, i32* %41, i32* %42, i32 0, i32 %43, i32 256, i32 1, i32 0, i32 1)
store i32 %44, i32* %5
br label %45
45: ; preds = %34, %33, %21
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
define i32 @sais(i8* %0, i32* %1, i32* %2, i32 %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i32* %1, null
%7 = or i1 %5, %6
%8 = icmp eq i32* %2, null
%9 = or i1 %7, %8
%10 = icmp slt i32 %3, 0
%11 = or i1 %9, %10
br i1 %11, label %22, label %12
12: ; preds = %4
%13 = icmp ult i32 %3, 2
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = icmp eq i32 %3, 1
br i1 %15, label %16, label %22
16: ; preds = %14
store i32 0, i32* %1
store i32 0, i32* %2
br label %22
17: ; preds = %12
%18 = add nsw i32 %3, -1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
%21 = tail call i32 @sais_main(i8* %0, i32* %1, i32* %2, i32 0, i32 %3, i32 256, i32 1, i32 0, i32 1)
br label %22
22: ; preds = %14, %16, %4, %17
%23 = phi i32 [ %21, %17 ], [ -1, %4 ], [ 0, %16 ], [ 0, %14 ]
ret i32 %23
}