#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(int);
double sqrt(int);
double rq_pricing_time_switch(short call, double S, double X, double a,
                              double T, int m, double dt, double r, double b,
                              double v) {
  double sum = 0;
  int i;
  int n = (int)(T / dt);
  int Z = (call ? 1 : -1);
  double half_b_minus_vsqr = (b - (v * v) / 2.0);
  double log_S_over_X = log(S / X);
  for (i = 1; i <= n; i++) {
    double d = (log_S_over_X + half_b_minus_vsqr * i * dt) / (v * sqrt(i * dt));
    sum = sum + rq_pricing_cumul_norm_dist(Z * d) * dt;
  }
  return a * exp(-r * T) * sum + dt * a * exp(-r * T) * m;
}


x86 assembly (clang, -O0):
<rq_pricing_time_switch>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
movsd  %xmm4,-0x38(%rbp)
movsd  %xmm5,-0x40(%rbp)
movsd  %xmm6,-0x48(%rbp)
movsd  %xmm7,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x60(%rbp)
movswl -0x2(%rbp),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x64(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movsd  0xe3c(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x78(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x60(%rbp),%eax
jg     12a8 <rq_pricing_time_switch+0x168>
movsd  -0x78(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
cvtsi2sdl -0x5c(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  -0x98(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x90(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
cvtsi2sdl -0x64(%rbp),%xmm0
mulsd  -0x80(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  -0x88(%rbp),%xmm1
ff
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11ec <rq_pricing_time_switch+0xac>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0xb8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <exp@plt>
movsd  -0xb0(%rbp),%xmm1
ff
movsd  -0xa8(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_time_switch>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
movsd  %xmm7,0x18(%rsp)
movsd  %xmm6,0x10(%rsp)
movaps %xmm5,0x20(%rsp)
mov    %esi,%r14d
movsd  %xmm2,0x40(%rsp)
mov    %edi,%r15d
movsd  %xmm3,0x38(%rsp)
movapd %xmm3,%xmm2
movsd  %xmm4,0x8(%rsp)
divsd  %xmm4,%xmm2
cvttsd2si %xmm2,%ebx
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x48(%rsp)
test   %ebx,%ebx
jle    1256 <rq_pricing_time_switch+0x116>
movsd  0x18(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0xe58(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
neg    %ebx
mov    $0x1,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm1
jmp    1203 <rq_pricing_time_switch+0xc3>
cvttsd2si %xmm0,%edi
call   1030 <rq_pricing_cumul_norm_dist@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
je     125f <rq_pricing_time_switch+0x11f>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movapd %xmm0,0x50(%rsp)
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movapd 0x50(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  0x48(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
test   %r15w,%r15w
jne    11d0 <rq_pricing_time_switch+0x90>
xorpd  0xdbf(%rip),%xmm0
jmp    11d0 <rq_pricing_time_switch+0x90>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movapd 0x20(%rsp),%xmm0
xorpd  0xda3(%rip),%xmm0
mulsd  0x38(%rsp),%xmm0
movapd %xmm0,0x20(%rsp)
call   1040 <exp@plt>
movsd  0x40(%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <exp@plt>
mulsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
mulsd  %xmm1,%xmm0
addsd  (%rsp),%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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