#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 pow(double, int);
void stage_two(double *vec, double *fact, int p, double *sigmas, double *mseR,
               double *res, double *ECik) {
  int i, j, k;
  double mse_cum;
  for (i = p - 1; i > 0; --i) {
    mse_cum = 0.;
    for (j = 0; j < p - i; ++j) {
      k = p * i + (p - i) + j * p;
      vec[k] = vec[k - p] * fact[i + j - 1];
      mse_cum += (sigmas[i + j - 1] / pow(fact[i + j - 1], 2)) *
                 ((1 / vec[k - p]) + (1 / ECik[i + j - 1]));
    }
    mseR[p - i] = pow(vec[k], 2) * mse_cum;
    res[p - i] = vec[k] - vec[p * i - i];
  }
}


x86 assembly (clang, -O0):
<stage_two>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    12c6 <stage_two+0x1b6>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x34(%rbp),%ecx
cmp    %ecx,%eax
jge    1255 <stage_two+0x145>
mov    -0x14(%rbp),%eax
imul   -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x34(%rbp),%ecx
add    %ecx,%eax
mov    -0x38(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xdf1(%rip),%xmm2
divsd  (%rax,%rcx,8),%xmm2
mov    0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xdd4(%rip),%xmm1
divsd  (%rax,%rcx,8),%xmm1
addsd  %xmm1,%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1155 <stage_two+0x45>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mulsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x34(%rbp),%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    113c <stage_two+0x2c>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stage_two>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x28(%rsp)
mov    %rcx,0x68(%rsp)
mov    %rsi,0x60(%rsp)
cmp    $0x2,%edx
jl     1315 <stage_two+0x205>
mov    %edx,%r13d
mov    %edx,%ecx
mov    %rcx,%rax
shl    $0x20,%rax
movabs $0xfffffffe00000000,%rbx
ff ff ff
add    %rax,%rbx
lea    -0x2(%r13),%eax
imul   %edx,%eax
add    $0x1,%eax
mov    $0x1,%edx
sub    %r13d,%edx
mov    %edx,0x14(%rsp)
lea    -0x1(%r13),%edx
imul   %r13d,%edx
add    $0x1,%edx
mov    $0x1,%r14d
mov    %rcx,%rsi
mov    %r13,0x58(%rsp)
mov    %rcx,0x20(%rsp)
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rsi
mov    %rsi,0x40(%rsp)
sub    %rsi,%rcx
mov    %rcx,0x38(%rsp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,0x48(%rsp)
mov    %edx,0x18(%rsp)
mov    %edx,%r12d
mov    %eax,0x1c(%rsp)
mov    %eax,%r15d
mov    %rbx,0x50(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r15d,%r15
movsd  (%rdi,%r15,8),%xmm0
mov    %rbx,%r13
sar    $0x1d,%r13
mov    0x60(%rsp),%rcx
mulsd  (%rcx,%r13,1),%xmm0
movslq %r12d,%r12
movsd  %xmm0,(%rdi,%r12,8)
mov    0x68(%rsp),%rax
movsd  (%rax,%r13,1),%xmm0
movsd  %xmm0,0x70(%rsp)
movsd  (%rcx,%r13,1),%xmm0
mov    %rdi,%rbp
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rbp,%rdi
movsd  0x70(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x0(%rbp,%r15,8),%xmm0
mov    0xb0(%rsp),%rax
movhpd (%rax,%r13,1),%xmm0
mov    0x58(%rsp),%r13
movapd 0xdb9(%rip),%xmm1
divpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movabs $0x100000000,%rax
add    %rax,%rbx
add    %r13d,%r15d
add    %r13d,%r12d
add    $0xffffffffffffffff,%r14
jne    11d0 <stage_two+0xc0>
movslq %r15d,%rbx
movsd  (%rdi,%rbx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rbp,%rdi
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mov    0x28(%rsp),%rax
mov    0x38(%rsp),%rcx
movsd  %xmm1,(%rax,%rcx,8)
movsd  0x0(%rbp,%rbx,8),%xmm0
mov    0x40(%rsp),%rsi
mov    %esi,%eax
imul   %r13d,%eax
cltq
sub    %rsi,%rax
subsd  0x0(%rbp,%rax,8),%xmm0
mov    0x30(%rsp),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    0x48(%rsp),%r14
add    $0x1,%r14
mov    0x50(%rsp),%rbx
movabs $0xffffffff00000000,%rax
ff ff ff
add    %rax,%rbx
mov    0x1c(%rsp),%eax
mov    0x14(%rsp),%ecx
add    %ecx,%eax
mov    0x18(%rsp),%edx
add    %ecx,%edx
mov    0x20(%rsp),%rcx
cmp    %rcx,%r14
jne    1190 <stage_two+0x80>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @stage_two(double* nocapture %0, double* nocapture %1, i32 %2, double* nocapture %3, double* nocapture writeonly %4, double* nocapture writeonly %5, double* nocapture %6) {
%8 = icmp sgt i32 %2, 1
br i1 %8, label %9, label %73
9: ; preds = %7
%10 = zext i32 %2 to i64
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %56, %9
%13 = phi i64 [ %10, %9 ], [ %15, %56 ]
%14 = phi i64 [ 1, %9 ], [ %71, %56 ]
%15 = add nsw i64 %13, -1
%16 = trunc i64 %15 to i32
%17 = sub nsw i64 %10, %15
%18 = add i64 %13, 4294967294
%19 = trunc i64 %17 to i32
br label %20
20: ; preds = %12, %20
%21 = phi i64 [ 0, %12 ], [ %54, %20 ]
%22 = phi double [ 0.000000e+00, %12 ], [ %53, %20 ]
%23 = trunc i64 %21 to i32
%24 = add i32 %23, %16
%25 = mul i32 %24, %2
%26 = add i32 %25, %19
%27 = sub nsw i32 %26, %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %0, i64 %28
%30 = load double, double* %29
%31 = add i64 %18, %21
%32 = shl i64 %31, 32
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds double, double* %1, i64 %33
%35 = load double, double* %34
%36 = fmul double %30, %35
%37 = sext i32 %26 to i64
%38 = getelementptr inbounds double, double* %0, i64 %37
store double %36, double* %38
%39 = getelementptr inbounds double, double* %3, i64 %33
%40 = load double, double* %39
%41 = load double, double* %34
%42 = tail call double @pow(double %41, i32 2)
%43 = fdiv double %40, %42
%44 = load double, double* %29
%45 = getelementptr inbounds double, double* %6, i64 %33
%46 = load double, double* %45
%47 = insertelement <2 x double> poison, double %44, i64 0
%48 = insertelement <2 x double> %47, double %46, i64 1
%49 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %48
%50 = shufflevector <2 x double> %49, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%51 = fadd <2 x double> %49, %50
%52 = extractelement <2 x double> %51, i64 0
%53 = tail call double @llvm.fmuladd.f64(double %43, double %52, double %22)
%54 = add nuw nsw i64 %21, 1
%55 = icmp eq i64 %54, %14
br i1 %55, label %56, label %20
56: ; preds = %20
%57 = sext i32 %26 to i64
%58 = getelementptr inbounds double, double* %0, i64 %57
%59 = load double, double* %58
%60 = tail call double @pow(double %59, i32 2)
%61 = fmul double %53, %60
%62 = getelementptr inbounds double, double* %4, i64 %17
store double %61, double* %62
%63 = load double, double* %58
%64 = mul nsw i32 %16, %2
%65 = sext i32 %64 to i64
%66 = sub nsw i64 %65, %15
%67 = getelementptr inbounds double, double* %0, i64 %66
%68 = load double, double* %67
%69 = fsub double %63, %68
%70 = getelementptr inbounds double, double* %5, i64 %17
store double %69, double* %70
%71 = add nuw nsw i64 %14, 1
%72 = icmp eq i64 %71, %11
br i1 %72, label %73, label %12
73: ; preds = %56, %7
ret void
}