#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 */
scalar_t__ pow(int /*<<< orphan*/, int);
int /*<<< orphan*/ residual(double, double, double, double);
double sse(double *x, double *y, int n, double slope, double intcp) {
  double SSE = 0;
  for (int i = 0; i < n; i++)
    SSE += pow(residual(x[i], y[i], slope, intcp), 2);
  return SSE;
}


x86 assembly (clang, -O0):
<sse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11aa <sse+0x8a>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
call   1030 <residual@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114c <sse+0x2c>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sse>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    11a4 <sse+0x84>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xorps  %xmm2,%xmm2
xor    %ebx,%ebx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax)
movsd  %xmm2,(%rsp)
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm3
call   1030 <residual@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
movsd  (%rsp),%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,(%rsp)
movsd  (%rsp),%xmm2
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <sse+0x30>
jmp    11a7 <sse+0x87>
xorps  %xmm2,%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @sse(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 i32
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* %11
store i32 0, i32* %12
br label %13
13: ; preds = %35, %5
%14 = load i32, i32* %12
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = load double*, double** %6
%19 = load i32, i32* %12
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %7
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %9
%29 = load double, double* %10
%30 = call i32 @residual(double %22, double %27, double %28, double %29)
%31 = call i64 @pow(i32 %30, i32 2)
%32 = sitofp i64 %31 to double
%33 = load double, double* %11
%34 = fadd double %33, %32
store double %34, double* %11
br label %35
35: ; preds = %17
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
br label %13
38: ; preds = %13
%39 = load double, double* %11
ret double %39
}

LLVM IR (-O2):
define double @sse(double* nocapture %0, double* nocapture %1, i32 %2, double %3, double %4) {
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = zext i32 %2 to i64
br label %11
9: ; preds = %11, %5
%10 = phi double [ 0.000000e+00, %5 ], [ %21, %11 ]
ret double %10
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %22, %11 ]
%13 = phi double [ 0.000000e+00, %7 ], [ %21, %11 ]
%14 = getelementptr inbounds double, double* %0, i64 %12
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %1, i64 %12
%17 = load double, double* %16
%18 = tail call i32 @residual(double %15, double %17, double %3, double %4)
%19 = tail call i64 @pow(i32 %18, i32 2)
%20 = sitofp i64 %19 to double
%21 = fadd double %13, %20
%22 = add nuw nsw i64 %12, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %9, label %11
}