double kinetic_energy(int num_ptcls, const double *x, const double *v,
                      double mass, double omega) {
  double energy = 0.0;
  int i;
  double vr[3];
  for (i = 0; i < num_ptcls; ++i) {
    vr[0] = v[3 * i + 0];
    vr[1] = v[3 * i + 1];
    vr[0] -= (-omega) * x[3 * i + 1];
    vr[1] += (-omega) * x[3 * i + 0];
    vr[2] = v[3 * i + 2];
    energy += 0.5 * mass * (vr[0] * vr[0] + vr[1] * vr[1] + vr[2] * vr[2]);
  }
  return energy;
}


x86 assembly (clang, -O0):
<kinetic_energy>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1270 <kinetic_energy+0x170>
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x50(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xde3(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm3
movsd  -0x48(%rbp),%xmm2
mulsd  -0x48(%rbp),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1128 <kinetic_energy+0x28>
movsd  -0x30(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<kinetic_energy>:
test   %edi,%edi
jle    117e <kinetic_energy+0x7e>
movapd 0xef4(%rip),%xmm3
xorpd  %xmm1,%xmm3
mulsd  0xef8(%rip),%xmm0
mov    %edi,%eax
shl    $0x3,%rax
lea    (%rax,%rax,2),%rax
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movsd  0x8(%rsi,%rcx,1),%xmm4
mulsd  %xmm1,%xmm4
addsd  (%rdx,%rcx,1),%xmm4
movsd  (%rsi,%rcx,1),%xmm5
mulsd  %xmm3,%xmm5
addsd  0x8(%rdx,%rcx,1),%xmm5
movsd  0x10(%rdx,%rcx,1),%xmm6
mulsd  %xmm5,%xmm5
mulsd  %xmm4,%xmm4
addsd  %xmm5,%xmm4
mulsd  %xmm6,%xmm6
addsd  %xmm4,%xmm6
mulsd  %xmm0,%xmm6
addsd  %xmm6,%xmm2
add    $0x18,%rcx
cmp    %rcx,%rax
jne    1130 <kinetic_energy+0x30>
movapd %xmm2,%xmm0
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @kinetic_energy(i32 %0, double* %1, double* %2, double %3, double %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca [3 x double]
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store double %3, double* %9
store double %4, double* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %12
br label %14
14: ; preds = %87, %5
%15 = load i32, i32* %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %90
18: ; preds = %14
%19 = load double*, double** %8
%20 = load i32, i32* %12
%21 = mul nsw i32 3, %20
%22 = add nsw i32 %21, 0
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %19, i64 %23
%25 = load double, double* %24
%26 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
store double %25, double* %26
%27 = load double*, double** %8
%28 = load i32, i32* %12
%29 = mul nsw i32 3, %28
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %27, i64 %31
%33 = load double, double* %32
%34 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
store double %33, double* %34
%35 = load double, double* %10
%36 = fneg double %35
%37 = load double*, double** %7
%38 = load i32, i32* %12
%39 = mul nsw i32 3, %38
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %37, i64 %41
%43 = load double, double* %42
%44 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%45 = load double, double* %44
%46 = fneg double %36
%47 = call double @llvm.fmuladd.f64(double %46, double %43, double %45)
store double %47, double* %44
%48 = load double, double* %10
%49 = fneg double %48
%50 = load double*, double** %7
%51 = load i32, i32* %12
%52 = mul nsw i32 3, %51
%53 = add nsw i32 %52, 0
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %50, i64 %54
%56 = load double, double* %55
%57 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%58 = load double, double* %57
%59 = call double @llvm.fmuladd.f64(double %49, double %56, double %58)
store double %59, double* %57
%60 = load double*, double** %8
%61 = load i32, i32* %12
%62 = mul nsw i32 3, %61
%63 = add nsw i32 %62, 2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %60, i64 %64
%66 = load double, double* %65
%67 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
store double %66, double* %67
%68 = load double, double* %9
%69 = fmul double 5.000000e-01, %68
%70 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%71 = load double, double* %70
%72 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%73 = load double, double* %72
%74 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%75 = load double, double* %74
%76 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%77 = load double, double* %76
%78 = fmul double %75, %77
%79 = call double @llvm.fmuladd.f64(double %71, double %73, double %78)
%80 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
%81 = load double, double* %80
%82 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
%83 = load double, double* %82
%84 = call double @llvm.fmuladd.f64(double %81, double %83, double %79)
%85 = load double, double* %11
%86 = call double @llvm.fmuladd.f64(double %69, double %84, double %85)
store double %86, double* %11
br label %87
87: ; preds = %18
%88 = load i32, i32* %12
%89 = add nsw i32 %88, 1
store i32 %89, i32* %12
br label %14
90: ; preds = %14
%91 = load double, double* %11
ret double %91
}

LLVM IR (-O2):
define double @kinetic_energy(i32 %0, double* nocapture %1, double* nocapture %2, double %3, double %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %35
7: ; preds = %5
%8 = fneg double %4
%9 = fmul double %3, 5.000000e-01
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %33, %11 ]
%13 = phi double [ 0.000000e+00, %7 ], [ %32, %11 ]
%14 = mul nuw nsw i64 %12, 3
%15 = getelementptr inbounds double, double* %2, i64 %14
%16 = load double, double* %15
%17 = add nuw nsw i64 %14, 1
%18 = getelementptr inbounds double, double* %2, i64 %17
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 %17
%21 = load double, double* %20
%22 = tail call double @llvm.fmuladd.f64(double %4, double %21, double %16)
%23 = getelementptr inbounds double, double* %1, i64 %14
%24 = load double, double* %23
%25 = tail call double @llvm.fmuladd.f64(double %8, double %24, double %19)
%26 = add nuw nsw i64 %14, 2
%27 = getelementptr inbounds double, double* %2, i64 %26
%28 = load double, double* %27
%29 = fmul double %25, %25
%30 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %29)
%31 = tail call double @llvm.fmuladd.f64(double %28, double %28, double %30)
%32 = tail call double @llvm.fmuladd.f64(double %9, double %31, double %13)
%33 = add nuw nsw i64 %12, 1
%34 = icmp eq i64 %33, %10
br i1 %34, label %35, label %11
35: ; preds = %11, %5
%36 = phi double [ 0.000000e+00, %5 ], [ %32, %11 ]
ret double %36
}