#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 Kp(double, double, double, double, double);
double exp(double);
double log(double);
double pow(double, double);
double rq_pricing_blackscholes_gen(int /*<<< orphan*/, double, double, double,
                                   double, double, double);
double rq_pricing_cumul_norm_dist(double);
double sqrt(double);
double rq_pricing_barone_adesi_whaley_amer_put(double S, double X, double T,
                                               double r, double b, double v) {
  double ret = 0.0;
  double Sk = Kp(X, T, r, b, v);
  if (S > Sk) {
    double v_sqr = v * v;
    double n = 2.0 * b / v_sqr;
    double K = 2.0 * r / (v_sqr * (1.0 - exp(-r * T)));
    double d1 = (log(Sk / X) + (b + v_sqr / 2.0) * T) / (v * sqrt(T));
    double Q1 = (-(n - 1) - sqrt(pow((n - 1), 2) + 4.0 * K)) / 2.0;
    double a1 =
        -(Sk / Q1) * (1.0 - exp((b - r) * T) * rq_pricing_cumul_norm_dist(-d1));
    ret = rq_pricing_blackscholes_gen(0, S, X, T, r, b, v) +
          a1 * pow((S / Sk), Q1);
  } else
    ret = X - S;
  return ret;
}


x86 assembly (clang, -O0):
<rq_pricing_barone_adesi_whaley_amer_put>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
movsd  -0x30(%rbp),%xmm4
call   1040 <Kp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1481 <rq_pricing_barone_adesi_whaley_amer_put+0x311>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe1d(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe06(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1050 <exp@plt>
movsd  -0xb8(%rbp),%xmm1
ff
movaps %xmm0,%xmm3
movsd  -0xb0(%rbp),%xmm0
ff
movsd  0xda3(%rip),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  0xd76(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
call   1090 <sqrt@plt>
movsd  -0xa8(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xd0d(%rip),%xmm1
subsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
movsd  0xcdd(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xcd9(%rip),%xmm1
call   1080 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
movsd  0xccc(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1090 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  0xca0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  -0x90(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x88(%rbp),%xmm0
ff
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
movsd  0xbf3(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x30(%rbp),%xmm5
xor    %edi,%edi
call   1060 <rq_pricing_blackscholes_gen@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
call   1080 <pow@plt>
movsd  -0x80(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1490 <rq_pricing_barone_adesi_whaley_amer_put+0x320>
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_barone_adesi_whaley_amer_put>:
sub    $0x88,%rsp
movsd  %xmm0,0x48(%rsp)
movsd  %xmm1,0x38(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm1
movaps %xmm3,0x70(%rsp)
movaps %xmm3,%xmm2
movsd  %xmm4,(%rsp)
movaps %xmm4,%xmm3
movsd  %xmm5,0x40(%rsp)
movaps %xmm5,%xmm4
call   1040 <Kp@plt>
movsd  0x48(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    1287 <rq_pricing_barone_adesi_whaley_amer_put+0x117>
movapd %xmm0,%xmm1
movsd  0x40(%rsp),%xmm2
mulsd  %xmm2,%xmm2
movapd %xmm2,0x10(%rsp)
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
divsd  %xmm2,%xmm0
movapd %xmm0,0x60(%rsp)
movapd 0x70(%rsp),%xmm2
movapd %xmm2,%xmm0
addsd  %xmm2,%xmm0
movapd %xmm0,0x50(%rsp)
movapd 0xdff(%rip),%xmm0
xorpd  %xmm2,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm1,0x30(%rsp)
call   1050 <exp@plt>
movsd  0xdf2(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movapd 0x50(%rsp),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x50(%rsp)
movsd  0x30(%rsp),%xmm0
divsd  0x38(%rsp),%xmm0
call   1070 <log@plt>
movapd %xmm0,%xmm3
movapd 0x10(%rsp),%xmm0
mulsd  0xdbd(%rip),%xmm0
addsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
movapd %xmm1,%xmm0
jb     1299 <rq_pricing_barone_adesi_whaley_amer_put+0x129>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    12b2 <rq_pricing_barone_adesi_whaley_amer_put+0x142>
movsd  0x38(%rsp),%xmm0
subsd  %xmm2,%xmm0
add    $0x88,%rsp
ret
movsd  %xmm3,0x28(%rsp)
call   1090 <sqrt@plt>
movsd  0x28(%rsp),%xmm3
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
addsd  %xmm3,%xmm0
movapd %xmm0,0x10(%rsp)
mulsd  0x40(%rsp),%xmm1
movsd  %xmm1,0x28(%rsp)
movapd 0x60(%rsp),%xmm1
addsd  0xd44(%rip),%xmm1
movapd 0xd1c(%rip),%xmm0
xorpd  %xmm1,%xmm0
movapd %xmm0,0x60(%rsp)
movapd 0x50(%rsp),%xmm0
mulsd  0xd2c(%rip),%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1310 <rq_pricing_barone_adesi_whaley_amer_put+0x1a0>
sqrtsd %xmm0,%xmm0
jmp    1315 <rq_pricing_barone_adesi_whaley_amer_put+0x1a5>
call   1090 <sqrt@plt>
movapd 0x70(%rsp),%xmm1
movapd 0x60(%rsp),%xmm2
subsd  %xmm0,%xmm2
mulsd  0xceb(%rip),%xmm2
movapd %xmm2,0x60(%rsp)
movsd  0x30(%rsp),%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,0x50(%rsp)
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x80(%rsp)
movapd 0x10(%rsp),%xmm0
xorpd  0xc92(%rip),%xmm0
divsd  0x28(%rsp),%xmm0
call   1030 <rq_pricing_cumul_norm_dist@plt>
mulsd  0x80(%rsp),%xmm0
movsd  0xc86(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x50(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %edi,%edi
movsd  0x48(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
movaps 0x70(%rsp),%xmm3
movsd  (%rsp),%xmm4
movsd  0x40(%rsp),%xmm5
call   1060 <rq_pricing_blackscholes_gen@plt>
movsd  %xmm0,(%rsp)
movsd  0x48(%rsp),%xmm0
divsd  0x30(%rsp),%xmm0
movaps 0x60(%rsp),%xmm1
call   1080 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x88,%rsp
ret

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

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