#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 mean(float *, int);
scalar_t__ pow(double, int);
int /*<<< orphan*/ printf(char *, double, double, double, double, double);
double sqrt(double);
double correlation(float *xData, float *yData, int n) {
  int i;
  double sumProduct = 0, xSumSquares = 0, ySumSquares = 0;
  double xMean, yMean;
  xMean = mean(xData, n);
  yMean = mean(yData, n);
  for (i = 0; i < n; i++) {
    sumProduct += ((double)xData[i] - xMean) * ((double)yData[i] - yMean);
    xSumSquares += pow((double)xData[i] - xMean, 2);
    ySumSquares += pow((double)yData[i] - yMean, 2);
  }
  printf("%f %f %f %f %f\n", sumProduct, xSumSquares, ySumSquares, xMean,
         yMean);
  return ((sumProduct / (sqrt(xSumSquares * ySumSquares))) *
          (sumProduct / (sqrt(xSumSquares * ySumSquares))));
}


x86 assembly (clang, -O0):
<correlation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <mean@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <mean@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    124a <correlation+0x10a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm2
subsd  -0x40(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1194 <correlation+0x54>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
movsd  -0x40(%rbp),%xmm4
lea    0xd96(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<correlation>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%esi
call   1050 <mean@plt>
movsd  %xmm0,0x20(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <mean@plt>
movapd %xmm0,%xmm4
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
test   %ebp,%ebp
jle    1245 <correlation+0x105>
mov    %ebp,%r15d
xorpd  %xmm3,%xmm3
xor    %ebp,%ebp
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
movsd  %xmm4,0x28(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm2,0x10(%rsp)
movss  (%r14,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  0x20(%rsp),%xmm0
movss  (%rbx,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm4,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm3
movapd %xmm3,0x30(%rsp)
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movss  (%rbx,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  0x28(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movapd 0x10(%rsp),%xmm2
movsd  0x28(%rsp),%xmm4
movapd 0x30(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm2
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11b0 <correlation+0x70>
movapd %xmm2,0x10(%rsp)
lea    0xdb6(%rip),%rdi
movapd %xmm3,0x30(%rsp)
movapd %xmm3,%xmm0
movaps (%rsp),%xmm1
movsd  0x20(%rsp),%xmm3
call   1030 <printf@plt>
movapd (%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
xorps  %xmm3,%xmm3
sqrtsd %xmm1,%xmm3
ucomisd 0xd7b(%rip),%xmm1
movapd %xmm3,%xmm2
jae    12ae <correlation+0x16e>
movapd %xmm1,%xmm0
movapd %xmm1,(%rsp)
movapd %xmm3,0x10(%rsp)
call   1060 <sqrt@plt>
movapd 0x10(%rsp),%xmm3
movapd (%rsp),%xmm1
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jae    12cf <correlation+0x18f>
movapd %xmm1,%xmm0
movapd %xmm2,(%rsp)
call   1060 <sqrt@plt>
movapd (%rsp),%xmm2
movapd %xmm0,%xmm3
unpcklpd %xmm3,%xmm2
movapd 0x30(%rsp),%xmm1
unpcklpd %xmm1,%xmm1
divpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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