#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 factorial(int);
int /*<<< orphan*/ log_trace(char *, int, int, ...);
double combination(int n, int k) {
  log_trace("f(%d)=%f", n, factorial(n));
  log_trace("f(%d)=%f", k, factorial(k));
  log_trace("f(%d-%d)=%f", n, k, factorial(n - k));
  double total = factorial(n) / factorial(k) * factorial(n - k);
  log_trace("c(%d,%d)=%f", n, k, total);
  return total;
}


x86 assembly (clang, -O0):
<combination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <factorial@plt>
mov    -0x30(%rbp),%esi
cvttsd2si %xmm0,%edx
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <log_trace@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    -0x2c(%rbp),%esi
cvttsd2si %xmm0,%edx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <log_trace@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe71(%rip),%rdi
mov    $0x1,%al
call   1040 <log_trace@plt>
mov    -0x4(%rbp),%edi
call   1030 <factorial@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1030 <factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
movsd  -0x10(%rbp),%xmm0
lea    0xe22(%rip),%rdi
mov    $0x1,%al
call   1040 <log_trace@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<combination>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebx
call   1030 <factorial@plt>
cvttsd2si %xmm0,%edx
lea    0xec4(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <log_trace@plt>
mov    %r15d,%edi
call   1030 <factorial@plt>
cvttsd2si %xmm0,%edx
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <log_trace@plt>
mov    %ebx,%ebp
sub    %r15d,%ebp
mov    %ebp,%edi
call   1030 <factorial@plt>
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    $0x1,%al
call   1040 <log_trace@plt>
mov    %ebx,%edi
call   1030 <factorial@plt>
movsd  %xmm0,(%rsp)
mov    %r15d,%edi
call   1030 <factorial@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %ebp,%edi
call   1030 <factorial@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0xe5b(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    $0x1,%al
call   1040 <log_trace@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"f(%d)=%f\00"
@.str.1 = [12 x i8] c"f(%d-%d)=%f\00"
@.str.2 = [12 x i8] c"c(%d,%d)=%f\00"
define double @combination(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* %3
%8 = call double @factorial(i32 %7)
%9 = fptosi double %8 to i32
%10 = call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
%11 = load i32, i32* %4
%12 = load i32, i32* %4
%13 = call double @factorial(i32 %12)
%14 = fptosi double %13 to i32
%15 = call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14)
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %18, %19
%21 = call double @factorial(i32 %20)
%22 = call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17, double %21)
%23 = load i32, i32* %3
%24 = call double @factorial(i32 %23)
%25 = load i32, i32* %4
%26 = call double @factorial(i32 %25)
%27 = fdiv double %24, %26
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = sub nsw i32 %28, %29
%31 = call double @factorial(i32 %30)
%32 = fmul double %27, %31
store double %32, double* %5
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = load double, double* %5
%36 = call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34, double %35)
%37 = load double, double* %5
ret double %37
}

LLVM IR (-O2):
@.str = [9 x i8] c"f(%d)=%f\00"
@.str.1 = [12 x i8] c"f(%d-%d)=%f\00"
@.str.2 = [12 x i8] c"c(%d,%d)=%f\00"
define double @combination(i32 %0, i32 %1) {
%3 = tail call double @factorial(i32 %0)
%4 = fptosi double %3 to i32
%5 = tail call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %4)
%6 = tail call double @factorial(i32 %1)
%7 = fptosi double %6 to i32
%8 = tail call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %7)
%9 = sub nsw i32 %0, %1
%10 = tail call double @factorial(i32 %9)
%11 = tail call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1, double %10)
%12 = tail call double @factorial(i32 %0)
%13 = tail call double @factorial(i32 %1)
%14 = fdiv double %12, %13
%15 = tail call double @factorial(i32 %9)
%16 = fmul double %14, %15
%17 = tail call i32 (i8*, i32, i32, ...) @log_trace(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1, double %16)
ret double %16
}