#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_norm_density(double);
double sqrt(double);
double rq_pricing_blackscholes_gamma(double S, double X, double r, double b,
                                     double v, double tv, double td) {
  double D = r - b;
  double norm_density;
  if (tv <= 0.0 || td <= 0.0)
    return 0.0;
  norm_density = rq_pricing_norm_density(
      (log(S / X) + (b * td) + (((v * v) / 2.0) * tv)) / (v * sqrt(tv)));
  return exp(-D * td) * norm_density / (S * v * sqrt(tv));
}


x86 assembly (clang, -O0):
<rq_pricing_blackscholes_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
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)
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jae    1196 <rq_pricing_blackscholes_gamma+0x56>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     11a3 <rq_pricing_blackscholes_gamma+0x63>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1282 <rq_pricing_blackscholes_gamma+0x142>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x28(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1060 <rq_pricing_norm_density@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_blackscholes_gamma>:
sub    $0x48,%rsp
movsd  %xmm4,(%rsp)
xorpd  %xmm4,%xmm4
ucomisd %xmm5,%xmm4
jae    1278 <rq_pricing_blackscholes_gamma+0x138>
xorpd  %xmm7,%xmm7
ucomisd %xmm6,%xmm7
jae    1278 <rq_pricing_blackscholes_gamma+0x138>
subsd  %xmm3,%xmm2
movapd %xmm2,0x30(%rsp)
movsd  %xmm0,0x18(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm5,0x20(%rsp)
movsd  %xmm6,0x28(%rsp)
movsd  %xmm3,0x10(%rsp)
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
mulsd  0xe4b(%rip),%xmm1
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
ucomisd 0xe36(%rip),%xmm2
movsd  %xmm0,0x10(%rsp)
jae    11f1 <rq_pricing_blackscholes_gamma+0xb1>
movsd  0x20(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  (%rsp),%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1060 <rq_pricing_norm_density@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x30(%rsp),%xmm0
xorpd  0xdf9(%rip),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <exp@plt>
movapd %xmm0,%xmm4
mulsd  0x8(%rsp),%xmm4
movsd  0x18(%rsp),%xmm1
mulsd  (%rsp),%xmm1
xorpd  %xmm0,%xmm0
movsd  0x20(%rsp),%xmm2
ucomisd %xmm0,%xmm2
movapd %xmm2,%xmm0
movsd  0x10(%rsp),%xmm2
jae    1270 <rq_pricing_blackscholes_gamma+0x130>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm4,(%rsp)
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm4
movsd  0x18(%rsp),%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm4
movapd %xmm4,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @rq_pricing_blackscholes_gamma(double %0, double %1, double %2, double %3, double %4, double %5, double %6) {
%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
store double %0, double* %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
%18 = load double, double* %11
%19 = load double, double* %12
%20 = fsub double %18, %19
store double %20, double* %16
%21 = load double, double* %14
%22 = fcmp ole double %21, 0.000000e+00
br i1 %22, label %26, label %23
23: ; preds = %7
%24 = load double, double* %15
%25 = fcmp ole double %24, 0.000000e+00
br i1 %25, label %26, label %27
26: ; preds = %23, %7
store double 0.000000e+00, double* %8
br label %61
27: ; preds = %23
%28 = load double, double* %9
%29 = load double, double* %10
%30 = fdiv double %28, %29
%31 = call double @log(double %30)
%32 = load double, double* %12
%33 = load double, double* %15
%34 = call double @llvm.fmuladd.f64(double %32, double %33, double %31)
%35 = load double, double* %13
%36 = load double, double* %13
%37 = fmul double %35, %36
%38 = fdiv double %37, 2.000000e+00
%39 = load double, double* %14
%40 = call double @llvm.fmuladd.f64(double %38, double %39, double %34)
%41 = load double, double* %13
%42 = load double, double* %14
%43 = call double @sqrt(double %42)
%44 = fmul double %41, %43
%45 = fdiv double %40, %44
%46 = call double @rq_pricing_norm_density(double %45)
store double %46, double* %17
%47 = load double, double* %16
%48 = fneg double %47
%49 = load double, double* %15
%50 = fmul double %48, %49
%51 = call double @exp(double %50)
%52 = load double, double* %17
%53 = fmul double %51, %52
%54 = load double, double* %9
%55 = load double, double* %13
%56 = fmul double %54, %55
%57 = load double, double* %14
%58 = call double @sqrt(double %57)
%59 = fmul double %56, %58
%60 = fdiv double %53, %59
store double %60, double* %8
br label %61
61: ; preds = %27, %26
%62 = load double, double* %8
ret double %62
}

LLVM IR (-O2):
define double @rq_pricing_blackscholes_gamma(double %0, double %1, double %2, double %3, double %4, double %5, double %6) {
%8 = fcmp ole double %5, 0.000000e+00
%9 = fcmp ole double %6, 0.000000e+00
%10 = or i1 %8, %9
br i1 %10, label %31, label %11
11: ; preds = %7
%12 = fsub double %2, %3
%13 = fdiv double %0, %1
%14 = tail call double @log(double %13)
%15 = tail call double @llvm.fmuladd.f64(double %3, double %6, double %14)
%16 = fmul double %4, %4
%17 = fmul double %16, 5.000000e-01
%18 = tail call double @llvm.fmuladd.f64(double %17, double %5, double %15)
%19 = tail call double @sqrt(double %5)
%20 = fmul double %19, %4
%21 = fdiv double %18, %20
%22 = tail call double @rq_pricing_norm_density(double %21)
%23 = fneg double %12
%24 = fmul double %23, %6
%25 = tail call double @exp(double %24)
%26 = fmul double %22, %25
%27 = fmul double %0, %4
%28 = tail call double @sqrt(double %5)
%29 = fmul double %27, %28
%30 = fdiv double %26, %29
br label %31
31: ; preds = %7, %11
%32 = phi double [ %30, %11 ], [ 0.000000e+00, %7 ]
ret double %32
}