#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 */
int classify(double *, double **);
int /*<<< orphan*/ printf(char *, int, int);
void validate(double **trainingData, double weight[10][784],
              int trainingPicNum) {
  int ctr0, ctr1;
  int correctRes = 0, wrongRes = 0;
  for (ctr0 = 0; ctr0 < trainingPicNum; ctr0++) {
    int resIndex = classify(trainingData[ctr0] + 1, weight);
    if (resIndex == trainingData[ctr0][0]) {
      correctRes++;
    } else {
      wrongRes++;
    }
  }
  printf("We get %d correct judgements among %d pictures\n\n", correctRes,
         trainingPicNum);
}


x86 assembly (clang, -O0):
<validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bb <validate+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x8,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <classify@plt>
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
ucomisd (%rax),%xmm0
jne    119f <validate+0x7f>
jp     119f <validate+0x7f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a8 <validate+0x88>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ad <validate+0x8d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1148 <validate+0x28>
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
test   %edx,%edx
jle    1174 <validate+0x54>
mov    %rsi,%r15
mov    %rdi,%r13
mov    %r14d,%r12d
xor    %ebp,%ebp
xor    %ebx,%ebx
nop
mov    0x0(%r13,%rbp,8),%rdi
add    $0x8,%rdi
mov    %r15,%rsi
call   1040 <classify@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0x0(%r13,%rbp,8),%rax
cmpeqsd (%rax),%xmm0
movq   %xmm0,%rax
sub    %eax,%ebx
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1140 <validate+0x20>
jmp    1176 <validate+0x56>
xor    %ebx,%ebx
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"We get %d correct judgements among %d pictures\0A\0A\00"
define void @validate(double** %0, [784 x double]* %1, i32 %2) {
%4 = alloca double**
%5 = alloca [784 x double]*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double** %0, double*** %4
store [784 x double]* %1, [784 x double]** %5
store i32 %2, i32* %6
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %7
br label %12
12: ; preds = %43, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %46
16: ; preds = %12
%17 = load double**, double*** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double*, double** %17, i64 %19
%21 = load double*, double** %20
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load [784 x double]*, [784 x double]** %5
%24 = bitcast [784 x double]* %23 to double**
%25 = call i32 @classify(double* %22, double** %24)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = sitofp i32 %26 to double
%28 = load double**, double*** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = getelementptr inbounds double, double* %32, i64 0
%34 = load double, double* %33
%35 = fcmp oeq double %27, %34
br i1 %35, label %36, label %39
36: ; preds = %16
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %42
39: ; preds = %16
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %12
46: ; preds = %12
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %48)
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"We get %d correct judgements among %d pictures\0A\0A\00"
define void @validate(double** nocapture %0, [784 x double]* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %23
5: ; preds = %3
%6 = bitcast [784 x double]* %1 to double**
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %21, %8 ]
%10 = phi i32 [ 0, %5 ], [ %20, %8 ]
%11 = getelementptr inbounds double*, double** %0, i64 %9
%12 = load double*, double** %11
%13 = getelementptr inbounds double, double* %12, i64 1
%14 = tail call i32 @classify(double* %13, double** %6)
%15 = sitofp i32 %14 to double
%16 = load double*, double** %11
%17 = load double, double* %16
%18 = fcmp oeq double %17, %15
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %10, %19
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %8
23: ; preds = %8, %3
%24 = phi i32 [ 0, %3 ], [ %20, %8 ]
%25 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %2)
ret void
}