double score(double *pic, double *weight) {
  int picDim = 784;
  int ctr;
  double score = 0;
  for (ctr = 0; ctr < picDim; ctr++) {
    if (pic[ctr] > 0) {
      score += weight[ctr];
    }
  }
  return score;
}


x86 assembly (clang, -O0):
<score>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x310,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1172 <score+0x72>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    115f <score+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1164 <score+0x64>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1122 <score+0x22>
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<score>:
xorpd  %xmm1,%xmm1
mov    $0x1,%eax
xorpd  %xmm0,%xmm0
jmp    111c <score+0x1c>
nop
add    $0x2,%rax
cmp    $0x311,%rax
je     1140 <score+0x40>
movsd  -0x8(%rdi,%rax,8),%xmm2
ucomisd %xmm1,%xmm2
jbe    112e <score+0x2e>
addsd  -0x8(%rsi,%rax,8),%xmm0
movsd  (%rdi,%rax,8),%xmm2
ucomisd %xmm1,%xmm2
jbe    1110 <score+0x10>
addsd  (%rsi,%rax,8),%xmm0
jmp    1110 <score+0x10>
ret

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

LLVM IR (-O2):
define double @score(double* nocapture %0, double* nocapture %1) {
br label %3
3: ; preds = %23, %2
%4 = phi i64 [ 0, %2 ], [ %25, %23 ]
%5 = phi double [ 0.000000e+00, %2 ], [ %24, %23 ]
%6 = getelementptr inbounds double, double* %0, i64 %4
%7 = load double, double* %6
%8 = fcmp ogt double %7, 0.000000e+00
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = getelementptr inbounds double, double* %1, i64 %4
%11 = load double, double* %10
%12 = fadd double %5, %11
br label %13
13: ; preds = %3, %9
%14 = phi double [ %12, %9 ], [ %5, %3 ]
%15 = or i64 %4, 1
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = getelementptr inbounds double, double* %1, i64 %15
%21 = load double, double* %20
%22 = fadd double %14, %21
br label %23
23: ; preds = %19, %13
%24 = phi double [ %22, %19 ], [ %14, %13 ]
%25 = add nuw nsw i64 %4, 2
%26 = icmp eq i64 %25, 784
br i1 %26, label %27, label %3
27: ; preds = %23
ret double %24
}