#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_blackscholes_gen(short, double, double, double, double,
                                   double, double);
double sqrt(double);
double rq_pricing_average_rate_turnbullwakeman(short call, double S, double SA,
                                               double X, double r, double rf,
                                               double v, double T, double T2,
                                               double T_period) {
  double v_sqr = v * v;
  double b = r - rf;
  double two_b_plus_v_sqr = 2.0 * b + v_sqr;
  double T_minus_tau = T - T_period;
  double m1 = (exp(b * T) - exp(b * T_period)) / (b * T_minus_tau);
  double m2 =
      2.0 * exp(two_b_plus_v_sqr * T) /
          ((b + v_sqr) * two_b_plus_v_sqr * (T_minus_tau * T_minus_tau)) +
      2.0 * exp(two_b_plus_v_sqr * T_period) / (b * T_minus_tau * T_minus_tau) *
          (1 / two_b_plus_v_sqr - exp(b * T_minus_tau) / (b + v_sqr));
  double bA = log(m1) / T;
  double vA = sqrt(log(m2) / T - 2 * bA);
  double t1 = T - T2;
  double ret = 0.0;
  if (t1 > 0) {
    X = T / T2 * X - t1 / T2 * SA;
    ret = rq_pricing_blackscholes_gen(call, S, X, T2, r, bA, vA) * T2 / T;
  } else
    ret = rq_pricing_blackscholes_gen(call, S, X, T2, r, bA, vA);
  return ret;
}


x86 assembly (clang, -O0):
<rq_pricing_average_rate_turnbullwakeman>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %di,%ax
movsd  0x10(%rbp),%xmm8
mov    %ax,-0x2(%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)
movsd  %xmm7,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  0x10(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
mulsd  0x10(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0xb8(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  -0x58(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xde2(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x58(%rbp),%xmm1
addsd  -0x50(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
mulsd  -0x68(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
mulsd  0x10(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xd9b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x58(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  0xd6c(%rip),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
call   1030 <exp@plt>
movsd  -0xb0(%rbp),%xmm2
ff
movsd  -0xa8(%rbp),%xmm1
ff
movaps %xmm0,%xmm3
movsd  -0xa0(%rbp),%xmm0
ff
movsd  -0x58(%rbp),%xmm4
addsd  -0x50(%rbp),%xmm4
divsd  %xmm4,%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
call   1050 <log@plt>
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x78(%rbp),%xmm0
call   1050 <log@plt>
divsd  -0x40(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    13e2 <rq_pricing_average_rate_turnbullwakeman+0x2a2>
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x90(%rbp),%xmm1
ff
divsd  -0x48(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2(%rbp),%ax
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
movsd  -0x80(%rbp),%xmm4
movsd  -0x88(%rbp),%xmm5
ff
movswl %ax,%edi
call   1040 <rq_pricing_blackscholes_gen@plt>
mulsd  -0x48(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
jmp    1417 <rq_pricing_average_rate_turnbullwakeman+0x2d7>
mov    -0x2(%rbp),%ax
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
movsd  -0x80(%rbp),%xmm4
movsd  -0x88(%rbp),%xmm5
ff
movswl %ax,%edi
call   1040 <rq_pricing_blackscholes_gen@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_average_rate_turnbullwakeman>:
push   %rbx
sub    $0x70,%rsp
movsd  %xmm7,0x58(%rsp)
movsd  %xmm2,0x40(%rsp)
movsd  %xmm1,0x60(%rsp)
movsd  %xmm0,0x48(%rsp)
mov    %edi,%ebx
movsd  0x80(%rsp),%xmm1
movsd  %xmm1,0x20(%rsp)
mulsd  %xmm5,%xmm5
movsd  %xmm5,0x28(%rsp)
movsd  %xmm3,0x50(%rsp)
subsd  %xmm4,%xmm3
movsd  %xmm3,0x8(%rsp)
movapd %xmm3,%xmm0
addsd  %xmm3,%xmm0
addsd  %xmm5,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  %xmm6,0x18(%rsp)
movapd %xmm6,%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm6,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
call   1030 <exp@plt>
movsd  0x38(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x68(%rsp)
divsd  %xmm0,%xmm1
movsd  %xmm1,0x38(%rsp)
movsd  0x30(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
call   1030 <exp@plt>
addsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm3
addsd  0x28(%rsp),%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  0x30(%rsp),%xmm2
mulsd  %xmm2,%xmm3
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm3,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x20(%rsp),%xmm0
mulsd  %xmm2,%xmm0
call   1030 <exp@plt>
movapd %xmm0,%xmm2
addsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm1
movsd  0x68(%rsp),%xmm0
mulsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movsd  %xmm2,0x20(%rsp)
movsd  0xd86(%rip),%xmm1
divsd  0x30(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
call   1030 <exp@plt>
divsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x20(%rsp),%xmm1
addsd  0x28(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x38(%rsp),%xmm0
call   1050 <log@plt>
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <log@plt>
movsd  0x18(%rsp),%xmm6
divsd  %xmm6,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12f7 <rq_pricing_average_rate_turnbullwakeman+0x1b7>
sqrtsd %xmm0,%xmm5
jmp    130a <rq_pricing_average_rate_turnbullwakeman+0x1ca>
call   1060 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  0x18(%rsp),%xmm6
movapd %xmm0,%xmm5
movapd %xmm6,%xmm0
movsd  0x58(%rsp),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1366 <rq_pricing_average_rate_turnbullwakeman+0x226>
movapd %xmm6,%xmm1
divsd  %xmm2,%xmm1
divsd  %xmm2,%xmm0
mulsd  0x60(%rsp),%xmm0
mulsd  0x40(%rsp),%xmm1
subsd  %xmm0,%xmm1
movswl %bx,%edi
movsd  0x48(%rsp),%xmm0
movsd  0x50(%rsp),%xmm3
movsd  0x8(%rsp),%xmm4
call   1040 <rq_pricing_blackscholes_gen@plt>
mulsd  0x58(%rsp),%xmm0
divsd  0x18(%rsp),%xmm0
add    $0x70,%rsp
pop    %rbx
ret
movswl %bx,%edi
movsd  0x48(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
movsd  0x50(%rsp),%xmm3
movsd  0x8(%rsp),%xmm4
add    $0x70,%rsp
pop    %rbx
jmp    1040 <rq_pricing_blackscholes_gen@plt>

LLVM IR (-O0):
define double @rq_pricing_average_rate_turnbullwakeman(i16 signext %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8, double %9) {
%11 = alloca i16
%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
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double
%28 = alloca double
%29 = alloca double
%30 = alloca double
store i16 %0, i16* %11
store double %1, double* %12
store double %2, double* %13
store double %3, double* %14
store double %4, double* %15
store double %5, double* %16
store double %6, double* %17
store double %7, double* %18
store double %8, double* %19
store double %9, double* %20
%31 = load double, double* %17
%32 = load double, double* %17
%33 = fmul double %31, %32
store double %33, double* %21
%34 = load double, double* %15
%35 = load double, double* %16
%36 = fsub double %34, %35
store double %36, double* %22
%37 = load double, double* %22
%38 = load double, double* %21
%39 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %37, double %38)
store double %39, double* %23
%40 = load double, double* %18
%41 = load double, double* %20
%42 = fsub double %40, %41
store double %42, double* %24
%43 = load double, double* %22
%44 = load double, double* %18
%45 = fmul double %43, %44
%46 = call double @exp(double %45)
%47 = load double, double* %22
%48 = load double, double* %20
%49 = fmul double %47, %48
%50 = call double @exp(double %49)
%51 = fsub double %46, %50
%52 = load double, double* %22
%53 = load double, double* %24
%54 = fmul double %52, %53
%55 = fdiv double %51, %54
store double %55, double* %25
%56 = load double, double* %23
%57 = load double, double* %18
%58 = fmul double %56, %57
%59 = call double @exp(double %58)
%60 = fmul double 2.000000e+00, %59
%61 = load double, double* %22
%62 = load double, double* %21
%63 = fadd double %61, %62
%64 = load double, double* %23
%65 = fmul double %63, %64
%66 = load double, double* %24
%67 = load double, double* %24
%68 = fmul double %66, %67
%69 = fmul double %65, %68
%70 = fdiv double %60, %69
%71 = load double, double* %23
%72 = load double, double* %20
%73 = fmul double %71, %72
%74 = call double @exp(double %73)
%75 = fmul double 2.000000e+00, %74
%76 = load double, double* %22
%77 = load double, double* %24
%78 = fmul double %76, %77
%79 = load double, double* %24
%80 = fmul double %78, %79
%81 = fdiv double %75, %80
%82 = load double, double* %23
%83 = fdiv double 1.000000e+00, %82
%84 = load double, double* %22
%85 = load double, double* %24
%86 = fmul double %84, %85
%87 = call double @exp(double %86)
%88 = load double, double* %22
%89 = load double, double* %21
%90 = fadd double %88, %89
%91 = fdiv double %87, %90
%92 = fsub double %83, %91
%93 = call double @llvm.fmuladd.f64(double %81, double %92, double %70)
store double %93, double* %26
%94 = load double, double* %25
%95 = call double @log(double %94)
%96 = load double, double* %18
%97 = fdiv double %95, %96
store double %97, double* %27
%98 = load double, double* %26
%99 = call double @log(double %98)
%100 = load double, double* %18
%101 = fdiv double %99, %100
%102 = load double, double* %27
%103 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %102, double %101)
%104 = call double @sqrt(double %103)
store double %104, double* %28
%105 = load double, double* %18
%106 = load double, double* %19
%107 = fsub double %105, %106
store double %107, double* %29
store double 0.000000e+00, double* %30
%108 = load double, double* %29
%109 = fcmp ogt double %108, 0.000000e+00
br i1 %109, label %110, label %134
110: ; preds = %10
%111 = load double, double* %18
%112 = load double, double* %19
%113 = fdiv double %111, %112
%114 = load double, double* %14
%115 = load double, double* %29
%116 = load double, double* %19
%117 = fdiv double %115, %116
%118 = load double, double* %13
%119 = fmul double %117, %118
%120 = fneg double %119
%121 = call double @llvm.fmuladd.f64(double %113, double %114, double %120)
store double %121, double* %14
%122 = load i16, i16* %11
%123 = load double, double* %12
%124 = load double, double* %14
%125 = load double, double* %19
%126 = load double, double* %15
%127 = load double, double* %27
%128 = load double, double* %28
%129 = call double @rq_pricing_blackscholes_gen(i16 signext %122, double %123, double %124, double %125, double %126, double %127, double %128)
%130 = load double, double* %19
%131 = fmul double %129, %130
%132 = load double, double* %18
%133 = fdiv double %131, %132
store double %133, double* %30
br label %143
134: ; preds = %10
%135 = load i16, i16* %11
%136 = load double, double* %12
%137 = load double, double* %14
%138 = load double, double* %19
%139 = load double, double* %15
%140 = load double, double* %27
%141 = load double, double* %28
%142 = call double @rq_pricing_blackscholes_gen(i16 signext %135, double %136, double %137, double %138, double %139, double %140, double %141)
store double %142, double* %30
br label %143
143: ; preds = %134, %110
%144 = load double, double* %30
ret double %144
}

LLVM IR (-O2):
define double @rq_pricing_average_rate_turnbullwakeman(i16 signext %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8, double %9) {
%11 = fmul double %6, %6
%12 = fsub double %4, %5
%13 = tail call double @llvm.fmuladd.f64(double %12, double 2.000000e+00, double %11)
%14 = fsub double %7, %9
%15 = fmul double %12, %7
%16 = tail call double @exp(double %15)
%17 = fmul double %12, %9
%18 = tail call double @exp(double %17)
%19 = fsub double %16, %18
%20 = fmul double %12, %14
%21 = fdiv double %19, %20
%22 = fmul double %13, %7
%23 = tail call double @exp(double %22)
%24 = fmul double %23, 2.000000e+00
%25 = fadd double %12, %11
%26 = fmul double %25, %13
%27 = fmul double %14, %14
%28 = fmul double %26, %27
%29 = fdiv double %24, %28
%30 = fmul double %13, %9
%31 = tail call double @exp(double %30)
%32 = fmul double %31, 2.000000e+00
%33 = fmul double %14, %20
%34 = fdiv double %32, %33
%35 = fdiv double 1.000000e+00, %13
%36 = tail call double @exp(double %20)
%37 = fdiv double %36, %25
%38 = fsub double %35, %37
%39 = tail call double @llvm.fmuladd.f64(double %34, double %38, double %29)
%40 = tail call double @log(double %21)
%41 = fdiv double %40, %7
%42 = tail call double @log(double %39)
%43 = fdiv double %42, %7
%44 = tail call double @llvm.fmuladd.f64(double %41, double -2.000000e+00, double %43)
%45 = tail call double @sqrt(double %44)
%46 = fsub double %7, %8
%47 = fcmp ogt double %46, 0.000000e+00
br i1 %47, label %48, label %57
48: ; preds = %10
%49 = fdiv double %7, %8
%50 = fneg double %46
%51 = fdiv double %50, %8
%52 = fmul double %51, %2
%53 = tail call double @llvm.fmuladd.f64(double %49, double %3, double %52)
%54 = tail call double @rq_pricing_blackscholes_gen(i16 signext %0, double %1, double %53, double %8, double %4, double %41, double %45)
%55 = fmul double %54, %8
%56 = fdiv double %55, %7
br label %59
57: ; preds = %10
%58 = tail call double @rq_pricing_blackscholes_gen(i16 signext %0, double %1, double %3, double %8, double %4, double %41, double %45)
br label %59
59: ; preds = %57, %48
%60 = phi double [ %56, %48 ], [ %58, %57 ]
ret double %60
}