#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 max(double, double);
double rq_pricing_cumul_norm_dist(double);
double sqrt(double);
double rq_pricing_blackscholes_gen(int call, double S, double X, double tau,
                                   double r, double b, double sigma) {
  double sigma_tau_sqrt, d1, d2;
  double m = call ? 1.0 : -1.0;
  if (tau <= 0.0)
    return max((S - X) * m, 0.0);
  sigma_tau_sqrt = sigma * sqrt(tau);
  d1 = (log(S / X) + (b + 0.5 * sigma * sigma) * tau) / sigma_tau_sqrt;
  d2 = d1 - sigma_tau_sqrt;
  return (m * S * exp((b - r) * tau) * rq_pricing_cumul_norm_dist(d1 * m) -
          m * X * exp(-r * tau) * rq_pricing_cumul_norm_dist(d2 * m));
}


x86 assembly (clang, -O0):
<rq_pricing_blackscholes_gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  %xmm4,-0x38(%rbp)
movsd  %xmm5,-0x40(%rbp)
mov    -0xc(%rbp),%eax
movsd  0xe79(%rip),%xmm0
movsd  0xe79(%rip),%xmm1
movsd  %xmm1,-0x70(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x68(%rbp)
jne    11ac <rq_pricing_blackscholes_gen+0x5c>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11e5 <rq_pricing_blackscholes_gen+0x95>
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   1040 <max@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1350 <rq_pricing_blackscholes_gen+0x200>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  0xde1(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  -0x88(%rbp),%xmm1
ff
movsd  -0x80(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_blackscholes_gen>:
sub    $0x58,%rsp
movapd %xmm0,%xmm7
xor    %eax,%eax
test   %edi,%edi
sete   %al
lea    0xe9a(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
xorpd  %xmm6,%xmm6
ucomisd %xmm2,%xmm6
jae    11ac <rq_pricing_blackscholes_gen+0x5c>
movsd  %xmm4,0x18(%rsp)
movaps %xmm3,0x30(%rsp)
movsd  %xmm0,0x10(%rsp)
ucomisd %xmm6,%xmm2
movsd  %xmm1,0x20(%rsp)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm7,(%rsp)
movsd  %xmm5,0x8(%rsp)
jb     11c1 <rq_pricing_blackscholes_gen+0x71>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    11db <rq_pricing_blackscholes_gen+0x8b>
subsd  %xmm1,%xmm7
mulsd  %xmm7,%xmm0
xorpd  %xmm1,%xmm1
add    $0x58,%rsp
jmp    1040 <max@plt>
movapd %xmm2,%xmm0
call   1070 <sqrt@plt>
movsd  0x8(%rsp),%xmm5
movsd  (%rsp),%xmm7
movsd  0x20(%rsp),%xmm1
mulsd  %xmm5,%xmm0
movsd  %xmm0,0x50(%rsp)
divsd  %xmm1,%xmm7
movapd %xmm7,%xmm0
call   1060 <log@plt>
movapd %xmm0,%xmm2
movsd  0xe22(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
addsd  %xmm0,%xmm1
movsd  0x28(%rsp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm1,%xmm2
movsd  0x50(%rsp),%xmm4
divsd  %xmm4,%xmm2
movsd  %xmm2,0x48(%rsp)
subsd  %xmm4,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  (%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  %xmm1,(%rsp)
subsd  0x30(%rsp),%xmm0
mulsd  %xmm3,%xmm0
call   1050 <exp@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x48(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  %xmm0,0x18(%rsp)
movapd 0x30(%rsp),%xmm0
xorpd  0xd84(%rip),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
mulsd  0x30(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x58,%rsp
ret

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

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