double sqdist(double a[3], double b[3]) {
  return ((a[0] - b[0]) * (a[0] - b[0])) + ((a[1] - b[1]) * (a[1] - b[1])) +
         ((a[2] - b[2]) * (a[2] - b[2]));
}


x86 assembly (clang, -O0):
<sqdist>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm3
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm3
mulsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
subsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqdist>:
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
subsd  (%rsi),%xmm1
subsd  0x8(%rsi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
subsd  0x10(%rsi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @sqdist(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
store double* %0, double** %3
store double* %1, double** %4
%5 = load double*, double** %3
%6 = getelementptr inbounds double, double* %5, i64 0
%7 = load double, double* %6
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = fsub double %7, %10
%12 = load double*, double** %3
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = load double*, double** %4
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = fsub double %14, %17
%19 = load double*, double** %3
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = load double*, double** %4
%23 = getelementptr inbounds double, double* %22, i64 1
%24 = load double, double* %23
%25 = fsub double %21, %24
%26 = load double*, double** %3
%27 = getelementptr inbounds double, double* %26, i64 1
%28 = load double, double* %27
%29 = load double*, double** %4
%30 = getelementptr inbounds double, double* %29, i64 1
%31 = load double, double* %30
%32 = fsub double %28, %31
%33 = fmul double %25, %32
%34 = call double @llvm.fmuladd.f64(double %11, double %18, double %33)
%35 = load double*, double** %3
%36 = getelementptr inbounds double, double* %35, i64 2
%37 = load double, double* %36
%38 = load double*, double** %4
%39 = getelementptr inbounds double, double* %38, i64 2
%40 = load double, double* %39
%41 = fsub double %37, %40
%42 = load double*, double** %3
%43 = getelementptr inbounds double, double* %42, i64 2
%44 = load double, double* %43
%45 = load double*, double** %4
%46 = getelementptr inbounds double, double* %45, i64 2
%47 = load double, double* %46
%48 = fsub double %44, %47
%49 = call double @llvm.fmuladd.f64(double %41, double %48, double %34)
ret double %49
}

LLVM IR (-O2):
define double @sqdist(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = load double, double* %1
%5 = fsub double %3, %4
%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 = fsub double %7, %9
%11 = fmul double %10, %10
%12 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %11)
%13 = getelementptr inbounds double, double* %0, i64 2
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %1, i64 2
%16 = load double, double* %15
%17 = fsub double %14, %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %12)
ret double %18
}