double DotProduct(A, B)
double *A;
double *B;
{
  int i;
  double score;
  score = 0;
  for (i = 0; i < 20; i++) {
    score = score + A[i] * B[i];
  }
  return score;
}


x86 assembly (clang, -O0):
<DotProduct>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    115f <DotProduct+0x5f>
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111b <DotProduct+0x1b>
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<DotProduct>:
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
mulsd  (%rsi),%xmm0
xorpd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  0x8(%rsi),%xmm1
addsd  %xmm2,%xmm1
movsd  0x10(%rdi),%xmm0
mulsd  0x10(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x18(%rdi),%xmm1
mulsd  0x18(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x20(%rdi),%xmm0
mulsd  0x20(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x28(%rdi),%xmm1
mulsd  0x28(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x30(%rdi),%xmm0
mulsd  0x30(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x38(%rdi),%xmm1
mulsd  0x38(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x40(%rdi),%xmm0
mulsd  0x40(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x48(%rdi),%xmm1
mulsd  0x48(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x50(%rdi),%xmm0
mulsd  0x50(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x58(%rdi),%xmm1
mulsd  0x58(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x60(%rdi),%xmm0
mulsd  0x60(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x68(%rdi),%xmm1
mulsd  0x68(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x70(%rdi),%xmm0
mulsd  0x70(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x78(%rdi),%xmm1
mulsd  0x78(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x80(%rdi),%xmm0
mulsd  0x80(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x88(%rdi),%xmm1
mulsd  0x88(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x90(%rdi),%xmm2
mulsd  0x90(%rsi),%xmm2
addsd  %xmm1,%xmm2
movsd  0x98(%rdi),%xmm0
mulsd  0x98(%rsi),%xmm0
addsd  %xmm2,%xmm0
ret

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

LLVM IR (-O2):
define double @DotProduct(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = load double, double* %1
%5 = tail call double @llvm.fmuladd.f64(double %3, double %4, double 0.000000e+00)
%6 = getelementptr inbounds double, double* %0, i64 1
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %1, i64 1
%9 = load double, double* %8
%10 = tail call double @llvm.fmuladd.f64(double %7, double %9, double %5)
%11 = getelementptr inbounds double, double* %0, i64 2
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %1, i64 2
%14 = load double, double* %13
%15 = tail call double @llvm.fmuladd.f64(double %12, double %14, double %10)
%16 = getelementptr inbounds double, double* %0, i64 3
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %1, i64 3
%19 = load double, double* %18
%20 = tail call double @llvm.fmuladd.f64(double %17, double %19, double %15)
%21 = getelementptr inbounds double, double* %0, i64 4
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %1, i64 4
%24 = load double, double* %23
%25 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %20)
%26 = getelementptr inbounds double, double* %0, i64 5
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %1, i64 5
%29 = load double, double* %28
%30 = tail call double @llvm.fmuladd.f64(double %27, double %29, double %25)
%31 = getelementptr inbounds double, double* %0, i64 6
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %1, i64 6
%34 = load double, double* %33
%35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %30)
%36 = getelementptr inbounds double, double* %0, i64 7
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %1, i64 7
%39 = load double, double* %38
%40 = tail call double @llvm.fmuladd.f64(double %37, double %39, double %35)
%41 = getelementptr inbounds double, double* %0, i64 8
%42 = load double, double* %41
%43 = getelementptr inbounds double, double* %1, i64 8
%44 = load double, double* %43
%45 = tail call double @llvm.fmuladd.f64(double %42, double %44, double %40)
%46 = getelementptr inbounds double, double* %0, i64 9
%47 = load double, double* %46
%48 = getelementptr inbounds double, double* %1, i64 9
%49 = load double, double* %48
%50 = tail call double @llvm.fmuladd.f64(double %47, double %49, double %45)
%51 = getelementptr inbounds double, double* %0, i64 10
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %1, i64 10
%54 = load double, double* %53
%55 = tail call double @llvm.fmuladd.f64(double %52, double %54, double %50)
%56 = getelementptr inbounds double, double* %0, i64 11
%57 = load double, double* %56
%58 = getelementptr inbounds double, double* %1, i64 11
%59 = load double, double* %58
%60 = tail call double @llvm.fmuladd.f64(double %57, double %59, double %55)
%61 = getelementptr inbounds double, double* %0, i64 12
%62 = load double, double* %61
%63 = getelementptr inbounds double, double* %1, i64 12
%64 = load double, double* %63
%65 = tail call double @llvm.fmuladd.f64(double %62, double %64, double %60)
%66 = getelementptr inbounds double, double* %0, i64 13
%67 = load double, double* %66
%68 = getelementptr inbounds double, double* %1, i64 13
%69 = load double, double* %68
%70 = tail call double @llvm.fmuladd.f64(double %67, double %69, double %65)
%71 = getelementptr inbounds double, double* %0, i64 14
%72 = load double, double* %71
%73 = getelementptr inbounds double, double* %1, i64 14
%74 = load double, double* %73
%75 = tail call double @llvm.fmuladd.f64(double %72, double %74, double %70)
%76 = getelementptr inbounds double, double* %0, i64 15
%77 = load double, double* %76
%78 = getelementptr inbounds double, double* %1, i64 15
%79 = load double, double* %78
%80 = tail call double @llvm.fmuladd.f64(double %77, double %79, double %75)
%81 = getelementptr inbounds double, double* %0, i64 16
%82 = load double, double* %81
%83 = getelementptr inbounds double, double* %1, i64 16
%84 = load double, double* %83
%85 = tail call double @llvm.fmuladd.f64(double %82, double %84, double %80)
%86 = getelementptr inbounds double, double* %0, i64 17
%87 = load double, double* %86
%88 = getelementptr inbounds double, double* %1, i64 17
%89 = load double, double* %88
%90 = tail call double @llvm.fmuladd.f64(double %87, double %89, double %85)
%91 = getelementptr inbounds double, double* %0, i64 18
%92 = load double, double* %91
%93 = getelementptr inbounds double, double* %1, i64 18
%94 = load double, double* %93
%95 = tail call double @llvm.fmuladd.f64(double %92, double %94, double %90)
%96 = getelementptr inbounds double, double* %0, i64 19
%97 = load double, double* %96
%98 = getelementptr inbounds double, double* %1, i64 19
%99 = load double, double* %98
%100 = tail call double @llvm.fmuladd.f64(double %97, double %99, double %95)
ret double %100
}