#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);
void regression(double *x, double *y, int n, double *slope, double *intercept) {
  double sumX, sumY, sumXX, sumYY, sumXY;
  sumX = sumY = sumXX = sumYY = sumXY = 0;
  int i = 0;
  for (; i < n; 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) / n;
  double sumSqDevXY = sumXY - sumX * sumY / n;
  *slope = sumSqDevXY / sumSqDevX;
  *intercept = (sumY - (*slope) * sumX) / n;
}


x86 assembly (clang, -O0):
<regression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1218 <regression+0x108>
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2sd %eax,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2sd %eax,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    115a <regression+0x4a>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  -0x70(%rbp),%xmm0
cltd
idivl  -0x14(%rbp)
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regression>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %rcx,%r15
mov    %edx,%r12d
test   %edx,%edx
jle    11e0 <regression+0xd0>
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %r12d,%r13d
xorpd  %xmm1,%xmm1
xor    %r14d,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xchg   %ax,%ax
movsd  0x0(%rbp,%r14,8),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x10(%rsp),%xmm1
addsd  (%rbx,%r14,8),%xmm1
movsd  %xmm1,0x10(%rsp)
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rbx,%r14,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x18(%rsp),%xmm1
movsd  0x0(%rbp,%r14,8),%xmm0
mulsd  (%rbx,%r14,8),%xmm0
movsd  0x8(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
add    $0x1,%r14
cmp    %r14,%r13
jne    1160 <regression+0x50>
jmp    1201 <regression+0xf1>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cltd
idiv   %r12d
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm4
subsd  %xmm0,%xmm4
movsd  0x10(%rsp),%xmm2
movapd %xmm2,%xmm0
movsd  0x18(%rsp),%xmm5
mulsd  %xmm5,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
divsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm3
subsd  %xmm0,%xmm3
divsd  %xmm4,%xmm3
movsd  %xmm3,(%r15)
mulsd  %xmm5,%xmm3
subsd  %xmm3,%xmm2
divsd  %xmm1,%xmm2
mov    0x20(%rsp),%rax
movsd  %xmm2,(%rax)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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