#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*/ suffix_array(unsigned int *, unsigned int *, unsigned int,
                                int);
void compute_sa(unsigned int *sa, const char *str, size_t len) {
  unsigned int str2[len];
  unsigned int i = 0;
  for (; i < len && str[i] != '\n'; i++)
    str2[i] = str[i];
  suffix_array(str2, sa, i, 4);
}


x86 assembly (clang, -O0):
<compute_sa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x39(%rbp)
jae    117b <compute_sa+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    118b <compute_sa+0x7b>
jmp    11ae <compute_sa+0x9e>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
movsbl (%rcx,%rdx,1),%edx
mov    -0x2c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1153 <compute_sa+0x43>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x4,%ecx
call   1030 <suffix_array@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_sa>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,%r8
mov    %rsp,%rdi
lea    0xf(,%rdx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
xor    %ecx,%ecx
test   %rdx,%rdx
je     1154 <compute_sa+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rsi,%rcx,1),%eax
cmp    $0xa,%eax
je     1154 <compute_sa+0x44>
mov    %eax,(%rdi,%rcx,4)
add    $0x1,%ecx
cmp    %rdx,%rcx
jb     1140 <compute_sa+0x30>
mov    %r8,%rsi
mov    %ecx,%edx
mov    $0x4,%ecx
call   1030 <suffix_array@plt>
mov    %rbp,%rsp
pop    %rbp
ret

LLVM IR (-O0):
define void @compute_sa(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i64, i64* %6
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i32, i64 %10
store i64 %10, i64* %8
store i32 0, i32* %9
br label %13
13: ; preds = %38, %3
%14 = load i32, i32* %9
%15 = zext i32 %14 to i64
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i32, i32* %9
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br label %26
26: ; preds = %18, %13
%27 = phi i1 [ false, %13 ], [ %25, %18 ]
br i1 %27, label %28, label %41
28: ; preds = %26
%29 = load i8*, i8** %5
%30 = load i32, i32* %9
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i32, i32* %9
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %12, i64 %36
store i32 %34, i32* %37
br label %38
38: ; preds = %28
%39 = load i32, i32* %9
%40 = add i32 %39, 1
store i32 %40, i32* %9
br label %13
41: ; preds = %26
%42 = load i32*, i32** %4
%43 = load i32, i32* %9
%44 = call i32 @suffix_array(i32* %12, i32* %42, i32 %43, i32 4)
%45 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
define void @compute_sa(i32* %0, i8* nocapture %1, i64 %2) {
%4 = alloca i32, i64 %2
%5 = icmp eq i64 %2, 0
br i1 %5, label %20, label %6
6: ; preds = %3, %12
%7 = phi i64 [ %16, %12 ], [ 0, %3 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
%11 = trunc i64 %7 to i32
br i1 %10, label %18, label %12
12: ; preds = %6
%13 = sext i8 %9 to i32
%14 = getelementptr inbounds i32, i32* %4, i64 %7
store i32 %13, i32* %14
%15 = add i32 %11, 1
%16 = zext i32 %15 to i64
%17 = icmp ult i64 %16, %2
br i1 %17, label %6, label %20
18: ; preds = %6
%19 = trunc i64 %7 to i32
br label %20
20: ; preds = %18, %12, %3
%21 = phi i32 [ 0, %3 ], [ %19, %18 ], [ %15, %12 ]
%22 = call i32 @suffix_array(i32* %4, i32* %0, i32 %21, i32 4)
ret void
}