void residuals(const double *x, const double *y, int n, double slope,
               double intcp, double *res) {
  for (int i = 0; i < n; i++) {
    res[i] = y[i] - (intcp + (slope * x[i]));
  }
}


x86 assembly (clang, -O0):
<residuals>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117b <residuals+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1124 <residuals+0x24>
pop    %rbp
ret

x86 assembly (clang, -O2):
<residuals>:
test   %edx,%edx
jle    12d7 <residuals+0x1d7>
mov    %edx,%r8d
cmp    $0x4,%edx
jae    1197 <residuals+0x97>
xor    %edx,%edx
mov    %rdx,%rax
not    %rax
test   $0x1,%r8b
je     1141 <residuals+0x41>
movsd  (%rsi,%rdx,8),%xmm2
movsd  (%rdi,%rdx,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
subsd  %xmm3,%xmm2
movsd  %xmm2,(%rcx,%rdx,8)
or     $0x1,%rdx
add    %r8,%rax
je     12d7 <residuals+0x1d7>
nopw   0x0(%rax,%rax,1)
movsd  (%rsi,%rdx,8),%xmm2
movsd  (%rdi,%rdx,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
subsd  %xmm3,%xmm2
movsd  %xmm2,(%rcx,%rdx,8)
movsd  0x8(%rsi,%rdx,8),%xmm2
movsd  0x8(%rdi,%rdx,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
subsd  %xmm3,%xmm2
movsd  %xmm2,0x8(%rcx,%rdx,8)
add    $0x2,%rdx
cmp    %rdx,%r8
jne    1150 <residuals+0x50>
jmp    12d7 <residuals+0x1d7>
lea    (%rcx,%r8,8),%rdx
lea    (%rsi,%r8,8),%rax
cmp    %rcx,%rax
seta   %r10b
lea    (%rdi,%r8,8),%rax
cmp    %rsi,%rdx
seta   %r11b
cmp    %rcx,%rax
seta   %al
cmp    %rdi,%rdx
seta   %r9b
xor    %edx,%edx
test   %r11b,%r10b
jne    1116 <residuals+0x16>
and    %r9b,%al
jne    1116 <residuals+0x16>
mov    %r8d,%edx
and    $0xfffffffc,%edx
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd %xmm1,%xmm3
unpcklpd %xmm1,%xmm3
lea    -0x4(%rdx),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rax,%rax
je     12d8 <residuals+0x1d8>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %eax,%eax
nopl   0x0(%rax)
movupd (%rsi,%rax,8),%xmm4
movupd 0x10(%rsi,%rax,8),%xmm5
movupd (%rdi,%rax,8),%xmm6
movupd 0x10(%rdi,%rax,8),%xmm7
mulpd  %xmm2,%xmm6
addpd  %xmm3,%xmm6
subpd  %xmm6,%xmm4
mulpd  %xmm2,%xmm7
addpd  %xmm3,%xmm7
subpd  %xmm7,%xmm5
movupd %xmm4,(%rcx,%rax,8)
movupd %xmm5,0x10(%rcx,%rax,8)
movupd 0x20(%rsi,%rax,8),%xmm4
movupd 0x30(%rsi,%rax,8),%xmm5
movupd 0x20(%rdi,%rax,8),%xmm6
movupd 0x30(%rdi,%rax,8),%xmm7
mulpd  %xmm2,%xmm6
addpd  %xmm3,%xmm6
subpd  %xmm6,%xmm4
mulpd  %xmm2,%xmm7
addpd  %xmm3,%xmm7
subpd  %xmm7,%xmm5
movupd %xmm4,0x20(%rcx,%rax,8)
movupd %xmm5,0x30(%rcx,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    1210 <residuals+0x110>
test   $0x1,%r9b
je     12ce <residuals+0x1ce>
movupd (%rsi,%rax,8),%xmm4
movupd 0x10(%rsi,%rax,8),%xmm5
movupd (%rdi,%rax,8),%xmm6
movupd 0x10(%rdi,%rax,8),%xmm7
mulpd  %xmm2,%xmm6
addpd  %xmm3,%xmm6
subpd  %xmm6,%xmm4
mulpd  %xmm2,%xmm7
addpd  %xmm3,%xmm7
subpd  %xmm7,%xmm5
movupd %xmm4,(%rcx,%rax,8)
movupd %xmm5,0x10(%rcx,%rax,8)
cmp    %r8,%rdx
jne    1116 <residuals+0x16>
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    1295 <residuals+0x195>
jmp    12ce <residuals+0x1ce>

LLVM IR (-O0):
define void @residuals(double* %0, double* %1, i32 %2, double %3, double %4, double* %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double*
%13 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store i32 %2, i32* %9
store double %3, double* %10
store double %4, double* %11
store double* %5, double** %12
store i32 0, i32* %13
br label %14
14: ; preds = %37, %6
%15 = load i32, i32* %13
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %40
18: ; preds = %14
%19 = load double*, double** %8
%20 = load i32, i32* %13
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double, double* %11
%25 = load double, double* %10
%26 = load double*, double** %7
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = call double @llvm.fmuladd.f64(double %25, double %30, double %24)
%32 = fsub double %23, %31
%33 = load double*, double** %12
%34 = load i32, i32* %13
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
store double %32, double* %36
br label %37
37: ; preds = %18
%38 = load i32, i32* %13
%39 = add nsw i32 %38, 1
store i32 %39, i32* %13
br label %14
40: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @residuals(double* nocapture %0, double* nocapture %1, i32 %2, double %3, double %4, double* nocapture writeonly %5) {
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %130
8: ; preds = %6
%9 = zext i32 %2 to i64
%10 = icmp ult i32 %2, 4
br i1 %10, label %112, label %11
11: ; preds = %8
%12 = getelementptr double, double* %5, i64 %9
%13 = getelementptr double, double* %1, i64 %9
%14 = getelementptr double, double* %0, i64 %9
%15 = icmp ugt double* %13, %5
%16 = icmp ugt double* %12, %1
%17 = and i1 %15, %16
%18 = icmp ugt double* %14, %5
%19 = icmp ugt double* %12, %0
%20 = and i1 %18, %19
%21 = or i1 %17, %20
br i1 %21, label %112, label %22
22: ; preds = %11
%23 = and i64 %9, 4294967292
%24 = insertelement <2 x double> poison, double %3, i64 0
%25 = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> zeroinitializer
%26 = insertelement <2 x double> poison, double %4, i64 0
%27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
%28 = insertelement <2 x double> poison, double %3, i64 0
%29 = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> zeroinitializer
%30 = insertelement <2 x double> poison, double %4, i64 0
%31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
%32 = add nsw i64 %23, -4
%33 = lshr exact i64 %32, 2
%34 = add nuw nsw i64 %33, 1
%35 = and i64 %34, 1
%36 = icmp eq i64 %32, 0
br i1 %36, label %86, label %37
37: ; preds = %22
%38 = and i64 %34, 9223372036854775806
br label %39
39: ; preds = %39, %37
%40 = phi i64 [ 0, %37 ], [ %83, %39 ]
%41 = phi i64 [ 0, %37 ], [ %84, %39 ]
%42 = getelementptr inbounds double, double* %1, i64 %40
%43 = bitcast double* %42 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = getelementptr inbounds double, double* %42, i64 2
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = getelementptr inbounds double, double* %0, i64 %40
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %48, i64 2
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %50, <2 x double> %27)
%55 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %29, <2 x double> %53, <2 x double> %31)
%56 = fsub <2 x double> %44, %54
%57 = fsub <2 x double> %47, %55
%58 = getelementptr inbounds double, double* %5, i64 %40
%59 = bitcast double* %58 to <2 x double>*
store <2 x double> %56, <2 x double>* %59
%60 = getelementptr inbounds double, double* %58, i64 2
%61 = bitcast double* %60 to <2 x double>*
store <2 x double> %57, <2 x double>* %61
%62 = or i64 %40, 4
%63 = getelementptr inbounds double, double* %1, i64 %62
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = getelementptr inbounds double, double* %63, i64 2
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = getelementptr inbounds double, double* %0, i64 %62
%70 = bitcast double* %69 to <2 x double>*
%71 = load <2 x double>, <2 x double>* %70
%72 = getelementptr inbounds double, double* %69, i64 2
%73 = bitcast double* %72 to <2 x double>*
%74 = load <2 x double>, <2 x double>* %73
%75 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %71, <2 x double> %27)
%76 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %29, <2 x double> %74, <2 x double> %31)
%77 = fsub <2 x double> %65, %75
%78 = fsub <2 x double> %68, %76
%79 = getelementptr inbounds double, double* %5, i64 %62
%80 = bitcast double* %79 to <2 x double>*
store <2 x double> %77, <2 x double>* %80
%81 = getelementptr inbounds double, double* %79, i64 2
%82 = bitcast double* %81 to <2 x double>*
store <2 x double> %78, <2 x double>* %82
%83 = add nuw i64 %40, 8
%84 = add i64 %41, 2
%85 = icmp eq i64 %84, %38
br i1 %85, label %86, label %39
86: ; preds = %39, %22
%87 = phi i64 [ 0, %22 ], [ %83, %39 ]
%88 = icmp eq i64 %35, 0
br i1 %88, label %110, label %89
89: ; preds = %86
%90 = getelementptr inbounds double, double* %1, i64 %87
%91 = bitcast double* %90 to <2 x double>*
%92 = load <2 x double>, <2 x double>* %91
%93 = getelementptr inbounds double, double* %90, i64 2
%94 = bitcast double* %93 to <2 x double>*
%95 = load <2 x double>, <2 x double>* %94
%96 = getelementptr inbounds double, double* %0, i64 %87
%97 = bitcast double* %96 to <2 x double>*
%98 = load <2 x double>, <2 x double>* %97
%99 = getelementptr inbounds double, double* %96, i64 2
%100 = bitcast double* %99 to <2 x double>*
%101 = load <2 x double>, <2 x double>* %100
%102 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %98, <2 x double> %27)
%103 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %29, <2 x double> %101, <2 x double> %31)
%104 = fsub <2 x double> %92, %102
%105 = fsub <2 x double> %95, %103
%106 = getelementptr inbounds double, double* %5, i64 %87
%107 = bitcast double* %106 to <2 x double>*
store <2 x double> %104, <2 x double>* %107
%108 = getelementptr inbounds double, double* %106, i64 2
%109 = bitcast double* %108 to <2 x double>*
store <2 x double> %105, <2 x double>* %109
br label %110
110: ; preds = %86, %89
%111 = icmp eq i64 %23, %9
br i1 %111, label %130, label %112
112: ; preds = %11, %8, %110
%113 = phi i64 [ 0, %11 ], [ 0, %8 ], [ %23, %110 ]
%114 = xor i64 %113, -1
%115 = and i64 %9, 1
%116 = icmp eq i64 %115, 0
br i1 %116, label %126, label %117
117: ; preds = %112
%118 = getelementptr inbounds double, double* %1, i64 %113
%119 = load double, double* %118
%120 = getelementptr inbounds double, double* %0, i64 %113
%121 = load double, double* %120
%122 = tail call double @llvm.fmuladd.f64(double %3, double %121, double %4)
%123 = fsub double %119, %122
%124 = getelementptr inbounds double, double* %5, i64 %113
store double %123, double* %124
%125 = or i64 %113, 1
br label %126
126: ; preds = %117, %112
%127 = phi i64 [ %113, %112 ], [ %125, %117 ]
%128 = sub nsw i64 0, %9
%129 = icmp eq i64 %114, %128
br i1 %129, label %130, label %131
130: ; preds = %126, %131, %110, %6
ret void
131: ; preds = %126, %131
%132 = phi i64 [ %148, %131 ], [ %127, %126 ]
%133 = getelementptr inbounds double, double* %1, i64 %132
%134 = load double, double* %133
%135 = getelementptr inbounds double, double* %0, i64 %132
%136 = load double, double* %135
%137 = tail call double @llvm.fmuladd.f64(double %3, double %136, double %4)
%138 = fsub double %134, %137
%139 = getelementptr inbounds double, double* %5, i64 %132
store double %138, double* %139
%140 = add nuw nsw i64 %132, 1
%141 = getelementptr inbounds double, double* %1, i64 %140
%142 = load double, double* %141
%143 = getelementptr inbounds double, double* %0, i64 %140
%144 = load double, double* %143
%145 = tail call double @llvm.fmuladd.f64(double %3, double %144, double %4)
%146 = fsub double %142, %145
%147 = getelementptr inbounds double, double* %5, i64 %140
store double %146, double* %147
%148 = add nuw nsw i64 %132, 2
%149 = icmp eq i64 %148, %9
br i1 %149, label %130, label %131
}