#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 scalar_t__ clock_t;

/* Variables and functions */
scalar_t__ CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readInMiniData(double ***, int);
int /*<<< orphan*/ validate(double **, double **, int);
int /*<<< orphan*/ vote(double *, double **, double **, int);
int /*<<< orphan*/ weighting(double *, double **, double **);
int main() {
  clock_t beginTime = clock();
  double **trainingData, **testData;
  int trainingPicNum = 42000;
  readInMiniData(&trainingData, trainingPicNum);
  printf("Succefully read in data\n\n");
  double occurrance[10] = {0};
  double voting[10][784] = {0};
  vote(occurrance, voting, trainingData, trainingPicNum);
  double weight[10][784] = {0};
  weighting(occurrance, voting, weight);
  validate(trainingData, weight, trainingPicNum);
  clock_t endTime = clock();
  printf("Total time elapsed %lf seconds\n\n",
         (double)(endTime - beginTime) / (double)CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1ea90,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
movl   $0xa410,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1090 <readInMiniData@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
lea    -0xf580(%rbp),%rdi
xor    %esi,%esi
mov    $0xf500,%edx
call   1060 <memset@plt>
lea    -0x80(%rbp),%rdi
lea    -0xf580(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1070 <vote@plt>
lea    -0x1ea80(%rbp),%rdi
xor    %esi,%esi
mov    $0xf500,%edx
call   1060 <memset@plt>
lea    -0x80(%rbp),%rdi
lea    -0xf580(%rbp),%rsi
lea    -0x1ea80(%rbp),%rdx
call   1040 <weighting@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1ea80(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <validate@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x1ea88(%rbp)
mov    -0x1ea88(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d9e(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xdc0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x1ea90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1ea68,%rsp
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
mov    $0xa410,%esi
call   10a0 <readInMiniData@plt>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xf560(%rsp),%r12
mov    $0xf500,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x8(%rsp),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xa410,%ecx
call   1080 <vote@plt>
lea    0x60(%rsp),%rbx
mov    $0xf500,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <weighting@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0xa410,%edx
call   1090 <validate@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2d9b(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xda3(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1ea68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Succefully read in data\0A\0A\00"
@.str.1 = [33 x i8] c"Total time elapsed %lf seconds\0A\0A\00"
@CLOCKS_PER_SEC = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca double**
%4 = alloca double**
%5 = alloca i32
%6 = alloca [10 x double]
%7 = alloca [10 x [784 x double]]
%8 = alloca [10 x [784 x double]]
%9 = alloca i64
store i32 0, i32* %1
%10 = call i64 (...) @clock()
store i64 %10, i64* %2
store i32 42000, i32* %5
%11 = load i32, i32* %5
%12 = call i32 @readInMiniData(double*** %3, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = bitcast [10 x double]* %6 to i8*
%15 = bitcast [10 x [784 x double]]* %7 to i8*
%16 = getelementptr inbounds [10 x double], [10 x double]* %6, i64 0, i64 0
%17 = getelementptr inbounds [10 x [784 x double]], [10 x [784 x double]]* %7, i64 0, i64 0
%18 = bitcast [784 x double]* %17 to double**
%19 = load double**, double*** %3
%20 = load i32, i32* %5
%21 = call i32 @vote(double* %16, double** %18, double** %19, i32 %20)
%22 = bitcast [10 x [784 x double]]* %8 to i8*
%23 = getelementptr inbounds [10 x double], [10 x double]* %6, i64 0, i64 0
%24 = getelementptr inbounds [10 x [784 x double]], [10 x [784 x double]]* %7, i64 0, i64 0
%25 = bitcast [784 x double]* %24 to double**
%26 = getelementptr inbounds [10 x [784 x double]], [10 x [784 x double]]* %8, i64 0, i64 0
%27 = bitcast [784 x double]* %26 to double**
%28 = call i32 @weighting(double* %23, double** %25, double** %27)
%29 = load double**, double*** %3
%30 = getelementptr inbounds [10 x [784 x double]], [10 x [784 x double]]* %8, i64 0, i64 0
%31 = bitcast [784 x double]* %30 to double**
%32 = load i32, i32* %5
%33 = call i32 @validate(double** %29, double** %31, i32 %32)
%34 = call i64 (...) @clock()
store i64 %34, i64* %9
%35 = load i64, i64* %9
%36 = load i64, i64* %2
%37 = sub nsw i64 %35, %36
%38 = sitofp i64 %37 to double
%39 = load i64, i64* @CLOCKS_PER_SEC
%40 = sitofp i64 %39 to double
%41 = fdiv double %38, %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %41)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c"Total time elapsed %lf seconds\0A\0A\00"
@CLOCKS_PER_SEC = global i64 0
@str = [25 x i8] c"Succefully read in data\0A\00"
define i32 @main() {
%1 = alloca double**
%2 = alloca [10 x double]
%3 = alloca [10 x [784 x double]]
%4 = alloca [10 x [784 x double]]
%5 = tail call i64 (...) @clock()
%6 = bitcast double*** %1 to i8*
%7 = call i32 @readInMiniData(double*** %1, i32 42000)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%9 = bitcast [10 x double]* %2 to i8*
%10 = bitcast [10 x [784 x double]]* %3 to i8*
%11 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%12 = bitcast [10 x [784 x double]]* %3 to double**
%13 = load double**, double*** %1
%14 = call i32 @vote(double* %11, double** %12, double** %13, i32 42000)
%15 = bitcast [10 x [784 x double]]* %4 to i8*
%16 = bitcast [10 x [784 x double]]* %4 to double**
%17 = call i32 @weighting(double* %11, double** %12, double** %16)
%18 = load double**, double*** %1
%19 = call i32 @validate(double** %18, double** %16, i32 42000)
%20 = call i64 (...) @clock()
%21 = sub nsw i64 %20, %5
%22 = sitofp i64 %21 to double
%23 = load i64, i64* @CLOCKS_PER_SEC
%24 = sitofp i64 %23 to double
%25 = fdiv double %22, %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %25)
ret i32 0
}