#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 lgamma(double);
double log_factorial(unsigned int);
double log_combination_k_r(unsigned int k, double r) {
  if (!k)
    return 0;
  double val = lgamma(k + r) - lgamma(r) - log_factorial(k);
  return val;
}


x86 assembly (clang, -O0):
<log_combination_k_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1147 <log_combination_k_r+0x27>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119c <log_combination_k_r+0x7c>
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
call   1040 <lgamma@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <lgamma@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <log_factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_combination_k_r>:
test   %edi,%edi
je     1180 <log_combination_k_r+0x60>
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm1
mov    %edi,%ebx
mov    %edi,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1040 <lgamma@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <lgamma@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %ebx,%edi
call   1030 <log_factorial@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @log_combination_k_r(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store double 0.000000e+00, double* %3
br label %23
10: ; preds = %2
%11 = load i32, i32* %4
%12 = uitofp i32 %11 to double
%13 = load double, double* %5
%14 = fadd double %12, %13
%15 = call double @lgamma(double %14)
%16 = load double, double* %5
%17 = call double @lgamma(double %16)
%18 = fsub double %15, %17
%19 = load i32, i32* %4
%20 = call double @log_factorial(i32 %19)
%21 = fsub double %18, %20
store double %21, double* %6
%22 = load double, double* %6
store double %22, double* %3
br label %23
23: ; preds = %10, %9
%24 = load double, double* %3
ret double %24
}

LLVM IR (-O2):
define double @log_combination_k_r(i32 %0, double %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = uitofp i32 %0 to double
%6 = fadd double %5, %1
%7 = tail call double @lgamma(double %6)
%8 = tail call double @lgamma(double %1)
%9 = fsub double %7, %8
%10 = tail call double @log_factorial(i32 %0)
%11 = fsub double %9, %10
br label %12
12: ; preds = %2, %4
%13 = phi double [ %11, %4 ], [ 0.000000e+00, %2 ]
ret double %13
}