#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 exp(double);
double sqrt(double);
binomial_option(double StockPrice, double OptionStrike, double TimePeriod,
                double vol, double risk, double *CallResult) {
  double T1 = vol * sqrt(TimePeriod);
  double T2 = risk * TimePeriod;
  double T3 = (exp(T2) - 1 / exp(T1)) / (exp(T1) - 1 / exp(T1));
  double T4 = 1 - T3;
  double T5 = StockPrice * exp(T1) - OptionStrike;
  *CallResult = (T3 * T5 - T4 * T5) / exp(T2);
}


x86 assembly (clang, -O0):
<binomial_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
mov    %rdi,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0x88(%rbp),%xmm0
ff
movsd  0xe4f(%rip),%xmm1
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
movsd  -0x80(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x78(%rbp),%xmm0
movsd  0xe14(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdfb(%rip),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binomial_option>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jb     1147 <binomial_option+0x27>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    1172 <binomial_option+0x52>
movapd %xmm2,%xmm0
movsd  %xmm2,0x18(%rsp)
movsd  %xmm4,(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movsd  (%rsp),%xmm4
movsd  0x18(%rsp),%xmm2
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm4,%xmm2
movsd  %xmm2,0x18(%rsp)
movapd %xmm2,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <exp@plt>
movsd  0xe59(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <exp@plt>
movsd  0xe23(%rip),%xmm2
movapd %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm3
subsd  %xmm1,%xmm3
movsd  (%rsp),%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,(%rsp)
subsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <exp@plt>
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
subsd  0x28(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <exp@plt>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @binomial_option(double %0, double %1, double %2, double %3, double %4, double* %5) {
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double*
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double* %5, double** %13
%19 = load double, double* %11
%20 = load double, double* %10
%21 = call double @sqrt(double %20)
%22 = fmul double %19, %21
store double %22, double* %14
%23 = load double, double* %12
%24 = load double, double* %10
%25 = fmul double %23, %24
store double %25, double* %15
%26 = load double, double* %15
%27 = call double @exp(double %26)
%28 = load double, double* %14
%29 = call double @exp(double %28)
%30 = fdiv double 1.000000e+00, %29
%31 = fsub double %27, %30
%32 = load double, double* %14
%33 = call double @exp(double %32)
%34 = load double, double* %14
%35 = call double @exp(double %34)
%36 = fdiv double 1.000000e+00, %35
%37 = fsub double %33, %36
%38 = fdiv double %31, %37
store double %38, double* %16
%39 = load double, double* %16
%40 = fsub double 1.000000e+00, %39
store double %40, double* %17
%41 = load double, double* %8
%42 = load double, double* %14
%43 = call double @exp(double %42)
%44 = load double, double* %9
%45 = fneg double %44
%46 = call double @llvm.fmuladd.f64(double %41, double %43, double %45)
store double %46, double* %18
%47 = load double, double* %16
%48 = load double, double* %18
%49 = load double, double* %17
%50 = load double, double* %18
%51 = fmul double %49, %50
%52 = fneg double %51
%53 = call double @llvm.fmuladd.f64(double %47, double %48, double %52)
%54 = load double, double* %15
%55 = call double @exp(double %54)
%56 = fdiv double %53, %55
%57 = load double*, double** %13
store double %56, double* %57
%58 = load i32, i32* %7
ret i32 %58
}

LLVM IR (-O2):
define i32 @binomial_option(double %0, double %1, double %2, double %3, double %4, double* nocapture writeonly %5) {
%7 = tail call double @sqrt(double %2)
%8 = fmul double %7, %3
%9 = fmul double %2, %4
%10 = tail call double @exp(double %9)
%11 = tail call double @exp(double %8)
%12 = fdiv double 1.000000e+00, %11
%13 = fsub double %10, %12
%14 = tail call double @exp(double %8)
%15 = tail call double @exp(double %8)
%16 = fdiv double 1.000000e+00, %15
%17 = fsub double %14, %16
%18 = fdiv double %13, %17
%19 = fsub double 1.000000e+00, %18
%20 = tail call double @exp(double %8)
%21 = fneg double %1
%22 = tail call double @llvm.fmuladd.f64(double %0, double %20, double %21)
%23 = fneg double %19
%24 = fmul double %22, %23
%25 = tail call double @llvm.fmuladd.f64(double %18, double %22, double %24)
%26 = tail call double @exp(double %9)
%27 = fdiv double %25, %26
store double %27, double* %5
ret i32 undef
}