#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 pow(double, int);
double sqrt(double);
void cost_iteration(double data[][14], double coeff[14], double cost_fn[10000],
                    int index) {
  int i, j;
  double hypothesis = 0.0;
  double err = 0.0;
  for (i = 0; i < 506; i++) {
    hypothesis = coeff[0];
    for (j = 1; j < 14; j++) {
      hypothesis = hypothesis + coeff[j] * data[i][j - 1];
    }
    err = err + pow((hypothesis - data[i][14 - 1]), 2);
  }
  cost_fn[index] = sqrt(err);
}


x86 assembly (clang, -O0):
<cost_iteration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1fa,-0x20(%rbp)
jge    120f <cost_iteration+0xef>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0xe,-0x24(%rbp)
jge    11c3 <cost_iteration+0xa3>
movsd  -0x30(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x70,%rcx,%rcx
add    %rcx,%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116f <cost_iteration+0x4f>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x70,%rcx,%rcx
add    %rcx,%rax
subsd  0x68(%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114e <cost_iteration+0x2e>
movsd  -0x38(%rbp),%xmm0
call   1040 <sqrt@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cost_iteration>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbp
xorpd  %xmm1,%xmm1
mov    $0x68,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%r12),%xmm0
movsd  0x10(%r12),%xmm1
mulsd  -0x68(%rbp,%rbx,1),%xmm0
addsd  (%r12),%xmm0
mulsd  -0x60(%rbp,%rbx,1),%xmm1
movsd  0x18(%r12),%xmm2
mulsd  -0x58(%rbp,%rbx,1),%xmm2
addsd  %xmm0,%xmm1
movsd  0x20(%r12),%xmm0
mulsd  -0x50(%rbp,%rbx,1),%xmm0
addsd  %xmm1,%xmm2
movsd  0x28(%r12),%xmm1
mulsd  -0x48(%rbp,%rbx,1),%xmm1
addsd  %xmm2,%xmm0
movsd  0x30(%r12),%xmm2
mulsd  -0x40(%rbp,%rbx,1),%xmm2
addsd  %xmm0,%xmm1
movsd  0x38(%r12),%xmm0
mulsd  -0x38(%rbp,%rbx,1),%xmm0
addsd  %xmm1,%xmm2
movsd  0x40(%r12),%xmm1
mulsd  -0x30(%rbp,%rbx,1),%xmm1
addsd  %xmm2,%xmm0
movsd  0x48(%r12),%xmm2
mulsd  -0x28(%rbp,%rbx,1),%xmm2
addsd  %xmm0,%xmm1
movsd  0x50(%r12),%xmm0
mulsd  -0x20(%rbp,%rbx,1),%xmm0
addsd  %xmm1,%xmm2
movsd  0x58(%r12),%xmm1
mulsd  -0x18(%rbp,%rbx,1),%xmm1
addsd  %xmm2,%xmm0
movsd  0x60(%r12),%xmm2
mulsd  -0x10(%rbp,%rbx,1),%xmm2
addsd  %xmm0,%xmm1
movsd  0x68(%r12),%xmm0
mulsd  -0x8(%rbp,%rbx,1),%xmm0
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
subsd  0x0(%rbp,%rbx,1),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
add    $0x70,%rbx
cmp    $0xddc8,%rbx
jne    1150 <cost_iteration+0x30>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1273 <cost_iteration+0x153>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    127c <cost_iteration+0x15c>
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
movslq %r15d,%rax
movsd  %xmm0,(%r14,%rax,8)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cost_iteration([14 x double]* %0, double* %1, double* %2, i32 %3) {
%5 = alloca [14 x double]*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store [14 x double]* %0, [14 x double]** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store i32 0, i32* %9
br label %13
13: ; preds = %55, %4
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 506
br i1 %15, label %16, label %58
16: ; preds = %13
%17 = load double*, double** %6
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
store double %19, double* %11
store i32 1, i32* %10
br label %20
20: ; preds = %40, %16
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 14
br i1 %22, label %23, label %43
23: ; preds = %20
%24 = load double, double* %11
%25 = load double*, double** %6
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load [14 x double]*, [14 x double]** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [14 x double], [14 x double]* %30, i64 %32
%34 = load i32, i32* %10
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [14 x double], [14 x double]* %33, i64 0, i64 %36
%38 = load double, double* %37
%39 = call double @llvm.fmuladd.f64(double %29, double %38, double %24)
store double %39, double* %11
br label %40
40: ; preds = %23
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %20
43: ; preds = %20
%44 = load double, double* %12
%45 = load double, double* %11
%46 = load [14 x double]*, [14 x double]** %5
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [14 x double], [14 x double]* %46, i64 %48
%50 = getelementptr inbounds [14 x double], [14 x double]* %49, i64 0, i64 13
%51 = load double, double* %50
%52 = fsub double %45, %51
%53 = call double @pow(double %52, i32 2)
%54 = fadd double %44, %53
store double %54, double* %12
br label %55
55: ; preds = %43
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %13
58: ; preds = %13
%59 = load double, double* %12
%60 = call double @sqrt(double %59)
%61 = load double*, double** %7
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
store double %60, double* %64
ret void
}

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