#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 const *, int *, int /*<<< orphan*/, int, int, int,
              int /*<<< orphan*/);
int sais(const unsigned char *T, unsigned int *SA, unsigned int n) {
  if ((T == NULL) || (SA == NULL)) {
    return -1;
  }
  if (n <= 1) {
    if (n == 1) {
      SA[0] = 0;
    }
    return 0;
  }
  return sais_main(T, (int *)SA, 0, (int)n, 256, sizeof(unsigned char), 0);
}


x86 assembly (clang, -O0):
<sais>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1139 <sais+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1145 <sais+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <sais+0x87>
cmpl   $0x1,-0x1c(%rbp)
ja     116f <sais+0x5f>
cmpl   $0x1,-0x1c(%rbp)
jne    1163 <sais+0x53>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1197 <sais+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
mov    $0x100,%r8d
mov    $0x1,%r9d
movl   $0x0,(%rsp)
call   1030 <sais_main@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sais>:
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1150 <sais+0x40>
test   %rsi,%rsi
je     1150 <sais+0x40>
mov    %edx,%ecx
cmp    $0x1,%edx
ja     1136 <sais+0x26>
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1150 <sais+0x40>
movl   $0x0,(%rsi)
pop    %rcx
ret
movl   $0x0,(%rsp)
xor    %edx,%edx
mov    $0x100,%r8d
mov    $0x1,%r9d
call   1030 <sais_main@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @sais(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %3
store i32 -1, i32* %4
br label %29
14: ; preds = %10
%15 = load i32, i32* %7
%16 = icmp ule i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32*, i32** %6
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 0, i32* %22
br label %23
23: ; preds = %20, %17
store i32 0, i32* %4
br label %29
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = load i32*, i32** %6
%27 = load i32, i32* %7
%28 = call i32 @sais_main(i8* %25, i32* %26, i32 0, i32 %27, i32 256, i32 1, i32 0)
store i32 %28, i32* %4
br label %29
29: ; preds = %24, %23, %13
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @sais(i8* %0, i32* %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i32* %1, null
%6 = or i1 %4, %5
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = icmp ult i32 %2, 2
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = icmp eq i32 %2, 1
br i1 %10, label %11, label %14
11: ; preds = %9
store i32 0, i32* %1
br label %14
12: ; preds = %7
%13 = tail call i32 @sais_main(i8* %0, i32* %1, i32 0, i32 %2, i32 256, i32 1, i32 0)
br label %14
14: ; preds = %9, %11, %3, %12
%15 = phi i32 [ %13, %12 ], [ -1, %3 ], [ 0, %11 ], [ 0, %9 ]
ret i32 %15
}