#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 log(double);
double rq_pricing_cumul_norm_dist(double);
double sqrt(double);
double rq_pricing_blackscholes(int call, double S, double X, double r_dom,
                               double r_for, double sigma, double tau_e,
                               double tau_d) {
  double m = (call ? 1.0 : -1.0);
  double f = S * exp(r_dom * tau_d) / exp(r_for * tau_d);
  double sigma_tau_sqrt = sigma * sqrt(tau_e);
  double d1 = (log(f / X) + (0.5 * sigma * sigma * tau_e)) / sigma_tau_sqrt;
  double d2 = (d1 - sigma_tau_sqrt) * m;
  d1 *= m;
  return exp(-r_dom * tau_d) * ((f * rq_pricing_cumul_norm_dist(d1) * m) +
                                (X * rq_pricing_cumul_norm_dist(d2) * -m));
}


x86 assembly (clang, -O0):
<rq_pricing_blackscholes>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  %xmm5,-0x38(%rbp)
movsd  %xmm6,-0x40(%rbp)
mov    -0x4(%rbp),%eax
movsd  0xe8c(%rip),%xmm0
movsd  0xe8c(%rip),%xmm1
movsd  %xmm1,-0x78(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x70(%rbp)
jne    11a1 <rq_pricing_blackscholes+0x61>
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0xb8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdba(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  -0x98(%rbp),%xmm2
ff
movsd  -0x90(%rbp),%xmm1
ff
movsd  -0x88(%rbp),%xmm3
ff
movaps %xmm0,%xmm4
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm4,%xmm2
movsd  -0x48(%rbp),%xmm4
movq   %xmm4,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm4
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_blackscholes>:
sub    $0x58,%rsp
movsd  %xmm6,0x20(%rsp)
movsd  %xmm5,0x8(%rsp)
movsd  %xmm4,0x10(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm1,0x30(%rsp)
movsd  %xmm0,(%rsp)
xor    %eax,%eax
test   %edi,%edi
sete   %al
lea    0xe8b(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,0x28(%rsp)
movapd %xmm2,0x40(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm6,%xmm0
call   1040 <exp@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
call   1040 <exp@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     11d8 <rq_pricing_blackscholes+0x98>
movsd  0x8(%rsp),%xmm0
sqrtsd %xmm0,%xmm0
jmp    11e3 <rq_pricing_blackscholes+0xa3>
movsd  0x8(%rsp),%xmm0
call   1060 <sqrt@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
divsd  0x30(%rsp),%xmm0
call   1050 <log@plt>
movsd  0xe19(%rip),%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm2
divsd  %xmm2,%xmm0
movsd  0x28(%rsp),%xmm1
movapd %xmm1,%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,0x38(%rsp)
subsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movapd 0x40(%rsp),%xmm0
xorpd  0xdb7(%rip),%xmm0
mulsd  0x20(%rsp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x38(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
mulsd  0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  (%rsp),%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm0,%xmm2
mulsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
define double @rq_pricing_blackscholes(i32 %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = alloca i32
%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
%19 = alloca double
%20 = alloca double
%21 = alloca double
store i32 %0, i32* %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store double %4, double* %13
store double %5, double* %14
store double %6, double* %15
store double %7, double* %16
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, double 1.000000e+00, double -1.000000e+00
store double %25, double* %17
%26 = load double, double* %10
%27 = load double, double* %12
%28 = load double, double* %16
%29 = fmul double %27, %28
%30 = call double @exp(double %29)
%31 = fmul double %26, %30
%32 = load double, double* %13
%33 = load double, double* %16
%34 = fmul double %32, %33
%35 = call double @exp(double %34)
%36 = fdiv double %31, %35
store double %36, double* %18
%37 = load double, double* %14
%38 = load double, double* %15
%39 = call double @sqrt(double %38)
%40 = fmul double %37, %39
store double %40, double* %19
%41 = load double, double* %18
%42 = load double, double* %11
%43 = fdiv double %41, %42
%44 = call double @log(double %43)
%45 = load double, double* %14
%46 = fmul double 5.000000e-01, %45
%47 = load double, double* %14
%48 = fmul double %46, %47
%49 = load double, double* %15
%50 = call double @llvm.fmuladd.f64(double %48, double %49, double %44)
%51 = load double, double* %19
%52 = fdiv double %50, %51
store double %52, double* %20
%53 = load double, double* %20
%54 = load double, double* %19
%55 = fsub double %53, %54
%56 = load double, double* %17
%57 = fmul double %55, %56
store double %57, double* %21
%58 = load double, double* %17
%59 = load double, double* %20
%60 = fmul double %59, %58
store double %60, double* %20
%61 = load double, double* %12
%62 = fneg double %61
%63 = load double, double* %16
%64 = fmul double %62, %63
%65 = call double @exp(double %64)
%66 = load double, double* %18
%67 = load double, double* %20
%68 = call double @rq_pricing_cumul_norm_dist(double %67)
%69 = fmul double %66, %68
%70 = load double, double* %17
%71 = load double, double* %11
%72 = load double, double* %21
%73 = call double @rq_pricing_cumul_norm_dist(double %72)
%74 = fmul double %71, %73
%75 = load double, double* %17
%76 = fneg double %75
%77 = fmul double %74, %76
%78 = call double @llvm.fmuladd.f64(double %69, double %70, double %77)
%79 = fmul double %65, %78
ret double %79
}

LLVM IR (-O2):
define double @rq_pricing_blackscholes(i32 %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = icmp eq i32 %0, 0
%10 = select i1 %9, double -1.000000e+00, double 1.000000e+00
%11 = fmul double %3, %7
%12 = tail call double @exp(double %11)
%13 = fmul double %12, %1
%14 = fmul double %4, %7
%15 = tail call double @exp(double %14)
%16 = fdiv double %13, %15
%17 = tail call double @sqrt(double %6)
%18 = fmul double %17, %5
%19 = fdiv double %16, %2
%20 = tail call double @log(double %19)
%21 = fmul double %5, 5.000000e-01
%22 = fmul double %21, %5
%23 = tail call double @llvm.fmuladd.f64(double %22, double %6, double %20)
%24 = fdiv double %23, %18
%25 = fsub double %24, %18
%26 = fmul double %10, %25
%27 = fmul double %10, %24
%28 = fneg double %3
%29 = fmul double %28, %7
%30 = tail call double @exp(double %29)
%31 = tail call double @rq_pricing_cumul_norm_dist(double %27)
%32 = fmul double %16, %31
%33 = tail call double @rq_pricing_cumul_norm_dist(double %26)
%34 = fmul double %33, %2
%35 = fneg double %10
%36 = fmul double %34, %35
%37 = tail call double @llvm.fmuladd.f64(double %32, double %10, double %36)
%38 = fmul double %30, %37
ret double %38
}