double kinetic_energy_in_plane(int num_ptcls, const double *x, const double *v,
                               double mass, double omega) {
  double energy = 0.0;
  int i;
  double vr[2];
  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];
    energy += 0.5 * mass * (vr[0] * vr[0] + vr[1] * vr[1]);
  }
  return energy;
}


x86 assembly (clang, -O0):
<kinetic_energy_in_plane>:
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    1246 <kinetic_energy_in_plane+0x146>
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)
movsd  0xdfb(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm3
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
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_in_plane+0x28>
movsd  -0x30(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<kinetic_energy_in_plane>:
test   %edi,%edi
jle    1170 <kinetic_energy_in_plane+0x70>
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
mulsd  %xmm5,%xmm5
mulsd  %xmm4,%xmm4
addsd  %xmm5,%xmm4
mulsd  %xmm0,%xmm4
addsd  %xmm4,%xmm2
add    $0x18,%rcx
cmp    %rcx,%rax
jne    1130 <kinetic_energy_in_plane+0x30>
movapd %xmm2,%xmm0
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @kinetic_energy_in_plane(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 [2 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 = %74, %5
%15 = load i32, i32* %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %77
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 [2 x double], [2 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 [2 x double], [2 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 [2 x double], [2 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 [2 x double], [2 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* %9
%61 = fmul double 5.000000e-01, %60
%62 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%63 = load double, double* %62
%64 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%65 = load double, double* %64
%66 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 1
%67 = load double, double* %66
%68 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 1
%69 = load double, double* %68
%70 = fmul double %67, %69
%71 = call double @llvm.fmuladd.f64(double %63, double %65, double %70)
%72 = load double, double* %11
%73 = call double @llvm.fmuladd.f64(double %61, double %71, double %72)
store double %73, double* %11
br label %74
74: ; preds = %18
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %14
77: ; preds = %14
%78 = load double, double* %11
ret double %78
}

LLVM IR (-O2):
define double @kinetic_energy_in_plane(i32 %0, double* nocapture %1, double* nocapture %2, double %3, double %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %31
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 ], [ %29, %11 ]
%13 = phi double [ 0.000000e+00, %7 ], [ %28, %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 = fmul double %25, %25
%27 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %26)
%28 = tail call double @llvm.fmuladd.f64(double %9, double %27, double %13)
%29 = add nuw nsw i64 %12, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %11
31: ; preds = %11, %5
%32 = phi double [ 0.000000e+00, %5 ], [ %28, %11 ]
ret double %32
}