#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 rq_pricing_norm_density(double);
int sqrt(double);
double rq_pricing_blackscholes_theta(int call, double S, double X, double r,
                                     double b, double v, double tv, double td) {
  double fi = (call ? 1.0 : -1.0);
  double d1 = (log(S / X) + b * td + (v * v) / 2.0 * tv) / (v * sqrt(tv));
  double d2 = d1 - v * sqrt(tv);
  double D = r - b;
  if (tv <= 0.0 || td <= 0.0)
    return 0.0;
  return -v * S * exp(-D * td) * rq_pricing_norm_density(fi * d1) /
             (2 * sqrt(tv)) +
         fi * D * S * rq_pricing_cumul_norm_dist(fi * d1) * exp(-D * td) -
         fi * r * X * rq_pricing_cumul_norm_dist(fi * d2) * exp(-r * td);
}


x86 assembly (clang, -O0):
<rq_pricing_blackscholes_theta>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%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)
movsd  %xmm6,-0x48(%rbp)
mov    -0xc(%rbp),%eax
movsd  0xe7c(%rip),%xmm0
movsd  0xe7c(%rip),%xmm1
movsd  %xmm1,-0x78(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x70(%rbp)
jne    11b1 <rq_pricing_blackscholes_theta+0x61>
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x30(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xe12(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0x98(%rbp),%xmm1
ff
movsd  -0x90(%rbp),%xmm0
ff
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x80(%rbp),%xmm1
cvtsi2sd %eax,%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jae    12c0 <rq_pricing_blackscholes_theta+0x170>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jb     12cd <rq_pricing_blackscholes_theta+0x17d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    149e <rq_pricing_blackscholes_theta+0x34e>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0xe0(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x48(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0xe0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xd8(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1070 <rq_pricing_norm_density@plt>
movaps %xmm0,%xmm1
movsd  -0xd8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xd0(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0xd0(%rbp),%xmm0
ff
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movaps %xmm0,%xmm1
movsd  -0xc8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x48(%rbp),%xmm0
call   1040 <exp@plt>
movsd  -0xc0(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0xb8(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x48(%rbp),%xmm0
call   1040 <exp@plt>
movsd  -0xa8(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0xa0(%rbp),%xmm0
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_blackscholes_theta>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
movsd  %xmm6,0x38(%rsp)
movsd  %xmm5,0x8(%rsp)
movapd %xmm4,0x10(%rsp)
movsd  %xmm3,0x40(%rsp)
movaps %xmm2,0x70(%rsp)
xor    %ebx,%ebx
test   %edi,%edi
sete   %r14b
movsd  %xmm0,0x58(%rsp)
movsd  %xmm1,0x88(%rsp)
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <sqrt@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1060 <sqrt@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm0
jae    1394 <rq_pricing_blackscholes_theta+0x244>
ucomisd 0x38(%rsp),%xmm0
jae    1394 <rq_pricing_blackscholes_theta+0x244>
movapd %xmm2,%xmm1
mov    %r14b,%bl
lea    0xe1c(%rip),%rcx
movsd  (%rcx,%rbx,8),%xmm0
movsd  %xmm0,0x28(%rsp)
movapd 0x70(%rsp),%xmm0
movsd  0x40(%rsp),%xmm5
subsd  %xmm5,%xmm0
movapd %xmm0,%xmm4
movapd %xmm0,0x60(%rsp)
movsd  0x38(%rsp),%xmm0
mulsd  %xmm0,%xmm5
movapd %xmm0,%xmm2
addsd  0x30(%rsp),%xmm5
movapd 0x10(%rsp),%xmm6
movapd %xmm6,%xmm3
mulsd  %xmm6,%xmm3
mulsd  0xded(%rip),%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm5,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm6,%xmm0
divsd  %xmm0,%xmm3
movapd %xmm3,0x40(%rsp)
xorpd  0xdb8(%rip),%xmm6
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm6,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x30(%rsp)
mulsd  0x58(%rsp),%xmm6
movapd %xmm6,0x10(%rsp)
movapd %xmm4,%xmm0
xorpd  0xd8b(%rip),%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm0,0x90(%rsp)
call   1040 <exp@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movapd 0x40(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
movapd %xmm0,0x40(%rsp)
call   1070 <rq_pricing_norm_density@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <sqrt@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movapd 0x60(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
mulsd  0x58(%rsp),%xmm0
movapd %xmm0,0x60(%rsp)
movapd 0x40(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
mulsd  0x60(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x90(%rsp),%xmm0
call   1040 <exp@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x30(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0xcb8(%rip),%xmm0
xorpd  0x70(%rsp),%xmm0
mulsd  0x38(%rsp),%xmm0
call   1040 <exp@plt>
movsd  0x28(%rsp),%xmm1
mulsd  0x70(%rsp),%xmm1
mulsd  0x88(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
jmp    1398 <rq_pricing_blackscholes_theta+0x248>
xorpd  %xmm0,%xmm0
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @rq_pricing_blackscholes_theta(i32 %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = alloca double
%10 = alloca i32
%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* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store double %7, double* %17
%22 = load i32, i32* %10
%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* %18
%26 = load double, double* %11
%27 = load double, double* %12
%28 = fdiv double %26, %27
%29 = call double @log(double %28)
%30 = load double, double* %14
%31 = load double, double* %17
%32 = call double @llvm.fmuladd.f64(double %30, double %31, double %29)
%33 = load double, double* %15
%34 = load double, double* %15
%35 = fmul double %33, %34
%36 = fdiv double %35, 2.000000e+00
%37 = load double, double* %16
%38 = call double @llvm.fmuladd.f64(double %36, double %37, double %32)
%39 = load double, double* %15
%40 = load double, double* %16
%41 = call i32 @sqrt(double %40)
%42 = sitofp i32 %41 to double
%43 = fmul double %39, %42
%44 = fdiv double %38, %43
store double %44, double* %19
%45 = load double, double* %19
%46 = load double, double* %15
%47 = load double, double* %16
%48 = call i32 @sqrt(double %47)
%49 = sitofp i32 %48 to double
%50 = fneg double %46
%51 = call double @llvm.fmuladd.f64(double %50, double %49, double %45)
store double %51, double* %20
%52 = load double, double* %13
%53 = load double, double* %14
%54 = fsub double %52, %53
store double %54, double* %21
%55 = load double, double* %16
%56 = fcmp ole double %55, 0.000000e+00
br i1 %56, label %60, label %57
57: ; preds = %8
%58 = load double, double* %17
%59 = fcmp ole double %58, 0.000000e+00
br i1 %59, label %60, label %61
60: ; preds = %57, %8
store double 0.000000e+00, double* %9
br label %115
61: ; preds = %57
%62 = load double, double* %15
%63 = fneg double %62
%64 = load double, double* %11
%65 = fmul double %63, %64
%66 = load double, double* %21
%67 = fneg double %66
%68 = load double, double* %17
%69 = fmul double %67, %68
%70 = call double @exp(double %69)
%71 = fmul double %65, %70
%72 = load double, double* %18
%73 = load double, double* %19
%74 = fmul double %72, %73
%75 = call double @rq_pricing_norm_density(double %74)
%76 = fmul double %71, %75
%77 = load double, double* %16
%78 = call i32 @sqrt(double %77)
%79 = mul nsw i32 2, %78
%80 = sitofp i32 %79 to double
%81 = fdiv double %76, %80
%82 = load double, double* %18
%83 = load double, double* %21
%84 = fmul double %82, %83
%85 = load double, double* %11
%86 = fmul double %84, %85
%87 = load double, double* %18
%88 = load double, double* %19
%89 = fmul double %87, %88
%90 = call double @rq_pricing_cumul_norm_dist(double %89)
%91 = fmul double %86, %90
%92 = load double, double* %21
%93 = fneg double %92
%94 = load double, double* %17
%95 = fmul double %93, %94
%96 = call double @exp(double %95)
%97 = call double @llvm.fmuladd.f64(double %91, double %96, double %81)
%98 = load double, double* %18
%99 = load double, double* %13
%100 = fmul double %98, %99
%101 = load double, double* %12
%102 = fmul double %100, %101
%103 = load double, double* %18
%104 = load double, double* %20
%105 = fmul double %103, %104
%106 = call double @rq_pricing_cumul_norm_dist(double %105)
%107 = fmul double %102, %106
%108 = load double, double* %13
%109 = fneg double %108
%110 = load double, double* %17
%111 = fmul double %109, %110
%112 = call double @exp(double %111)
%113 = fneg double %107
%114 = call double @llvm.fmuladd.f64(double %113, double %112, double %97)
store double %114, double* %9
br label %115
115: ; preds = %61, %60
%116 = load double, double* %9
ret double %116
}

LLVM IR (-O2):
define double @rq_pricing_blackscholes_theta(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 = fdiv double %1, %2
%12 = tail call double @log(double %11)
%13 = tail call double @llvm.fmuladd.f64(double %4, double %7, double %12)
%14 = fmul double %5, %5
%15 = fmul double %14, 5.000000e-01
%16 = tail call double @llvm.fmuladd.f64(double %15, double %6, double %13)
%17 = tail call i32 @sqrt(double %6)
%18 = sitofp i32 %17 to double
%19 = fmul double %18, %5
%20 = fdiv double %16, %19
%21 = tail call i32 @sqrt(double %6)
%22 = fneg double %5
%23 = fsub double %3, %4
%24 = fcmp ole double %6, 0.000000e+00
%25 = fcmp ole double %7, 0.000000e+00
%26 = or i1 %24, %25
br i1 %26, label %58, label %27
27: ; preds = %8
%28 = sitofp i32 %21 to double
%29 = tail call double @llvm.fmuladd.f64(double %22, double %28, double %20)
%30 = fmul double %22, %1
%31 = fneg double %23
%32 = fmul double %31, %7
%33 = tail call double @exp(double %32)
%34 = fmul double %30, %33
%35 = fmul double %10, %20
%36 = tail call double @rq_pricing_norm_density(double %35)
%37 = fmul double %34, %36
%38 = tail call i32 @sqrt(double %6)
%39 = shl nsw i32 %38, 1
%40 = sitofp i32 %39 to double
%41 = fdiv double %37, %40
%42 = fmul double %10, %23
%43 = fmul double %42, %1
%44 = tail call double @rq_pricing_cumul_norm_dist(double %35)
%45 = fmul double %43, %44
%46 = tail call double @exp(double %32)
%47 = tail call double @llvm.fmuladd.f64(double %45, double %46, double %41)
%48 = fmul double %10, %29
%49 = tail call double @rq_pricing_cumul_norm_dist(double %48)
%50 = fneg double %3
%51 = fmul double %50, %7
%52 = tail call double @exp(double %51)
%53 = fneg double %10
%54 = fmul double %53, %3
%55 = fmul double %54, %2
%56 = fmul double %55, %49
%57 = tail call double @llvm.fmuladd.f64(double %56, double %52, double %47)
br label %58
58: ; preds = %8, %27
%59 = phi double [ %57, %27 ], [ 0.000000e+00, %8 ]
ret double %59
}