#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*/ free(long *);
long maximum(int, long);
long computeLempelZivFact(long *lpf, long n) {
  long *lz, i;
  lz = (long *)emalloc(n * sizeof(long));
  lz[0] = 0;
  i = 0;
  while (lz[i] < n) {
    lz[i + 1] = lz[i] + maximum(1, lpf[lz[i]] + 1);
    i++;
  }
  free(lz);
  free(lpf);
  return i;
}


x86 assembly (clang, -O0):
<computeLempelZivFact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <emalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x10(%rbp),%rax
jge    11d1 <computeLempelZivFact+0xa1>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
mov    (%rax,%rcx,8),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1030 <maximum@plt>
mov    -0x28(%rbp),%rdx
add    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,0x8(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1164 <computeLempelZivFact+0x34>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x8(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeLempelZivFact>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x0(,%rsi,8),%rdi
call   1050 <emalloc@plt>
mov    %rax,%r15
movq   $0x0,(%rax)
test   %r12,%r12
jle    1185 <computeLempelZivFact+0x55>
xor    %ebx,%ebx
xor    %r13d,%r13d
mov    (%r14,%rbx,8),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1030 <maximum@plt>
add    %rax,%rbx
mov    %rbx,0x8(%r15,%r13,8)
add    $0x1,%r13
cmp    %r12,%rbx
jl     1160 <computeLempelZivFact+0x30>
jmp    1188 <computeLempelZivFact+0x58>
xor    %r13d,%r13d
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @computeLempelZivFact(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = mul i64 %7, 8
%9 = call i64 @emalloc(i64 %8)
%10 = inttoptr i64 %9 to i64*
store i64* %10, i64** %5
%11 = load i64*, i64** %5
%12 = getelementptr inbounds i64, i64* %11, i64 0
store i64 0, i64* %12
store i64 0, i64* %6
br label %13
13: ; preds = %20, %2
%14 = load i64*, i64** %5
%15 = load i64, i64* %6
%16 = getelementptr inbounds i64, i64* %14, i64 %15
%17 = load i64, i64* %16
%18 = load i64, i64* %4
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %41
20: ; preds = %13
%21 = load i64*, i64** %5
%22 = load i64, i64* %6
%23 = getelementptr inbounds i64, i64* %21, i64 %22
%24 = load i64, i64* %23
%25 = load i64*, i64** %3
%26 = load i64*, i64** %5
%27 = load i64, i64* %6
%28 = getelementptr inbounds i64, i64* %26, i64 %27
%29 = load i64, i64* %28
%30 = getelementptr inbounds i64, i64* %25, i64 %29
%31 = load i64, i64* %30
%32 = add nsw i64 %31, 1
%33 = call i64 @maximum(i32 1, i64 %32)
%34 = add nsw i64 %24, %33
%35 = load i64*, i64** %5
%36 = load i64, i64* %6
%37 = add nsw i64 %36, 1
%38 = getelementptr inbounds i64, i64* %35, i64 %37
store i64 %34, i64* %38
%39 = load i64, i64* %6
%40 = add nsw i64 %39, 1
store i64 %40, i64* %6
br label %13
41: ; preds = %13
%42 = load i64*, i64** %5
%43 = call i32 @free(i64* %42)
%44 = load i64*, i64** %3
%45 = call i32 @free(i64* %44)
%46 = load i64, i64* %6
ret i64 %46
}

LLVM IR (-O2):
define i64 @computeLempelZivFact(i64* nocapture %0, i64 %1) {
%3 = shl i64 %1, 3
%4 = tail call i64 @emalloc(i64 %3)
%5 = inttoptr i64 %4 to i64*
store i64 0, i64* %5
%6 = icmp sgt i64 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %2, %7
%8 = phi i64 [ %14, %7 ], [ 0, %2 ]
%9 = phi i64 [ %15, %7 ], [ 0, %2 ]
%10 = getelementptr inbounds i64, i64* %0, i64 %8
%11 = load i64, i64* %10
%12 = add nsw i64 %11, 1
%13 = tail call i64 @maximum(i32 1, i64 %12)
%14 = add nsw i64 %13, %8
%15 = add nuw nsw i64 %9, 1
%16 = getelementptr inbounds i64, i64* %5, i64 %15
store i64 %14, i64* %16
%17 = icmp slt i64 %14, %1
br i1 %17, label %7, label %18
18: ; preds = %7, %2
%19 = phi i64 [ 0, %2 ], [ %15, %7 ]
%20 = tail call i32 @free(i64* %5)
%21 = tail call i32 @free(i64* %0)
ret i64 %19
}