#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 */
int pow(double, int);
double sqrt(double);
double correlation(double *x, double *y, int dim) {
  double sumX, sumY, sumXX, sumYY, sumXY;
  sumX = sumY = sumXX = sumYY = sumXY = 0;
  for (int i = 0; i < dim; i++) {
    sumX += x[i];
    sumY += y[i];
    sumXX += pow(x[i], 2);
    sumYY += pow(y[i], 2);
    sumXY += x[i] * y[i];
  }
  double sumSqDevX = sumXX - pow(sumX, 2) / dim;
  double sumSqDevY = sumYY - pow(sumY, 2) / dim;
  double sumSqDevXY = sumXY - sumX * sumY / dim;
  double denom = sumSqDevX * sumSqDevY;
  return sumSqDevXY / sqrt(denom);
}


x86 assembly (clang, -O0):
<correlation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1223 <correlation+0x103>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2sd %eax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1165 <correlation+0x45>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  -0x80(%rbp),%xmm0
cltd
idivl  -0x14(%rbp)
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  -0x78(%rbp),%xmm0
cltd
idivl  -0x14(%rbp)
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
divsd  %xmm1,%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<correlation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edx,%r14d
xorps  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x10(%rsp)
xorpd  %xmm1,%xmm1
xorpd  %xmm3,%xmm3
test   %edx,%edx
jle    1222 <correlation+0x102>
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %r14d,%r15d
xorpd  %xmm3,%xmm3
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm2,%xmm2
xorps  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  (%r12,%rbp,8),%xmm0
addsd  %xmm0,%xmm3
movsd  %xmm3,0x20(%rsp)
addsd  (%rbx,%rbp,8),%xmm1
movsd  %xmm1,0x18(%rsp)
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x20(%rsp),%xmm3
movsd  0x28(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%r12,%rbp,8),%xmm1
mulsd  (%rbx,%rbp,8),%xmm1
addsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm1
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1180 <correlation+0x60>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm3,0x20(%rsp)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm3,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cltd
idiv   %r14d
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x28(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
cltd
idiv   %r14d
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
subsd  %xmm2,%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm3
mulsd  0x20(%rsp),%xmm3
xorps  %xmm2,%xmm2
cvtsi2sd %r14d,%xmm2
divsd  %xmm2,%xmm3
subsd  %xmm3,%xmm1
ucomisd 0xd48(%rip),%xmm0
jb     12c0 <correlation+0x1a0>
sqrtsd %xmm0,%xmm0
jmp    12d1 <correlation+0x1b1>
movsd  %xmm1,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @correlation(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %28
7: ; preds = %28, %3
%8 = phi double [ 0.000000e+00, %3 ], [ %50, %28 ]
%9 = phi double [ 0.000000e+00, %3 ], [ %47, %28 ]
%10 = phi double [ 0.000000e+00, %3 ], [ %43, %28 ]
%11 = phi double [ 0.000000e+00, %3 ], [ %40, %28 ]
%12 = phi double [ 0.000000e+00, %3 ], [ %37, %28 ]
%13 = tail call i32 @pow(double %12, i32 2)
%14 = sdiv i32 %13, %2
%15 = sitofp i32 %14 to double
%16 = fsub double %10, %15
%17 = tail call i32 @pow(double %11, i32 2)
%18 = sdiv i32 %17, %2
%19 = sitofp i32 %18 to double
%20 = fsub double %9, %19
%21 = fmul double %11, %12
%22 = sitofp i32 %2 to double
%23 = fdiv double %21, %22
%24 = fsub double %8, %23
%25 = fmul double %16, %20
%26 = tail call double @sqrt(double %25)
%27 = fdiv double %24, %26
ret double %27
28: ; preds = %5, %28
%29 = phi i64 [ 0, %5 ], [ %51, %28 ]
%30 = phi double [ 0.000000e+00, %5 ], [ %37, %28 ]
%31 = phi double [ 0.000000e+00, %5 ], [ %40, %28 ]
%32 = phi double [ 0.000000e+00, %5 ], [ %43, %28 ]
%33 = phi double [ 0.000000e+00, %5 ], [ %47, %28 ]
%34 = phi double [ 0.000000e+00, %5 ], [ %50, %28 ]
%35 = getelementptr inbounds double, double* %0, i64 %29
%36 = load double, double* %35
%37 = fadd double %30, %36
%38 = getelementptr inbounds double, double* %1, i64 %29
%39 = load double, double* %38
%40 = fadd double %31, %39
%41 = tail call i32 @pow(double %36, i32 2)
%42 = sitofp i32 %41 to double
%43 = fadd double %32, %42
%44 = load double, double* %38
%45 = tail call i32 @pow(double %44, i32 2)
%46 = sitofp i32 %45 to double
%47 = fadd double %33, %46
%48 = load double, double* %35
%49 = load double, double* %38
%50 = tail call double @llvm.fmuladd.f64(double %48, double %49, double %34)
%51 = add nuw nsw i64 %29, 1
%52 = icmp eq i64 %51, %6
br i1 %52, label %7, label %28
}