#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double calculate_cost(double **, double *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reset_coeff(double *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, double *);
char *strtok(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ train(double **, double *, int, double);
int main() {
  double data[506][14] = {0.0};
  double coeff[14] = {0.0};
  double cost[506] = {0.0};
  double alpha = 0.000001;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  char *token = NULL;
  char **tokens;
  int count = 0;
  int i, j, k;
  srand(time(NULL));
  FILE *f = fopen("../data/data.csv", "r");
  if (f == NULL) {
    printf("Failed to read file!\nExiting...\n");
    return -1;
  }
  while ((read = getline(&line, &len, f)) != -1) {
    count++;
    if (0 == 1) {
      printf("Retrieved line of length %zu Count : %d:\n", read, count);
      printf("%s", line);
    }
    token = strtok(line, ",");
    sscanf(token, "%lf", &data[count - 1][0]);
    for (i = 1; i < 14; i++) {
      token = strtok(NULL, ",");
      sscanf(token, "%lf", &data[count - 1][i]);
    }
  }
  fclose(f);
  if (0 == 1) {
    printf("Data Matrix: \n");
    for (i = 0; i < 506; i++) {
      for (j = 0; j < 14; j++)
        printf("%lf  ", data[i][j]);
      printf("\n");
    }
  }
  FILE *f2 = fopen("../data/all_cost.dat", "w");
  double temp_cost = 0.0;
  printf("Calculation is started...\n\n");
  reset_coeff(coeff);
  for (i = 1; i <= 506; i++) {
    for (j = 0; j < 5; j++) {
      train(data, coeff, i, alpha);
      temp_cost = temp_cost + calculate_cost(data, coeff);
      reset_coeff(coeff);
    }
    cost[i - 1] = temp_cost / 5.0;
    temp_cost = 0.0;
    fprintf(f2, "%.12e\n", cost[i - 1]);
    printf("For %d samples, the cost is %f\n", i, cost[i - 1]);
  }
  printf("\n\n The cost data for %d different samples are written into "
         "all_cost.dat file!\n\nExiting..\n",
         506);
  fclose(f2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xee10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xdd70(%rbp),%rdi
xor    %esi,%esi
mov    $0xdd60,%edx
call   1050 <memset@plt>
lea    -0xdde0(%rbp),%rdi
xor    %esi,%esi
mov    $0x70,%edx
call   1050 <memset@plt>
lea    -0xedb0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfd0,%edx
call   1050 <memset@plt>
movsd  0xddd(%rip),%xmm0
movsd  %xmm0,-0xedb8(%rbp)
ff
movq   $0x0,-0xedc0(%rbp)
movq   $0x0,-0xedc8(%rbp)
movq   $0x0,-0xedd8(%rbp)
movl   $0x0,-0xede4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xda3(%rip),%rdi
lea    0xdad(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xedf8(%rbp)
cmpq   $0x0,-0xedf8(%rbp)
jne    12a8 <main+0xd8>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1558 <main+0x388>
jmp    12ad <main+0xdd>
mov    -0xedf8(%rbp),%rdx
lea    -0xedc0(%rbp),%rdi
lea    -0xedc8(%rbp),%rsi
call   10f0 <getline@plt>
mov    %eax,-0xedcc(%rbp)
cmp    $0xffffffff,%eax
je     13ac <main+0x1dc>
mov    -0xede4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xede4(%rbp)
mov    -0xedc0(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0xedd8(%rbp)
mov    -0xedd8(%rbp),%rdi
mov    -0xede4(%rbp),%eax
sub    $0x1,%eax
cltq
lea    -0xdd70(%rbp),%rdx
imul   $0x70,%rax,%rax
add    %rax,%rdx
lea    0xd20(%rip),%rsi
call   10b0 <sscanf@plt>
movl   $0x1,-0xede8(%rbp)
cmpl   $0xe,-0xede8(%rbp)
jge    13a7 <main+0x1d7>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcf7(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0xedd8(%rbp)
mov    -0xedd8(%rbp),%rdi
mov    -0xede4(%rbp),%eax
sub    $0x1,%eax
cltq
lea    -0xdd70(%rbp),%rdx
imul   $0x70,%rax,%rax
add    %rax,%rdx
movslq -0xede8(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xcb8(%rip),%rsi
call   10b0 <sscanf@plt>
mov    -0xede8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xede8(%rbp)
jmp    1335 <main+0x165>
jmp    12ad <main+0xdd>
mov    -0xedf8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xc8b(%rip),%rdi
lea    0xc99(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xee00(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xee08(%rbp)
ff
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xdde0(%rbp),%rdi
call   10c0 <reset_coeff@plt>
movl   $0x1,-0xede8(%rbp)
cmpl   $0x1fa,-0xede8(%rbp)
jg     1539 <main+0x369>
movl   $0x0,-0xedec(%rbp)
cmpl   $0x5,-0xedec(%rbp)
jge    14a3 <main+0x2d3>
lea    -0xdd70(%rbp),%rdi
lea    -0xdde0(%rbp),%rsi
mov    -0xede8(%rbp),%edx
movsd  -0xedb8(%rbp),%xmm0
ff
call   1090 <train@plt>
movsd  -0xee08(%rbp),%xmm0
ff
movsd  %xmm0,-0xee10(%rbp)
ff
lea    -0xdd70(%rbp),%rdi
lea    -0xdde0(%rbp),%rsi
call   10a0 <calculate_cost@plt>
movaps %xmm0,%xmm1
movsd  -0xee10(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xee08(%rbp)
ff
lea    -0xdde0(%rbp),%rdi
call   10c0 <reset_coeff@plt>
mov    -0xedec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xedec(%rbp)
jmp    141b <main+0x24b>
movsd  -0xee08(%rbp),%xmm0
ff
movsd  0xb55(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0xede8(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  %xmm0,-0xedb0(%rbp,%rax,8)
ff ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xee08(%rbp)
ff
mov    -0xee00(%rbp),%rdi
mov    -0xede8(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0xedb0(%rbp,%rax,8),%xmm0
ff ff
lea    0xb85(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0xede8(%rbp),%esi
mov    -0xede8(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0xedb0(%rbp,%rax,8),%xmm0
ff ff
lea    0xb66(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0xede8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xede8(%rbp)
jmp    1401 <main+0x231>
lea    0xb64(%rip),%rdi
mov    $0x1fa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xee00(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xee10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xddf8,%rsp
lea    0x90(%rsp),%rbx
mov    $0xdd60,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0xdc0(%rip),%rdi
lea    0xdca(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     15e5 <main+0x405>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   1100 <getline@plt>
cmp    $0xffffffff,%eax
je     142b <main+0x24b>
lea    0xd99(%rip),%r15
lea    0xd94(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x18(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%rdi
mov    %r15,%rsi
call   10f0 <strtok@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x8(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x10(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x18(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x20(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x28(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x30(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x38(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x40(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x48(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x50(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x58(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x60(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
lea    0x68(%rbx),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <sscanf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1100 <getline@plt>
add    $0x70,%rbx
cmp    $0xffffffff,%eax
jne    12b0 <main+0xd0>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xbf7(%rip),%rdi
lea    0xc05(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r14
lea    0xc79(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   10d0 <reset_coeff@plt>
mov    $0x1,%ebx
lea    0x90(%rsp),%r15
lea    0xbd2(%rip),%r12
lea    0xbd2(%rip),%r13
nopl   (%rax)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
movsd  0xb70(%rip),%xmm0
call   10a0 <train@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10b0 <calculate_cost@plt>
addsd  0xb68(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
call   10d0 <reset_coeff@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
movsd  0xb3a(%rip),%xmm0
call   10a0 <train@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10b0 <calculate_cost@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
call   10d0 <reset_coeff@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
movsd  0xb06(%rip),%xmm0
call   10a0 <train@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10b0 <calculate_cost@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
call   10d0 <reset_coeff@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
movsd  0xad2(%rip),%xmm0
call   10a0 <train@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10b0 <calculate_cost@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
call   10d0 <reset_coeff@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
movsd  0xa9e(%rip),%xmm0
call   10a0 <train@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10b0 <calculate_cost@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
call   10d0 <reset_coeff@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xa74(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <fprintf@plt>
mov    %r13,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebx
cmp    $0x1fb,%ebx
jne    1480 <main+0x2a0>
lea    0xaa2(%rip),%rdi
xor    %ebx,%ebx
mov    $0x1fa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    15f6 <main+0x416>
lea    0xaf8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xddf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"../data/data.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Failed to read file!\0AExiting...\0A\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [21 x i8] c"../data/all_cost.dat\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [28 x i8] c"Calculation is started...\0A\0A\00"
@.str.8 = [7 x i8] c"%.12e\0A\00"
@.str.9 = [32 x i8] c"For %d samples, the cost is %f\0A\00"
@.str.10 = [90 x i8] c"\0A\0A The cost data for %d different samples are written into all_cost.dat file!\0A\0AExiting..\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [506 x [14 x double]]
%3 = alloca [14 x double]
%4 = alloca [506 x double]
%5 = alloca double
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca double
store i32 0, i32* %1
%18 = bitcast [506 x [14 x double]]* %2 to i8*
%19 = bitcast [14 x double]* %3 to i8*
%20 = bitcast [506 x double]* %4 to i8*
store double 0x3EB0C6F7A0B5ED8D, double* %5
store i8* null, i8** %6
store i64 0, i64* %7
store i8* null, i8** %9
store i32 0, i32* %11
%21 = call i32 @time(i32* null)
%22 = call i32 @srand(i32 %21)
%23 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %15
%24 = load i32*, i32** %15
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %123
28: ; preds = %0
br label %29
29: ; preds = %62, %28
%30 = load i32*, i32** %15
%31 = call i32 @getline(i8** %6, i64* %7, i32* %30)
store i32 %31, i32* %8
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %63
33: ; preds = %29
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
%36 = load i8*, i8** %6
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = load i32, i32* %11
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %2, i64 0, i64 %41
%43 = getelementptr inbounds [14 x double], [14 x double]* %42, i64 0, i64 0
%44 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %43)
store i32 1, i32* %12
br label %45
45: ; preds = %59, %33
%46 = load i32, i32* %12
%47 = icmp slt i32 %46, 14
br i1 %47, label %48, label %62
48: ; preds = %45
%49 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %49, i8** %9
%50 = load i8*, i8** %9
%51 = load i32, i32* %11
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %2, i64 0, i64 %53
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [14 x double], [14 x double]* %54, i64 0, i64 %56
%58 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %57)
br label %59
59: ; preds = %48
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
store i32 %61, i32* %12
br label %45
62: ; preds = %45
br label %29
63: ; preds = %29
%64 = load i32*, i32** %15
%65 = call i32 @fclose(i32* %64)
%66 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %66, i32** %16
store double 0.000000e+00, double* %17
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%68 = getelementptr inbounds [14 x double], [14 x double]* %3, i64 0, i64 0
%69 = call i32 @reset_coeff(double* %68)
store i32 1, i32* %12
br label %70
70: ; preds = %116, %63
%71 = load i32, i32* %12
%72 = icmp sle i32 %71, 506
br i1 %72, label %73, label %119
73: ; preds = %70
store i32 0, i32* %13
br label %74
74: ; preds = %92, %73
%75 = load i32, i32* %13
%76 = icmp slt i32 %75, 5
br i1 %76, label %77, label %95
77: ; preds = %74
%78 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %2, i64 0, i64 0
%79 = bitcast [14 x double]* %78 to double**
%80 = getelementptr inbounds [14 x double], [14 x double]* %3, i64 0, i64 0
%81 = load i32, i32* %12
%82 = load double, double* %5
%83 = call i32 @train(double** %79, double* %80, i32 %81, double %82)
%84 = load double, double* %17
%85 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %2, i64 0, i64 0
%86 = bitcast [14 x double]* %85 to double**
%87 = getelementptr inbounds [14 x double], [14 x double]* %3, i64 0, i64 0
%88 = call double @calculate_cost(double** %86, double* %87)
%89 = fadd double %84, %88
store double %89, double* %17
%90 = getelementptr inbounds [14 x double], [14 x double]* %3, i64 0, i64 0
%91 = call i32 @reset_coeff(double* %90)
br label %92
92: ; preds = %77
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
store i32 %94, i32* %13
br label %74
95: ; preds = %74
%96 = load double, double* %17
%97 = fdiv double %96, 5.000000e+00
%98 = load i32, i32* %12
%99 = sub nsw i32 %98, 1
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [506 x double], [506 x double]* %4, i64 0, i64 %100
store double %97, double* %101
store double 0.000000e+00, double* %17
%102 = load i32*, i32** %16
%103 = load i32, i32* %12
%104 = sub nsw i32 %103, 1
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [506 x double], [506 x double]* %4, i64 0, i64 %105
%107 = load double, double* %106
%108 = call i32 @fprintf(i32* %102, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), double %107)
%109 = load i32, i32* %12
%110 = load i32, i32* %12
%111 = sub nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [506 x double], [506 x double]* %4, i64 0, i64 %112
%114 = load double, double* %113
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %109, double %114)
br label %116
116: ; preds = %95
%117 = load i32, i32* %12
%118 = add nsw i32 %117, 1
store i32 %118, i32* %12
br label %70
119: ; preds = %70
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.10, i64 0, i64 0), i32 506)
%121 = load i32*, i32** %16
%122 = call i32 @fclose(i32* %121)
br label %123
123: ; preds = %119, %26
%124 = load i32, i32* %1
ret i32 %124
}

LLVM IR (-O2):
@.str = [17 x i8] c"../data/data.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [21 x i8] c"../data/all_cost.dat\00"
@.str.6 = [2 x i8] c"w\00"
@.str.8 = [7 x i8] c"%.12e\0A\00"
@.str.9 = [32 x i8] c"For %d samples, the cost is %f\0A\00"
@.str.10 = [90 x i8] c"\0A\0A The cost data for %d different samples are written into all_cost.dat file!\0A\0AExiting..\0A\00"
@str = [27 x i8] c"Calculation is started...\0A\00"
@str.11 = [32 x i8] c"Failed to read file!\0AExiting...\00"
define i32 @main() {
%1 = alloca [506 x [14 x double]]
%2 = alloca [14 x double]
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast [506 x [14 x double]]* %1 to i8*
%6 = bitcast [14 x double]* %2 to i8*
%7 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = call i32 @getline(i8** %3, i64* %4, i32* %11)
%15 = icmp eq i32 %14, -1
br i1 %15, label %66, label %18
16: ; preds = %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0))
br label %103
18: ; preds = %13, %18
%19 = phi i64 [ %63, %18 ], [ 0, %13 ]
%20 = load i8*, i8** %3
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 0
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %22)
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 1
%26 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %25)
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 2
%29 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %28)
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 3
%32 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %31)
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 4
%35 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %34)
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 5
%38 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %37)
%39 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 6
%41 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %40)
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%43 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 7
%44 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %43)
%45 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 8
%47 = call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %46)
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%49 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 9
%50 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %49)
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%52 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 10
%53 = call i32 @sscanf(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %52)
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%55 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 11
%56 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %55)
%57 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%58 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 12
%59 = call i32 @sscanf(i8* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %58)
%60 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%61 = getelementptr inbounds [506 x [14 x double]], [506 x [14 x double]]* %1, i64 0, i64 %19, i64 13
%62 = call i32 @sscanf(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %61)
%63 = add nuw i64 %19, 1
%64 = call i32 @getline(i8** %3, i64* %4, i32* %11)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %18
66: ; preds = %18, %13
%67 = call i32 @fclose(i32* %11)
%68 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%70 = getelementptr inbounds [14 x double], [14 x double]* %2, i64 0, i64 0
%71 = call i32 @reset_coeff(double* %70)
%72 = bitcast [506 x [14 x double]]* %1 to double**
br label %73
73: ; preds = %66, %73
%74 = phi i32 [ 1, %66 ], [ %98, %73 ]
%75 = call i32 @train(double** %72, double* %70, i32 %74, double 0x3EB0C6F7A0B5ED8D)
%76 = call double @calculate_cost(double** %72, double* %70)
%77 = fadd double %76, 0.000000e+00
%78 = call i32 @reset_coeff(double* %70)
%79 = call i32 @train(double** %72, double* %70, i32 %74, double 0x3EB0C6F7A0B5ED8D)
%80 = call double @calculate_cost(double** %72, double* %70)
%81 = fadd double %77, %80
%82 = call i32 @reset_coeff(double* %70)
%83 = call i32 @train(double** %72, double* %70, i32 %74, double 0x3EB0C6F7A0B5ED8D)
%84 = call double @calculate_cost(double** %72, double* %70)
%85 = fadd double %81, %84
%86 = call i32 @reset_coeff(double* %70)
%87 = call i32 @train(double** %72, double* %70, i32 %74, double 0x3EB0C6F7A0B5ED8D)
%88 = call double @calculate_cost(double** %72, double* %70)
%89 = fadd double %85, %88
%90 = call i32 @reset_coeff(double* %70)
%91 = call i32 @train(double** %72, double* %70, i32 %74, double 0x3EB0C6F7A0B5ED8D)
%92 = call double @calculate_cost(double** %72, double* %70)
%93 = fadd double %89, %92
%94 = call i32 @reset_coeff(double* %70)
%95 = fdiv double %93, 5.000000e+00
%96 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), double %95)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %74, double %95)
%98 = add nuw nsw i32 %74, 1
%99 = icmp eq i32 %98, 507
br i1 %99, label %100, label %73
100: ; preds = %73
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @.str.10, i64 0, i64 0), i32 506)
%102 = call i32 @fclose(i32* %68)
br label %103
103: ; preds = %100, %16
%104 = phi i32 [ -1, %16 ], [ 0, %100 ]
ret i32 %104
}