#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 */
scalar_t__ emalloc(long);
int /*<<< orphan*/ freeStack();
long maximum(long, long);
long minimum(long, long);
int /*<<< orphan*/ stackEmpty();
int /*<<< orphan*/ stackInit(int);
int /*<<< orphan*/ stackPop();
int /*<<< orphan*/ stackPush(long);
size_t stackTop();
long *computeLpf(long *sa, long *lcp, long n) {
  long i;
  long *lpf;
  lpf = (long *)emalloc(n * sizeof(long));
  sa[n] = -1;
  lcp[n] = 0;
  stackInit(1);
  stackPush(0);
  for (i = 1; i <= n; i++) {
    while (!stackEmpty() &&
           (sa[i] < sa[stackTop()] ||
            (sa[i] > sa[stackTop()] && lcp[i] <= lcp[stackTop()]))) {
      if (sa[i] < sa[stackTop()]) {
        lpf[sa[stackTop()]] = maximum(lcp[stackTop()], lcp[i]);
        lcp[i] = minimum(lcp[stackTop()], lcp[i]);
      } else
        lpf[sa[stackTop()]] = lcp[stackTop()];
      stackPop();
    }
    if (i < n)
      stackPush(i);
  }
  freeStack();
  return lpf;
}


x86 assembly (clang, -O0):
<computeLpf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <emalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movq   $0xffffffffffffffff,(%rax,%rcx,8)
ff
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    $0x1,%edi
call   1070 <stackInit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <stackPush@plt>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     1464 <computeLpf+0x2d4>
jmp    1206 <computeLpf+0x76>
mov    $0x0,%al
call   1060 <stackEmpty@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    12cf <computeLpf+0x13f>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%rsi
mov    $0x1,%al
cmp    (%rdx,%rsi,8),%rcx
mov    %al,-0x2a(%rbp)
jl     12c9 <computeLpf+0x139>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %rax,%rsi
xor    %eax,%eax
cmp    (%rdx,%rsi,8),%rcx
mov    %al,-0x41(%rbp)
jle    12c3 <computeLpf+0x133>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    -0x68(%rbp),%rcx
mov    %rax,%rdx
mov    -0x60(%rbp),%rax
cmp    (%rcx,%rdx,8),%rax
setle  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    12df <computeLpf+0x14f>
jmp    1437 <computeLpf+0x2a7>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    -0x78(%rbp),%rcx
mov    %rax,%rdx
mov    -0x70(%rbp),%rax
cmp    (%rcx,%rdx,8),%rax
jge    13c7 <computeLpf+0x237>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <maximum@plt>
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    -0x98(%rbp),%rcx
mov    -0x90(%rbp),%rdx
mov    %rax,%rsi
mov    -0x88(%rbp),%rax
mov    (%rcx,%rsi,8),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <minimum@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    142b <computeLpf+0x29b>
mov    -0x10(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    %rax,%rcx
mov    -0xc0(%rbp),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    $0x0,%al
call   1050 <stackTop@plt>
mov    -0xb8(%rbp),%rcx
mov    -0xb0(%rbp),%rdx
mov    %rax,%rsi
mov    -0xa8(%rbp),%rax
mov    (%rcx,%rsi,8),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   10a0 <stackPop@plt>
jmp    1206 <computeLpf+0x76>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    144e <computeLpf+0x2be>
mov    -0x20(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    1453 <computeLpf+0x2c3>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11f3 <computeLpf+0x63>
mov    $0x0,%al
call   1090 <freeStack@plt>
mov    -0x28(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeLpf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
lea    0x0(,%rdx,8),%rdi
call   1080 <emalloc@plt>
mov    %rax,0x8(%rsp)
movq   $0xffffffffffffffff,0x0(%r13,%rbp,8)
ff ff
movq   $0x0,(%r12,%rbp,8)
mov    $0x1,%edi
call   1070 <stackInit@plt>
xor    %edi,%edi
call   10b0 <stackPush@plt>
test   %rbp,%rbp
jle    12da <computeLpf+0x14a>
mov    $0x1,%ebx
mov    %rbp,0x10(%rsp)
jmp    120c <computeLpf+0x7c>
xor    %eax,%eax
call   1050 <stackTop@plt>
mov    0x0(%r13,%rax,8),%rax
mov    0x8(%rsp),%rcx
mov    %rbp,(%rcx,%rax,8)
xor    %eax,%eax
call   10a0 <stackPop@plt>
xor    %eax,%eax
call   1060 <stackEmpty@plt>
test   %eax,%eax
jne    12b8 <computeLpf+0x128>
mov    0x0(%r13,%rbx,8),%rbp
xor    %eax,%eax
call   1050 <stackTop@plt>
cmp    0x0(%r13,%rax,8),%rbp
jl     1252 <computeLpf+0xc2>
mov    0x0(%r13,%rbx,8),%rbp
xor    %eax,%eax
call   1050 <stackTop@plt>
cmp    0x0(%r13,%rax,8),%rbp
jle    12b8 <computeLpf+0x128>
mov    (%r12,%rbx,8),%rbp
xor    %eax,%eax
call   1050 <stackTop@plt>
cmp    (%r12,%rax,8),%rbp
jg     12b8 <computeLpf+0x128>
mov    0x0(%r13,%rbx,8),%r14
xor    %eax,%eax
call   1050 <stackTop@plt>
mov    0x0(%r13,%rax,8),%r15
xor    %eax,%eax
call   1050 <stackTop@plt>
mov    (%r12,%rax,8),%rbp
cmp    %r15,%r14
jge    11f0 <computeLpf+0x60>
mov    (%r12,%rbx,8),%rsi
mov    %rbp,%rdi
call   1030 <maximum@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <stackTop@plt>
mov    0x0(%r13,%rax,8),%rax
mov    0x8(%rsp),%rcx
mov    %rbp,(%rcx,%rax,8)
xor    %eax,%eax
call   1050 <stackTop@plt>
mov    (%r12,%rax,8),%rdi
mov    (%r12,%rbx,8),%rsi
call   1040 <minimum@plt>
mov    %rax,(%r12,%rbx,8)
jmp    1205 <computeLpf+0x75>
mov    0x10(%rsp),%rbp
cmp    %rbp,%rbx
jge    12ca <computeLpf+0x13a>
mov    %rbx,%rdi
call   10b0 <stackPush@plt>
lea    0x1(%rbx),%rax
cmp    %rbp,%rbx
mov    %rax,%rbx
jne    120c <computeLpf+0x7c>
xor    %eax,%eax
call   1090 <freeStack@plt>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64* @computeLpf(i64* %0, i64* %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64*
store i64* %0, i64** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = mul i64 %9, 8
%11 = call i64 @emalloc(i64 %10)
%12 = inttoptr i64 %11 to i64*
store i64* %12, i64** %8
%13 = load i64*, i64** %4
%14 = load i64, i64* %6
%15 = getelementptr inbounds i64, i64* %13, i64 %14
store i64 -1, i64* %15
%16 = load i64*, i64** %5
%17 = load i64, i64* %6
%18 = getelementptr inbounds i64, i64* %16, i64 %17
store i64 0, i64* %18
%19 = call i32 @stackInit(i32 1)
%20 = call i32 @stackPush(i64 0)
store i64 1, i64* %7
br label %21
21: ; preds = %124, %3
%22 = load i64, i64* %7
%23 = load i64, i64* %6
%24 = icmp sle i64 %22, %23
br i1 %24, label %25, label %127
25: ; preds = %21
br label %26
26: ; preds = %114, %25
%27 = call i32 (...) @stackEmpty()
%28 = icmp ne i32 %27, 0
br i1 %28, label %63, label %29
29: ; preds = %26
%30 = load i64*, i64** %4
%31 = load i64, i64* %7
%32 = getelementptr inbounds i64, i64* %30, i64 %31
%33 = load i64, i64* %32
%34 = load i64*, i64** %4
%35 = call i64 (...) @stackTop()
%36 = getelementptr inbounds i64, i64* %34, i64 %35
%37 = load i64, i64* %36
%38 = icmp slt i64 %33, %37
br i1 %38, label %61, label %39
39: ; preds = %29
%40 = load i64*, i64** %4
%41 = load i64, i64* %7
%42 = getelementptr inbounds i64, i64* %40, i64 %41
%43 = load i64, i64* %42
%44 = load i64*, i64** %4
%45 = call i64 (...) @stackTop()
%46 = getelementptr inbounds i64, i64* %44, i64 %45
%47 = load i64, i64* %46
%48 = icmp sgt i64 %43, %47
br i1 %48, label %49, label %59
49: ; preds = %39
%50 = load i64*, i64** %5
%51 = load i64, i64* %7
%52 = getelementptr inbounds i64, i64* %50, i64 %51
%53 = load i64, i64* %52
%54 = load i64*, i64** %5
%55 = call i64 (...) @stackTop()
%56 = getelementptr inbounds i64, i64* %54, i64 %55
%57 = load i64, i64* %56
%58 = icmp sle i64 %53, %57
br label %59
59: ; preds = %49, %39
%60 = phi i1 [ false, %39 ], [ %58, %49 ]
br label %61
61: ; preds = %59, %29
%62 = phi i1 [ true, %29 ], [ %60, %59 ]
br label %63
63: ; preds = %61, %26
%64 = phi i1 [ false, %26 ], [ %62, %61 ]
br i1 %64, label %65, label %116
65: ; preds = %63
%66 = load i64*, i64** %4
%67 = load i64, i64* %7
%68 = getelementptr inbounds i64, i64* %66, i64 %67
%69 = load i64, i64* %68
%70 = load i64*, i64** %4
%71 = call i64 (...) @stackTop()
%72 = getelementptr inbounds i64, i64* %70, i64 %71
%73 = load i64, i64* %72
%74 = icmp slt i64 %69, %73
br i1 %74, label %75, label %103
75: ; preds = %65
%76 = load i64*, i64** %5
%77 = call i64 (...) @stackTop()
%78 = getelementptr inbounds i64, i64* %76, i64 %77
%79 = load i64, i64* %78
%80 = load i64*, i64** %5
%81 = load i64, i64* %7
%82 = getelementptr inbounds i64, i64* %80, i64 %81
%83 = load i64, i64* %82
%84 = call i64 @maximum(i64 %79, i64 %83)
%85 = load i64*, i64** %8
%86 = load i64*, i64** %4
%87 = call i64 (...) @stackTop()
%88 = getelementptr inbounds i64, i64* %86, i64 %87
%89 = load i64, i64* %88
%90 = getelementptr inbounds i64, i64* %85, i64 %89
store i64 %84, i64* %90
%91 = load i64*, i64** %5
%92 = call i64 (...) @stackTop()
%93 = getelementptr inbounds i64, i64* %91, i64 %92
%94 = load i64, i64* %93
%95 = load i64*, i64** %5
%96 = load i64, i64* %7
%97 = getelementptr inbounds i64, i64* %95, i64 %96
%98 = load i64, i64* %97
%99 = call i64 @minimum(i64 %94, i64 %98)
%100 = load i64*, i64** %5
%101 = load i64, i64* %7
%102 = getelementptr inbounds i64, i64* %100, i64 %101
store i64 %99, i64* %102
br label %114
103: ; preds = %65
%104 = load i64*, i64** %5
%105 = call i64 (...) @stackTop()
%106 = getelementptr inbounds i64, i64* %104, i64 %105
%107 = load i64, i64* %106
%108 = load i64*, i64** %8
%109 = load i64*, i64** %4
%110 = call i64 (...) @stackTop()
%111 = getelementptr inbounds i64, i64* %109, i64 %110
%112 = load i64, i64* %111
%113 = getelementptr inbounds i64, i64* %108, i64 %112
store i64 %107, i64* %113
br label %114
114: ; preds = %103, %75
%115 = call i32 (...) @stackPop()
br label %26
116: ; preds = %63
%117 = load i64, i64* %7
%118 = load i64, i64* %6
%119 = icmp slt i64 %117, %118
br i1 %119, label %120, label %123
120: ; preds = %116
%121 = load i64, i64* %7
%122 = call i32 @stackPush(i64 %121)
br label %123
123: ; preds = %120, %116
br label %124
124: ; preds = %123
%125 = load i64, i64* %7
%126 = add nsw i64 %125, 1
store i64 %126, i64* %7
br label %21
127: ; preds = %21
%128 = call i32 (...) @freeStack()
%129 = load i64*, i64** %8
ret i64* %129
}

LLVM IR (-O2):
define i64* @computeLpf(i64* nocapture %0, i64* nocapture %1, i64 %2) {
%4 = shl i64 %2, 3
%5 = tail call i64 @emalloc(i64 %4)
%6 = inttoptr i64 %5 to i64*
%7 = getelementptr inbounds i64, i64* %0, i64 %2
store i64 -1, i64* %7
%8 = getelementptr inbounds i64, i64* %1, i64 %2
store i64 0, i64* %8
%9 = tail call i32 @stackInit(i32 1)
%10 = tail call i32 @stackPush(i64 0)
%11 = icmp slt i64 %2, 1
br i1 %11, label %74, label %12
12: ; preds = %3, %71
%13 = phi i64 [ %72, %71 ], [ 1, %3 ]
%14 = getelementptr inbounds i64, i64* %1, i64 %13
%15 = tail call i32 (...) @stackEmpty()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %67
17: ; preds = %12
%18 = getelementptr inbounds i64, i64* %0, i64 %13
br label %19
19: ; preds = %17, %63
%20 = load i64, i64* %18
%21 = tail call i64 (...) @stackTop()
%22 = getelementptr inbounds i64, i64* %0, i64 %21
%23 = load i64, i64* %22
%24 = icmp slt i64 %20, %23
br i1 %24, label %37, label %25
25: ; preds = %19
%26 = load i64, i64* %18
%27 = tail call i64 (...) @stackTop()
%28 = getelementptr inbounds i64, i64* %0, i64 %27
%29 = load i64, i64* %28
%30 = icmp sgt i64 %26, %29
br i1 %30, label %31, label %67
31: ; preds = %25
%32 = load i64, i64* %14
%33 = tail call i64 (...) @stackTop()
%34 = getelementptr inbounds i64, i64* %1, i64 %33
%35 = load i64, i64* %34
%36 = icmp sgt i64 %32, %35
br i1 %36, label %67, label %37
37: ; preds = %19, %31
%38 = load i64, i64* %18
%39 = tail call i64 (...) @stackTop()
%40 = getelementptr inbounds i64, i64* %0, i64 %39
%41 = load i64, i64* %40
%42 = icmp slt i64 %38, %41
%43 = tail call i64 (...) @stackTop()
%44 = getelementptr inbounds i64, i64* %1, i64 %43
%45 = load i64, i64* %44
br i1 %42, label %46, label %58
46: ; preds = %37
%47 = load i64, i64* %14
%48 = tail call i64 @maximum(i64 %45, i64 %47)
%49 = tail call i64 (...) @stackTop()
%50 = getelementptr inbounds i64, i64* %0, i64 %49
%51 = load i64, i64* %50
%52 = getelementptr inbounds i64, i64* %6, i64 %51
store i64 %48, i64* %52
%53 = tail call i64 (...) @stackTop()
%54 = getelementptr inbounds i64, i64* %1, i64 %53
%55 = load i64, i64* %54
%56 = load i64, i64* %14
%57 = tail call i64 @minimum(i64 %55, i64 %56)
store i64 %57, i64* %14
br label %63
58: ; preds = %37
%59 = tail call i64 (...) @stackTop()
%60 = getelementptr inbounds i64, i64* %0, i64 %59
%61 = load i64, i64* %60
%62 = getelementptr inbounds i64, i64* %6, i64 %61
store i64 %45, i64* %62
br label %63
63: ; preds = %58, %46
%64 = tail call i32 (...) @stackPop()
%65 = tail call i32 (...) @stackEmpty()
%66 = icmp eq i32 %65, 0
br i1 %66, label %19, label %67
67: ; preds = %31, %63, %25, %12
%68 = icmp slt i64 %13, %2
br i1 %68, label %69, label %71
69: ; preds = %67
%70 = tail call i32 @stackPush(i64 %13)
br label %71
71: ; preds = %67, %69
%72 = add nuw i64 %13, 1
%73 = icmp eq i64 %13, %2
br i1 %73, label %74, label %12
74: ; preds = %71, %3
%75 = tail call i32 (...) @freeStack()
ret i64* %6
}