#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*/ EXIT_FAILURE;
int /*<<< orphan*/ compute_sa(unsigned int *, char *, size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(void) {
  char *line = NULL;
  int read;
  size_t len;
  read = getline(&line, &len, stdin);
  if (read < 0)
    exit(EXIT_FAILURE);
  unsigned int sa[len];
  compute_sa(sa, line, len);
  printf(" Index         SA\n");
  for (unsigned int i = 0; i < len; i++)
    printf("%12u : %12u\n", i, sa[i]);
  free(line);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1198 <main+0x48>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <compute_sa@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    1218 <main+0xc8>
mov    -0x40(%rbp),%rax
mov    -0x34(%rbp),%esi
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e2 <main+0x92>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,-0x30(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getline@plt>
test   %eax,%eax
js     1214 <main+0xb4>
mov    %rsp,%r12
mov    -0x28(%rbp),%rax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %r15,%rdi
call   1060 <compute_sa@plt>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
cmpq   $0x0,-0x28(%rbp)
je     11f9 <main+0x99>
lea    0xe25(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
cmp    %rbx,-0x28(%rbp)
ja     11e0 <main+0x80>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [19 x i8] c" Index SA\0A\00"
@.str.1 = [13 x i8] c"%12u : %12u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %2, i64* %4, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i64, i64* %4
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca i32, i64 %16
store i64 %16, i64* %6
%19 = load i8*, i8** %2
%20 = load i64, i64* %4
%21 = call i32 @compute_sa(i32* %18, i8* %19, i64 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %23
23: ; preds = %35, %15
%24 = load i32, i32* %7
%25 = zext i32 %24 to i64
%26 = load i64, i64* %4
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %23
%29 = load i32, i32* %7
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %18, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %33)
br label %35
35: ; preds = %28
%36 = load i32, i32* %7
%37 = add i32 %36, 1
store i32 %37, i32* %7
br label %23
38: ; preds = %23
%39 = load i8*, i8** %2
%40 = call i32 @free(i8* %39)
%41 = load i8*, i8** %5
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"%12u : %12u\0A\00"
@str = [18 x i8] c" Index SA\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
%5 = load i32, i32* @stdin
%6 = call i32 @getline(i8** %1, i64* %2, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i64, i64* %2
%13 = call i8* @llvm.stacksave()
%14 = alloca i32, i64 %12
%15 = load i8*, i8** %1
%16 = load i64, i64* %2
%17 = call i32 @compute_sa(i32* %14, i8* %15, i64 %16)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%19 = load i64, i64* %2
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %24, %11
%22 = load i8*, i8** %1
%23 = call i32 @free(i8* %22)
ret i32 0
24: ; preds = %11, %24
%25 = phi i64 [ %31, %24 ], [ 0, %11 ]
%26 = trunc i64 %25 to i32
%27 = getelementptr inbounds i32, i32* %14, i64 %25
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %28)
%30 = add nuw nsw i64 %25, 1
%31 = and i64 %30, 4294967295
%32 = load i64, i64* %2
%33 = icmp ugt i64 %32, %31
br i1 %33, label %24, label %21
}