#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 sqrt(double);
int corr(double x[], double y[], int n, double xbar, double ybar, double *uxy,
         double *r0) {
  int i;
  double w1, w2, w3, wx, wy;
  if (n < 2)
    return 999;
  w1 = w2 = w3 = 0.0;
  n -= 1;
  for (i = 0; i <= n; i++) {
    wx = x[i] - xbar;
    wy = y[i] - ybar;
    w1 += (wx * wy);
    w2 += (wx * wx);
    w3 += (wy * wy);
  }
  *uxy = w1 / n;
  *r0 = w1 / sqrt(w2 * w3);
  return 0;
}


x86 assembly (clang, -O0):
<corr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    114e <corr+0x3e>
movl   $0x3e7,-0x4(%rbp)
jmp    125c <corr+0x14c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1212 <corr+0x102>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1176 <corr+0x66>
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<corr>:
mov    $0x3e7,%eax
cmp    $0x2,%edx
jl     1223 <corr+0x113>
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %edx,%r8d
add    $0xffffffff,%edx
unpcklpd %xmm0,%xmm1
lea    0x0(,%r8,8),%rax
and    $0xfffffffffffffff0,%rax
xorpd  %xmm2,%xmm2
xorpd  %xmm4,%xmm4
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  (%rsi,%rbx,1),%xmm0
movhpd (%rdi,%rbx,1),%xmm0
subpd  %xmm1,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
mulpd  %xmm0,%xmm0
addpd  %xmm2,%xmm0
movsd  0x8(%rsi,%rbx,1),%xmm2
addsd  %xmm4,%xmm3
movhpd 0x8(%rdi,%rbx,1),%xmm2
subpd  %xmm1,%xmm2
movapd %xmm2,%xmm4
unpckhpd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
mulpd  %xmm2,%xmm2
addpd  %xmm0,%xmm2
add    $0x10,%rbx
cmp    %rbx,%rax
jne    1150 <corr+0x40>
test   $0x1,%r8b
je     11d3 <corr+0xc3>
movsd  (%rsi,%rbx,1),%xmm0
movhpd (%rdi,%rbx,1),%xmm0
subpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm4
mulpd  %xmm0,%xmm0
addpd  %xmm0,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
movapd %xmm4,%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,(%rcx)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1202 <corr+0xf2>
sqrtsd %xmm0,%xmm0
jmp    1211 <corr+0x101>
movapd %xmm4,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm4
divsd  %xmm0,%xmm4
movsd  %xmm4,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @corr(double* %0, double* %1, i32 %2, double %3, double %4, double* %5, double* %6) {
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%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
store double* %0, double** %9
store double* %1, double** %10
store i32 %2, i32* %11
store double %3, double* %12
store double %4, double* %13
store double* %5, double** %14
store double* %6, double** %15
%22 = load i32, i32* %11
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %25
24: ; preds = %7
store i32 999, i32* %8
br label %75
25: ; preds = %7
store double 0.000000e+00, double* %19
store double 0.000000e+00, double* %18
store double 0.000000e+00, double* %17
%26 = load i32, i32* %11
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %11
store i32 0, i32* %16
br label %28
28: ; preds = %59, %25
%29 = load i32, i32* %16
%30 = load i32, i32* %11
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %62
32: ; preds = %28
%33 = load double*, double** %9
%34 = load i32, i32* %16
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = load double, double* %12
%39 = fsub double %37, %38
store double %39, double* %20
%40 = load double*, double** %10
%41 = load i32, i32* %16
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double, double* %13
%46 = fsub double %44, %45
store double %46, double* %21
%47 = load double, double* %20
%48 = load double, double* %21
%49 = load double, double* %17
%50 = call double @llvm.fmuladd.f64(double %47, double %48, double %49)
store double %50, double* %17
%51 = load double, double* %20
%52 = load double, double* %20
%53 = load double, double* %18
%54 = call double @llvm.fmuladd.f64(double %51, double %52, double %53)
store double %54, double* %18
%55 = load double, double* %21
%56 = load double, double* %21
%57 = load double, double* %19
%58 = call double @llvm.fmuladd.f64(double %55, double %56, double %57)
store double %58, double* %19
br label %59
59: ; preds = %32
%60 = load i32, i32* %16
%61 = add nsw i32 %60, 1
store i32 %61, i32* %16
br label %28
62: ; preds = %28
%63 = load double, double* %17
%64 = load i32, i32* %11
%65 = sitofp i32 %64 to double
%66 = fdiv double %63, %65
%67 = load double*, double** %14
store double %66, double* %67
%68 = load double, double* %17
%69 = load double, double* %18
%70 = load double, double* %19
%71 = fmul double %69, %70
%72 = call double @sqrt(double %71)
%73 = fdiv double %68, %72
%74 = load double*, double** %15
store double %73, double* %74
store i32 0, i32* %8
br label %75
75: ; preds = %62, %24
%76 = load i32, i32* %8
ret i32 %76
}

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