#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 */
double log(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
double *initLogD(int L) {
  if (L < 2)
    L = 2;
  double *LogD = (double *)malloc(sizeof(double) * L);
  memset(LogD, 0, sizeof(double) * L);
  LogD[0] = 0;
  LogD[1] = 0;
  for (int i = 2; i < L; i++) {
    LogD[i] = LogD[i - 1] + log(i);
  }
  return LogD;
}


x86 assembly (clang, -O0):
<initLogD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    114c <initLogD+0x1c>
movl   $0x2,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e4 <initLogD+0xb4>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <initLogD+0x62>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initLogD>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
cmp    $0x3,%edi
mov    $0x2,%ebx
cmovge %edi,%ebx
lea    0x0(,%rbx,8),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r14)
cmp    $0x3,%r15d
jl     11ae <initLogD+0x7e>
mov    %ebx,%ebp
mov    $0x2,%ebx
xorpd  %xmm0,%xmm0
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
call   1050 <log@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <initLogD+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double* @initLogD(i32 %0) {
%2 = icmp sgt i32 %0, 2
%3 = select i1 %2, i32 %0, i32 2
%4 = shl i32 %3, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to double*
%7 = tail call i32 @memset(double* %6, i32 0, i32 %4)
%8 = inttoptr i64 %5 to i8*
br i1 %2, label %9, label %11
9: ; preds = %1
%10 = zext i32 %3 to i64
br label %12
11: ; preds = %12, %1
ret double* %6
12: ; preds = %9, %12
%13 = phi double [ 0.000000e+00, %9 ], [ %17, %12 ]
%14 = phi i64 [ 2, %9 ], [ %19, %12 ]
%15 = trunc i64 %14 to i32
%16 = tail call double @log(i32 %15)
%17 = fadd double %13, %16
%18 = getelementptr inbounds double, double* %6, i64 %14
store double %17, double* %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %11, label %12
}