double distance(double position_x[256], double position_y[256],
                double position_z[256], int i, int j) {
  double delx, dely, delz, r2inv;
  delx = position_x[i] - position_x[j];
  dely = position_y[i] - position_y[j];
  delz = position_z[i] - position_z[j];
  r2inv = delx * delx + dely * dely + delz * delz;
  return r2inv;
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
movslq %ecx,%rax
movsd  (%rdi,%rax,8),%xmm1
movslq %r8d,%rcx
subsd  (%rdi,%rcx,8),%xmm1
movsd  (%rsi,%rax,8),%xmm2
subsd  (%rsi,%rcx,8),%xmm2
movsd  (%rdx,%rax,8),%xmm0
subsd  (%rdx,%rcx,8),%xmm0
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ret

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

LLVM IR (-O2):
define double @distance(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, i32 %4) {
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds double, double* %0, i64 %6
%8 = load double, double* %7
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds double, double* %0, i64 %9
%11 = load double, double* %10
%12 = fsub double %8, %11
%13 = getelementptr inbounds double, double* %1, i64 %6
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %1, i64 %9
%16 = load double, double* %15
%17 = fsub double %14, %16
%18 = getelementptr inbounds double, double* %2, i64 %6
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %2, i64 %9
%21 = load double, double* %20
%22 = fsub double %19, %21
%23 = fmul double %17, %17
%24 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %23)
%25 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %24)
ret double %25
}