#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 const, int);
double lgamma(int);
double *logbinomial_table(const int n_size) {
  int k, n;
  double *logbinom = (double *)calloc(n_size * n_size, sizeof(double));
  for (n = 1; n < n_size; ++n) {
    double lfn = lgamma(n + 1);
    for (k = 1; k <= n; ++k)
      logbinom[n << 8 | k] = lfn - lgamma(k + 1) - lgamma(n - k + 1);
  }
  return logbinom;
}


x86 assembly (clang, -O0):
<logbinomial_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
imul   -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ec <logbinomial_table+0xcc>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1040 <lgamma@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d9 <logbinomial_table+0xb9>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1040 <lgamma@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%edi
sub    -0x8(%rbp),%edi
add    $0x1,%edi
call   1040 <lgamma@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x8,%ecx
or     -0x8(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116a <logbinomial_table+0x4a>
jmp    11de <logbinomial_table+0xbe>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1147 <logbinomial_table+0x27>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logbinomial_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
imul   %edi,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
mov    %ebx,(%rsp)
cmp    $0x2,%ebx
jl     11d1 <logbinomial_table+0xb1>
mov    $0x1,%eax
mov    $0x2,%r13d
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebp
lea    0x1(%rbp),%edi
mov    %edi,0x4(%rsp)
call   1040 <lgamma@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%r14d
shl    $0x8,%r14d
mov    $0x2,%ebx
lea    -0x1(%rbx),%r15d
or     %r14d,%r15d
mov    %ebx,%edi
call   1040 <lgamma@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %ebp,%edi
call   1040 <lgamma@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movslq %r15d,%rax
movsd  %xmm1,(%r12,%rax,8)
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    1180 <logbinomial_table+0x60>
lea    0x1(%r13),%eax
cmp    (%rsp),%r13d
mov    %eax,%r13d
mov    0x4(%rsp),%eax
jne    1160 <logbinomial_table+0x40>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double* @logbinomial_table(i32 %0) {
%2 = mul nsw i32 %0, %0
%3 = tail call i64 @calloc(i32 %2, i32 8)
%4 = inttoptr i64 %3 to double*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %9, label %27
6: ; preds = %15
%7 = add nuw i32 %10, 1
%8 = icmp eq i32 %10, %0
br i1 %8, label %27, label %9
9: ; preds = %1, %6
%10 = phi i32 [ %7, %6 ], [ 2, %1 ]
%11 = phi i32 [ %12, %6 ], [ 1, %1 ]
%12 = add nuw nsw i32 %11, 1
%13 = tail call double @lgamma(i32 %12)
%14 = shl i32 %11, 8
br label %15
15: ; preds = %9, %15
%16 = phi i32 [ 1, %9 ], [ %17, %15 ]
%17 = add nuw nsw i32 %16, 1
%18 = tail call double @lgamma(i32 %17)
%19 = fsub double %13, %18
%20 = sub nsw i32 %12, %16
%21 = tail call double @lgamma(i32 %20)
%22 = fsub double %19, %21
%23 = or i32 %16, %14
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %4, i64 %24
store double %22, double* %25
%26 = icmp eq i32 %17, %10
br i1 %26, label %6, label %15
27: ; preds = %6, %1
ret double* %4
}