#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__ calloc(int, int);
double log(int);
double *init_logarithm_array(int nmax) {
  double *factorial_logarithms = (double *)calloc(nmax, sizeof(double));
  factorial_logarithms[0] = 0;
  factorial_logarithms[1] = 0;
  for (int i = 2; i < nmax; i++) {
    factorial_logarithms[i] = factorial_logarithms[i - 1] + log(i);
  }
  return factorial_logarithms;
}


x86 assembly (clang, -O0):
<init_logarithm_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
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    11ac <init_logarithm_array+0x8c>
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   1040 <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    115a <init_logarithm_array+0x3a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_logarithm_array>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
xorpd  %xmm0,%xmm0
movupd %xmm0,(%rax)
cmp    $0x3,%ebx
jl     1192 <init_logarithm_array+0x72>
mov    %ebx,%r15d
mov    $0x2,%ebx
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1040 <log@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <init_logarithm_array+0x40>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @init_logarithm_array(i32 %0) {
%2 = alloca i32
%3 = alloca double*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @calloc(i32 %5, i32 8)
%7 = inttoptr i64 %6 to double*
store double* %7, double** %3
%8 = load double*, double** %3
%9 = getelementptr inbounds double, double* %8, i64 0
store double 0.000000e+00, double* %9
%10 = load double*, double** %3
%11 = getelementptr inbounds double, double* %10, i64 1
store double 0.000000e+00, double* %11
store i32 2, i32* %4
br label %12
12: ; preds = %30, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load double*, double** %3
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %17, i64 %20
%22 = load double, double* %21
%23 = load i32, i32* %4
%24 = call double @log(i32 %23)
%25 = fadd double %22, %24
%26 = load double*, double** %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
br label %30
30: ; preds = %16
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %12
33: ; preds = %12
%34 = load double*, double** %3
ret double* %34
}

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