#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 score(double *, double *);
int classify(double *pic, double weight[10][784]) {
  int ctr;
  int index = 0;
  double highestScore = 0, tmpScore;
  for (ctr = 0; ctr < 10; ctr++) {
    tmpScore = score(pic, (double *)weight[ctr]);
    if (tmpScore > highestScore) {
      index = ctr;
      highestScore = tmpScore;
    }
  }
  return index;
}


x86 assembly (clang, -O0):
<classify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1193 <classify+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
imul   $0x1880,%rax,%rax
add    %rax,%rsi
call   1030 <score@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1180 <classify+0x70>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1185 <classify+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <classify+0x26>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<classify>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <score@plt>
xorpd  %xmm1,%xmm1
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x1880(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
xor    %ebp,%ebp
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
seta   %bpl
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x3100(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x2,%ebx
cmovbe %ebp,%ebx
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x4980(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x3,%ebp
cmovbe %ebx,%ebp
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x6200(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x4,%ebx
cmovbe %ebp,%ebx
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x7a80(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x5,%ebp
cmovbe %ebx,%ebp
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x9300(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x6,%ebx
cmovbe %ebp,%ebx
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0xab80(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x7,%ebp
cmovbe %ebx,%ebp
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0xc400(%r15),%rsi
mov    %r14,%rdi
call   1030 <score@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x8,%ebx
cmovbe %ebp,%ebx
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
add    $0xdc80,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <score@plt>
ucomisd (%rsp),%xmm0
mov    $0x9,%eax
cmovbe %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @classify(double* %0, [784 x double]* %1) {
%3 = alloca double*
%4 = alloca [784 x double]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store double* %0, double** %3
store [784 x double]* %1, [784 x double]** %4
store i32 0, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %5
br label %9
9: ; preds = %27, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load double*, double** %3
%14 = load [784 x double]*, [784 x double]** %4
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [784 x double], [784 x double]* %14, i64 %16
%18 = getelementptr inbounds [784 x double], [784 x double]* %17, i64 0, i64 0
%19 = call double @score(double* %13, double* %18)
store double %19, double* %8
%20 = load double, double* %8
%21 = load double, double* %7
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* %5
store i32 %24, i32* %6
%25 = load double, double* %8
store double %25, double* %7
br label %26
26: ; preds = %23, %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %9
30: ; preds = %9
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
define i32 @classify(double* %0, [784 x double]* %1) {
%3 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 0, i64 0
%4 = tail call double @score(double* %0, double* %3)
%5 = fcmp ogt double %4, 0.000000e+00
%6 = select i1 %5, double %4, double 0.000000e+00
%7 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 1, i64 0
%8 = tail call double @score(double* %0, double* %7)
%9 = fcmp ogt double %8, %6
%10 = zext i1 %9 to i32
%11 = select i1 %9, double %8, double %6
%12 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 2, i64 0
%13 = tail call double @score(double* %0, double* %12)
%14 = fcmp ogt double %13, %11
%15 = select i1 %14, i32 2, i32 %10
%16 = select i1 %14, double %13, double %11
%17 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 3, i64 0
%18 = tail call double @score(double* %0, double* %17)
%19 = fcmp ogt double %18, %16
%20 = select i1 %19, i32 3, i32 %15
%21 = select i1 %19, double %18, double %16
%22 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 4, i64 0
%23 = tail call double @score(double* %0, double* %22)
%24 = fcmp ogt double %23, %21
%25 = select i1 %24, i32 4, i32 %20
%26 = select i1 %24, double %23, double %21
%27 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 5, i64 0
%28 = tail call double @score(double* %0, double* %27)
%29 = fcmp ogt double %28, %26
%30 = select i1 %29, i32 5, i32 %25
%31 = select i1 %29, double %28, double %26
%32 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 6, i64 0
%33 = tail call double @score(double* %0, double* %32)
%34 = fcmp ogt double %33, %31
%35 = select i1 %34, i32 6, i32 %30
%36 = select i1 %34, double %33, double %31
%37 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 7, i64 0
%38 = tail call double @score(double* %0, double* %37)
%39 = fcmp ogt double %38, %36
%40 = select i1 %39, i32 7, i32 %35
%41 = select i1 %39, double %38, double %36
%42 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 8, i64 0
%43 = tail call double @score(double* %0, double* %42)
%44 = fcmp ogt double %43, %41
%45 = select i1 %44, i32 8, i32 %40
%46 = select i1 %44, double %43, double %41
%47 = getelementptr inbounds [784 x double], [784 x double]* %1, i64 9, i64 0
%48 = tail call double @score(double* %0, double* %47)
%49 = fcmp ogt double %48, %46
%50 = select i1 %49, i32 9, i32 %45
ret i32 %50
}