#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 /*<<< orphan*/ construct_SA(unsigned char const *, int *, int *, int *, int,
                                int);
int sort_typeBstar(unsigned char const *, int *, int *, int *, int);
int divsufsort(const unsigned char *T, int *SA, int *bucket, int n) {
  int *bucket_A = bucket, *bucket_B = bucket + ((256));
  int m;
  int err = 0;
  if ((T == NULL) || (SA == NULL) || (n < 0))
    return -1;
  if (n == 0)
    return 0;
  if (n == 1)
    return SA[0] = 0;
  if (n == 2) {
    SA[m = T[0] < T[1]] = 1;
    return SA[m ^ 1] = 0;
  }
  if (bucket)
    m = sort_typeBstar(T, SA, bucket_A, bucket_B, n),
    construct_SA(T, SA, bucket_A, bucket_B, n, m);
  else
    err = -2;
  return err;
}


x86 assembly (clang, -O0):
<divsufsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x400,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <divsufsort+0x54>
cmpq   $0x0,-0x18(%rbp)
je     1174 <divsufsort+0x54>
cmpl   $0x0,-0x24(%rbp)
jge    1180 <divsufsort+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <divsufsort+0x141>
cmpl   $0x0,-0x24(%rbp)
jne    1196 <divsufsort+0x76>
movl   $0x0,-0x4(%rbp)
jmp    1261 <divsufsort+0x141>
cmpl   $0x1,-0x24(%rbp)
jne    11b6 <divsufsort+0x96>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1261 <divsufsort+0x141>
cmpl   $0x2,-0x24(%rbp)
jne    120b <divsufsort+0xeb>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movzbl (%rcx),%ecx
mov    -0x10(%rbp),%rdx
movzbl 0x1(%rdx),%edx
cmp    %edx,%ecx
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x3c(%rbp)
movslq %ecx,%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
xor    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
movl   $0x0,-0x4(%rbp)
jmp    1261 <divsufsort+0x141>
cmpq   $0x0,-0x20(%rbp)
je     1254 <divsufsort+0x134>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1040 <sort_typeBstar@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
call   1030 <construct_SA@plt>
jmp    125b <divsufsort+0x13b>
movl   $0xfffffffe,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<divsufsort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11bd <divsufsort+0x9d>
mov    %rsi,%r14
test   %rsi,%rsi
je     11bd <divsufsort+0x9d>
mov    %ecx,%ebp
mov    %rdx,%r15
lea    0x400(%rdx),%r12
test   %ecx,%ecx
js     11bd <divsufsort+0x9d>
je     1166 <divsufsort+0x46>
mov    %rdi,%rbx
cmp    $0x2,%ebp
je     116a <divsufsort+0x4a>
cmp    $0x1,%ebp
jne    118b <divsufsort+0x6b>
movl   $0x0,(%r14)
jmp    11bb <divsufsort+0x9b>
mov    %ebp,%eax
jmp    11bd <divsufsort+0x9d>
mov    (%rbx),%al
xor    %ecx,%ecx
xor    %edx,%edx
cmp    0x1(%rbx),%al
setae  %cl
setb   %dl
movl   $0x1,(%r14,%rdx,4)
movl   $0x0,(%r14,%rcx,4)
jmp    11bb <divsufsort+0x9b>
test   %r15,%r15
je     11c6 <divsufsort+0xa6>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %ebp,%r8d
call   1040 <sort_typeBstar@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
call   1030 <construct_SA@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xfffffffe,%eax
jmp    11bd <divsufsort+0x9d>

LLVM IR (-O0):
define i32 @divsufsort(i8* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%14 = load i32*, i32** %8
store i32* %14, i32** %10
%15 = load i32*, i32** %8
%16 = getelementptr inbounds i32, i32* %15, i64 256
store i32* %16, i32** %11
store i32 0, i32* %13
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %4
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22, %19, %4
store i32 -1, i32* %5
br label %78
26: ; preds = %22
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 0, i32* %5
br label %78
30: ; preds = %26
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32*, i32** %7
%35 = getelementptr inbounds i32, i32* %34, i64 0
store i32 0, i32* %35
store i32 0, i32* %5
br label %78
36: ; preds = %30
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %58
39: ; preds = %36
%40 = load i32*, i32** %7
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp slt i32 %44, %48
%50 = zext i1 %49 to i32
store i32 %50, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %40, i64 %51
store i32 1, i32* %52
%53 = load i32*, i32** %7
%54 = load i32, i32* %12
%55 = xor i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %53, i64 %56
store i32 0, i32* %57
store i32 0, i32* %5
br label %78
58: ; preds = %36
%59 = load i32*, i32** %8
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %75
61: ; preds = %58
%62 = load i8*, i8** %6
%63 = load i32*, i32** %7
%64 = load i32*, i32** %10
%65 = load i32*, i32** %11
%66 = load i32, i32* %9
%67 = call i32 @sort_typeBstar(i8* %62, i32* %63, i32* %64, i32* %65, i32 %66)
store i32 %67, i32* %12
%68 = load i8*, i8** %6
%69 = load i32*, i32** %7
%70 = load i32*, i32** %10
%71 = load i32*, i32** %11
%72 = load i32, i32* %9
%73 = load i32, i32* %12
%74 = call i32 @construct_SA(i8* %68, i32* %69, i32* %70, i32* %71, i32 %72, i32 %73)
br label %76
75: ; preds = %58
store i32 -2, i32* %13
br label %76
76: ; preds = %75, %61
%77 = load i32, i32* %13
store i32 %77, i32* %5
br label %78
78: ; preds = %76, %39, %33, %29, %25
%79 = load i32, i32* %5
ret i32 %79
}

LLVM IR (-O2):
define i32 @divsufsort(i8* %0, i32* %1, i32* %2, i32 %3) {
%5 = getelementptr inbounds i32, i32* %2, i64 256
%6 = icmp eq i8* %0, null
%7 = icmp eq i32* %1, null
%8 = or i1 %6, %7
%9 = icmp slt i32 %3, 0
%10 = or i1 %8, %9
br i1 %10, label %28, label %11
11: ; preds = %4
switch i32 %3, label %23 [
i32 0, label %28
i32 1, label %12
i32 2, label %13
]
12: ; preds = %11
store i32 0, i32* %1
br label %28
13: ; preds = %11
%14 = load i8, i8* %0
%15 = getelementptr inbounds i8, i8* %0, i64 1
%16 = load i8, i8* %15
%17 = icmp ult i8 %14, %16
%18 = zext i1 %17 to i64
%19 = getelementptr inbounds i32, i32* %1, i64 %18
store i32 1, i32* %19
%20 = xor i1 %17, true
%21 = zext i1 %20 to i64
%22 = getelementptr inbounds i32, i32* %1, i64 %21
store i32 0, i32* %22
br label %28
23: ; preds = %11
%24 = icmp eq i32* %2, null
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = tail call i32 @sort_typeBstar(i8* %0, i32* %1, i32* %2, i32* %5, i32 %3)
%27 = tail call i32 @construct_SA(i8* %0, i32* %1, i32* %2, i32* %5, i32 %3, i32 %26)
br label %28
28: ; preds = %25, %23, %11, %4, %13, %12
%29 = phi i32 [ 0, %12 ], [ 0, %13 ], [ -1, %4 ], [ %3, %11 ], [ 0, %25 ], [ -2, %23 ]
ret i32 %29
}