#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 */
struct SimpleNet {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fullPass(double *, struct SimpleNet *);
int /*<<< orphan*/ printf(char *, int, int, ...);
int selectFromOutput(struct SimpleNet *);
void TestForwardPass(double **data, int dataRowNum, struct SimpleNet *net) {
  int counter1, counter2, rightAns = 0, wrongAns = 0;
  for (counter1 = 0; counter1 < dataRowNum; counter1++) {
    double *pic = (double *)data[counter1];
    pic++;
    fullPass(pic, net);
    int maxAt = selectFromOutput(net);
    printf("Select %d as %d is right\n", maxAt, (int)data[counter1][0]);
    if (maxAt == (int)data[counter1][0])
      rightAns++;
    else
      wrongAns++;
  }
  printf("\n%d right answer among %d pics in training data, you scored %lf",
         rightAns, dataRowNum, (rightAns * 1.0 / dataRowNum));
}


x86 assembly (clang, -O0):
<TestForwardPass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ff <TestForwardPass+0xcf>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <fullPass@plt>
mov    -0x18(%rbp),%rdi
call   1050 <selectFromOutput@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cvttsd2si (%rax),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
cvttsd2si (%rcx),%ecx
cmp    %ecx,%eax
jne    11e3 <TestForwardPass+0xb3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ec <TestForwardPass+0xbc>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f1 <TestForwardPass+0xc1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <TestForwardPass+0x28>
mov    -0x24(%rbp),%esi
mov    -0xc(%rbp),%edx
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xdee(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestForwardPass>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
mov    %esi,0x4(%rsp)
jle    11b1 <TestForwardPass+0x81>
mov    %rdx,%r15
mov    %rdi,%r13
mov    %esi,%r14d
xor    %r12d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%r12,8),%rdi
add    $0x8,%rdi
mov    %r15,%rsi
call   1030 <fullPass@plt>
mov    %r15,%rdi
call   1050 <selectFromOutput@plt>
mov    %eax,%ebx
mov    0x0(%r13,%r12,8),%rax
cvttsd2si (%rax),%edx
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13,%r12,8),%rax
cvttsd2si (%rax),%eax
xor    %ecx,%ecx
cmp    %eax,%ebx
sete   %cl
add    %ecx,%ebp
add    $0x1,%r12
cmp    %r12,%r14
jne    1160 <TestForwardPass+0x30>
jmp    11b3 <TestForwardPass+0x83>
xor    %ebp,%ebp
cvtsi2sd %ebp,%xmm0
mov    0x4(%rsp),%edx
cvtsi2sd %edx,%xmm1
divsd  %xmm1,%xmm0
lea    0xe50(%rip),%rdi
mov    %ebp,%esi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.SimpleNet = type { i32 }
@.str = [26 x i8] c"Select %d as %d is right\0A\00"
@.str.1 = [64 x i8] c"\0A%d right answer among %d pics in training data, you scored %lf\00"
define void @TestForwardPass(double** %0, i32 %1, %struct.SimpleNet* %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca %struct.SimpleNet*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store %struct.SimpleNet* %2, %struct.SimpleNet** %6
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %7
br label %13
13: ; preds = %57, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %60
17: ; preds = %13
%18 = load double**, double*** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double*, double** %18, i64 %20
%22 = load double*, double** %21
store double* %22, double** %11
%23 = load double*, double** %11
%24 = getelementptr inbounds double, double* %23, i32 1
store double* %24, double** %11
%25 = load double*, double** %11
%26 = load %struct.SimpleNet*, %struct.SimpleNet** %6
%27 = call i32 @fullPass(double* %25, %struct.SimpleNet* %26)
%28 = load %struct.SimpleNet*, %struct.SimpleNet** %6
%29 = call i32 @selectFromOutput(%struct.SimpleNet* %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = load double**, double*** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = getelementptr inbounds double, double* %35, i64 0
%37 = load double, double* %36
%38 = fptosi double %37 to i32
%39 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %38)
%40 = load i32, i32* %12
%41 = load double**, double*** %4
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double*, double** %41, i64 %43
%45 = load double*, double** %44
%46 = getelementptr inbounds double, double* %45, i64 0
%47 = load double, double* %46
%48 = fptosi double %47 to i32
%49 = icmp eq i32 %40, %48
br i1 %49, label %50, label %53
50: ; preds = %17
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %56
53: ; preds = %17
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %56
56: ; preds = %53, %50
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %13
60: ; preds = %13
%61 = load i32, i32* %9
%62 = load i32, i32* %5
%63 = load i32, i32* %9
%64 = sitofp i32 %63 to double
%65 = fmul double %64, 1.000000e+00
%66 = load i32, i32* %5
%67 = sitofp i32 %66 to double
%68 = fdiv double %65, %67
%69 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %61, i32 %62, double %68)
ret void
}

LLVM IR (-O2):
%struct.SimpleNet = type { i32 }
@.str = [26 x i8] c"Select %d as %d is right\0A\00"
@.str.1 = [64 x i8] c"\0A%d right answer among %d pics in training data, you scored %lf\00"
define void @TestForwardPass(double** nocapture %0, i32 %1, %struct.SimpleNet* %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %27
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %25, %7 ]
%9 = phi i32 [ 0, %5 ], [ %24, %7 ]
%10 = getelementptr inbounds double*, double** %0, i64 %8
%11 = load double*, double** %10
%12 = getelementptr inbounds double, double* %11, i64 1
%13 = tail call i32 @fullPass(double* %12, %struct.SimpleNet* %2)
%14 = tail call i32 @selectFromOutput(%struct.SimpleNet* %2)
%15 = load double*, double** %10
%16 = load double, double* %15
%17 = fptosi double %16 to i32
%18 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %17)
%19 = load double*, double** %10
%20 = load double, double* %19
%21 = fptosi double %20 to i32
%22 = icmp eq i32 %14, %21
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %9, %23
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %7, %3
%28 = phi i32 [ 0, %3 ], [ %24, %7 ]
%29 = sitofp i32 %28 to double
%30 = sitofp i32 %1 to double
%31 = fdiv double %29, %30
%32 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %1, double %31)
ret void
}