#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(int);
double rq_pricing_blackscholes(short, double, double, double, double, double,
                               double, double);
double sqrt(double);
double rq_pricing_average_rate(short call, int num_ratesets,
                               double *rateset_dates, double *rateset_weights,
                               double S, double X, double r_dom, double r_for,
                               double sigma, double tau_e, double tau_d) {
  double as = 0.0;
  double var_as = 0.0;
  double vx = 0.0;
  int i;
  double b = r_dom - r_for;
  for (i = 0; i < num_ratesets; i++) {
    int j;
    double ti = rateset_dates[i] / 2.0;
    double weight_i = rateset_weights[i];
    as += weight_i * exp(b * ti);
    for (j = 0; j < num_ratesets; j++) {
      double tj = rateset_dates[j] / 2.0;
      double weight_j = rateset_weights[j];
      var_as += weight_i * weight_j * exp(b * (ti + tj)) *
                (exp(sigma * sigma * ((ti) < (tj) ? (ti) : (tj))) - 1.0);
    }
  }
  as *= S;
  var_as *= S * S;
  vx = sqrt(log(1 + var_as / (as * as)) / tau_e);
  return rq_pricing_blackscholes(call, as, X, r_dom, r_for, vx, tau_e, tau_d);
}


x86 assembly (clang, -O0):
<rq_pricing_average_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movsd  %xmm3,-0x38(%rbp)
movsd  %xmm4,-0x40(%rbp)
movsd  %xmm5,-0x48(%rbp)
movsd  %xmm6,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1379 <rq_pricing_average_rate+0x239>
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x18(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x78(%rbp),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0xa8(%rbp),%xmm0
ff
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1366 <rq_pricing_average_rate+0x226>
mov    -0x10(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xdb1(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x18(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
mulsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x78(%rbp),%xmm0
movsd  -0x88(%rbp),%xmm1
ff
addsd  -0x98(%rbp),%xmm1
ff
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0xc0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x88(%rbp),%xmm1
ff
movsd  -0x98(%rbp),%xmm0
ff
ucomisd %xmm1,%xmm0
jbe    1306 <rq_pricing_average_rate+0x1c6>
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0xc8(%rbp)
jmp    1316 <rq_pricing_average_rate+0x1d6>
movsd  -0x98(%rbp),%xmm0
ff
movsd  %xmm0,-0xc8(%rbp)
ff
movsd  -0xb0(%rbp),%xmm0
ff
movsd  -0xc8(%rbp),%xmm1
ff
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0xb8(%rbp),%xmm0
ff
movsd  0xcbe(%rip),%xmm1
subsd  %xmm1,%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1236 <rq_pricing_average_rate+0xf6>
jmp    136b <rq_pricing_average_rate+0x22b>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11ae <rq_pricing_average_rate+0x6e>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xc49(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <log@plt>
divsd  -0x48(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x68(%rbp)
mov    -0x2(%rbp),%ax
movsd  -0x58(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
movsd  -0x68(%rbp),%xmm4
movsd  -0x48(%rbp),%xmm5
movsd  -0x50(%rbp),%xmm6
movswl %ax,%edi
call   1040 <rq_pricing_blackscholes@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pricing_average_rate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movsd  %xmm6,0x68(%rsp)
movsd  %xmm5,0x38(%rsp)
movsd  %xmm4,0x20(%rsp)
movsd  %xmm3,0x30(%rsp)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x60(%rsp)
movsd  %xmm0,0x58(%rsp)
mov    %edi,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
test   %esi,%esi
jle    12e1 <rq_pricing_average_rate+0x1a1>
mov    %rcx,%r15
mov    %rdx,%r13
movsd  0x28(%rsp),%xmm1
subsd  0x30(%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    %esi,%ebx
xorpd  %xmm0,%xmm0
xor    %r12d,%r12d
movsd  0xe3c(%rip),%xmm3
xorpd  %xmm2,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x40(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x10(%rsp)
movsd  0x0(%r13,%r12,8),%xmm2
mulsd  %xmm3,%xmm2
movsd  (%r15,%r12,8),%xmm0
movsd  %xmm0,0x48(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm2,0x50(%rsp)
mulsd  %xmm2,%xmm0
call   1030 <exp@plt>
mulsd  0x48(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %ebp,%ebp
movsd  0x8(%rsp),%xmm1
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  0x0(%r13,%rbp,8),%xmm1
mulsd  0xdbb(%rip),%xmm1
movsd  %xmm1,0x70(%rsp)
movsd  (%r15,%rbp,8),%xmm0
mulsd  0x48(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x50(%rsp),%xmm0
addsd  %xmm1,%xmm0
mulsd  0x40(%rsp),%xmm0
call   1030 <exp@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x50(%rsp),%xmm0
minsd  0x70(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm1
addsd  0xd65(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1230 <rq_pricing_average_rate+0xf0>
movsd  %xmm1,0x8(%rsp)
add    $0x1,%r12
cmp    %rbx,%r12
movsd  0x18(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
movsd  0xd25(%rip),%xmm3
jne    11e0 <rq_pricing_average_rate+0xa0>
movsd  0x58(%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm1
mulsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm0,%xmm0
divsd  %xmm0,%xmm1
addsd  0xd05(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <log@plt>
divsd  0x38(%rsp),%xmm0
ucomisd 0xcf6(%rip),%xmm0
jb     132d <rq_pricing_average_rate+0x1ed>
xorps  %xmm4,%xmm4
sqrtsd %xmm0,%xmm4
jmp    1336 <rq_pricing_average_rate+0x1f6>
call   1060 <sqrt@plt>
movapd %xmm0,%xmm4
movswl %r14w,%edi
movsd  0x18(%rsp),%xmm0
movsd  0x60(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
movsd  0x30(%rsp),%xmm3
movsd  0x38(%rsp),%xmm5
movsd  0x68(%rsp),%xmm6
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <rq_pricing_blackscholes@plt>

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

LLVM IR (-O2):
define double @rq_pricing_average_rate(i16 signext %0, i32 %1, double* nocapture %2, double* nocapture %3, double %4, double %5, double %6, double %7, double %8, double %9, double %10) {
%12 = fsub double %6, %7
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %53
14: ; preds = %11
%15 = fmul double %8, %8
%16 = zext i32 %1 to i64
br label %17
17: ; preds = %50, %14
%18 = phi i64 [ 0, %14 ], [ %51, %50 ]
%19 = phi double [ 0.000000e+00, %14 ], [ %28, %50 ]
%20 = phi double [ 0.000000e+00, %14 ], [ %47, %50 ]
%21 = getelementptr inbounds double, double* %2, i64 %18
%22 = load double, double* %21
%23 = fmul double %22, 5.000000e-01
%24 = getelementptr inbounds double, double* %3, i64 %18
%25 = load double, double* %24
%26 = fmul double %12, %23
%27 = tail call double @exp(double %26)
%28 = tail call double @llvm.fmuladd.f64(double %25, double %27, double %19)
br label %29
29: ; preds = %17, %29
%30 = phi i64 [ 0, %17 ], [ %48, %29 ]
%31 = phi double [ %20, %17 ], [ %47, %29 ]
%32 = getelementptr inbounds double, double* %2, i64 %30
%33 = load double, double* %32
%34 = fmul double %33, 5.000000e-01
%35 = getelementptr inbounds double, double* %3, i64 %30
%36 = load double, double* %35
%37 = fmul double %25, %36
%38 = fadd double %23, %34
%39 = fmul double %12, %38
%40 = tail call double @exp(double %39)
%41 = fmul double %37, %40
%42 = fcmp olt double %23, %34
%43 = select i1 %42, double %23, double %34
%44 = fmul double %15, %43
%45 = tail call double @exp(double %44)
%46 = fadd double %45, -1.000000e+00
%47 = tail call double @llvm.fmuladd.f64(double %41, double %46, double %31)
%48 = add nuw nsw i64 %30, 1
%49 = icmp eq i64 %48, %16
br i1 %49, label %50, label %29
50: ; preds = %29
%51 = add nuw nsw i64 %18, 1
%52 = icmp eq i64 %51, %16
br i1 %52, label %53, label %17
53: ; preds = %50, %11
%54 = phi double [ 0.000000e+00, %11 ], [ %47, %50 ]
%55 = phi double [ 0.000000e+00, %11 ], [ %28, %50 ]
%56 = fmul double %55, %4
%57 = fmul double %4, %4
%58 = fmul double %57, %54
%59 = fmul double %56, %56
%60 = fdiv double %58, %59
%61 = fadd double %60, 1.000000e+00
%62 = fptosi double %61 to i32
%63 = tail call double @log(i32 %62)
%64 = fdiv double %63, %9
%65 = tail call double @sqrt(double %64)
%66 = tail call double @rq_pricing_blackscholes(i16 signext %0, double %56, double %5, double %6, double %7, double %65, double %9, double %10)
ret double %66
}