void velocity_calc(int nAtoms, int iter, int deltaWrite, double Ar_m,
                   double Ar_mmass, double delta_t, double kB, double *int_temp,
                   double *Tot_kinetic_en, double **atomVelocities,
                   double **atomForces, double **old_atomForces) {
  int i, j;
  double component;
  double sumv2;
  double dof;
  double convert;
  double convert2;
  convert = 4184 * 0.0001;
  convert2 = 0.0001;
  dof = nAtoms * 3.0;
  sumv2 = 0.0;
  for (i = 0; i < nAtoms; i++) {
    for (j = 0; j < 3; j++) {
      component = atomVelocities[i][j] +
                  0.5 * convert * delta_t *
                      (atomForces[i][j] + old_atomForces[i][j]) / Ar_mmass;
      atomVelocities[i][j] = component;
      if (iter % deltaWrite == 0) {
        sumv2 += atomVelocities[i][j] * atomVelocities[i][j];
      }
    }
  }
  *Tot_kinetic_en = 0.5 * Ar_mmass * sumv2 / convert;
  sumv2 = sumv2 / dof;
  *int_temp = (Ar_m * sumv2) / (kB * convert2);
}


x86 assembly (clang, -O0):
<velocity_calc>:
push   %rbp
mov    %rsp,%rbp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
mov    %r9,-0x48(%rbp)
movsd  0xed3(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1280 <velocity_calc+0x180>
movl   $0x0,-0x50(%rbp)
cmpl   $0x3,-0x50(%rbp)
jge    126d <velocity_calc+0x16d>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe6a(%rip),%xmm1
mulsd  -0x70(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mov    0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    125a <velocity_calc+0x15a>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    125f <velocity_calc+0x15f>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1187 <velocity_calc+0x87>
jmp    1272 <velocity_calc+0x172>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1174 <velocity_calc+0x74>
movsd  0xd90(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
divsd  -0x70(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x60(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x78(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<velocity_calc>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
jle    11ec <velocity_calc+0xec>
mov    %edx,%r10d
mov    0x28(%rsp),%r11
mov    0x20(%rsp),%r14
mulsd  0xede(%rip),%xmm2
mov    %esi,%eax
cltd
idiv   %r10d
mov    %edi,%r10d
xorpd  %xmm4,%xmm4
xor    %esi,%esi
jmp    114d <velocity_calc+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rsi
cmp    %rsi,%r10
je     11f0 <velocity_calc+0xf0>
mov    (%r9,%rsi,8),%rbx
mov    (%r14,%rsi,8),%rax
mov    (%r11,%rsi,8),%r15
movsd  (%rax),%xmm5
addsd  (%r15),%xmm5
mulsd  %xmm2,%xmm5
divsd  %xmm1,%xmm5
addsd  (%rbx),%xmm5
movsd  %xmm5,(%rbx)
test   %edx,%edx
je     1180 <velocity_calc+0x80>
movapd %xmm4,%xmm5
jmp    1188 <velocity_calc+0x88>
nopl   0x0(%rax)
mulsd  %xmm5,%xmm5
addsd  %xmm4,%xmm5
movsd  0x8(%rax),%xmm6
addsd  0x8(%r15),%xmm6
mulsd  %xmm2,%xmm6
divsd  %xmm1,%xmm6
addsd  0x8(%rbx),%xmm6
movsd  %xmm6,0x8(%rbx)
je     11b0 <velocity_calc+0xb0>
movapd %xmm4,%xmm6
jmp    11b8 <velocity_calc+0xb8>
nopl   (%rax)
mulsd  %xmm6,%xmm6
addsd  %xmm5,%xmm6
movsd  0x10(%rax),%xmm5
addsd  0x10(%r15),%xmm5
mulsd  %xmm2,%xmm5
divsd  %xmm1,%xmm5
addsd  0x10(%rbx),%xmm5
movsd  %xmm5,0x10(%rbx)
jne    1140 <velocity_calc+0x40>
mulsd  %xmm5,%xmm5
addsd  %xmm6,%xmm5
movapd %xmm5,%xmm4
jmp    1140 <velocity_calc+0x40>
xorpd  %xmm4,%xmm4
xorps  %xmm2,%xmm2
cvtsi2sd %edi,%xmm2
mulsd  0xe09(%rip),%xmm2
mulsd  0xe09(%rip),%xmm1
mulsd  %xmm4,%xmm1
divsd  0xe05(%rip),%xmm1
movsd  %xmm1,(%r8)
divsd  %xmm2,%xmm4
mulsd  %xmm0,%xmm4
mulsd  0xdf8(%rip),%xmm3
divsd  %xmm3,%xmm4
movsd  %xmm4,(%rcx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @velocity_calc(i32 %0, i32 %1, i32 %2, double %3, double %4, double %5, double %6, double* %7, double* %8, double** %9, double** %10, double** %11) {
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double*
%21 = alloca double*
%22 = alloca double**
%23 = alloca double**
%24 = alloca double**
%25 = alloca i32
%26 = alloca i32
%27 = alloca double
%28 = alloca double
%29 = alloca double
%30 = alloca double
%31 = alloca double
store i32 %0, i32* %13
store i32 %1, i32* %14
store i32 %2, i32* %15
store double %3, double* %16
store double %4, double* %17
store double %5, double* %18
store double %6, double* %19
store double* %7, double** %20
store double* %8, double** %21
store double** %9, double*** %22
store double** %10, double*** %23
store double** %11, double*** %24
store double 4.184000e-01, double* %30
store double 1.000000e-04, double* %31
%32 = load i32, i32* %13
%33 = sitofp i32 %32 to double
%34 = fmul double %33, 3.000000e+00
store double %34, double* %29
store double 0.000000e+00, double* %28
store i32 0, i32* %25
br label %35
35: ; preds = %119, %12
%36 = load i32, i32* %25
%37 = load i32, i32* %13
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %122
39: ; preds = %35
store i32 0, i32* %26
br label %40
40: ; preds = %115, %39
%41 = load i32, i32* %26
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %118
43: ; preds = %40
%44 = load double**, double*** %22
%45 = load i32, i32* %25
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double*, double** %44, i64 %46
%48 = load double*, double** %47
%49 = load i32, i32* %26
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load double, double* %30
%54 = fmul double 5.000000e-01, %53
%55 = load double, double* %18
%56 = fmul double %54, %55
%57 = load double**, double*** %23
%58 = load i32, i32* %25
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double*, double** %57, i64 %59
%61 = load double*, double** %60
%62 = load i32, i32* %26
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = load double**, double*** %24
%67 = load i32, i32* %25
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double*, double** %66, i64 %68
%70 = load double*, double** %69
%71 = load i32, i32* %26
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = fadd double %65, %74
%76 = fmul double %56, %75
%77 = load double, double* %17
%78 = fdiv double %76, %77
%79 = fadd double %52, %78
store double %79, double* %27
%80 = load double, double* %27
%81 = load double**, double*** %22
%82 = load i32, i32* %25
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double*, double** %81, i64 %83
%85 = load double*, double** %84
%86 = load i32, i32* %26
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
store double %80, double* %88
%89 = load i32, i32* %14
%90 = load i32, i32* %15
%91 = srem i32 %89, %90
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %114
93: ; preds = %43
%94 = load double**, double*** %22
%95 = load i32, i32* %25
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds double*, double** %94, i64 %96
%98 = load double*, double** %97
%99 = load i32, i32* %26
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds double, double* %98, i64 %100
%102 = load double, double* %101
%103 = load double**, double*** %22
%104 = load i32, i32* %25
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds double*, double** %103, i64 %105
%107 = load double*, double** %106
%108 = load i32, i32* %26
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
%112 = load double, double* %28
%113 = call double @llvm.fmuladd.f64(double %102, double %111, double %112)
store double %113, double* %28
br label %114
114: ; preds = %93, %43
br label %115
115: ; preds = %114
%116 = load i32, i32* %26
%117 = add nsw i32 %116, 1
store i32 %117, i32* %26
br label %40
118: ; preds = %40
br label %119
119: ; preds = %118
%120 = load i32, i32* %25
%121 = add nsw i32 %120, 1
store i32 %121, i32* %25
br label %35
122: ; preds = %35
%123 = load double, double* %17
%124 = fmul double 5.000000e-01, %123
%125 = load double, double* %28
%126 = fmul double %124, %125
%127 = load double, double* %30
%128 = fdiv double %126, %127
%129 = load double*, double** %21
store double %128, double* %129
%130 = load double, double* %28
%131 = load double, double* %29
%132 = fdiv double %130, %131
store double %132, double* %28
%133 = load double, double* %16
%134 = load double, double* %28
%135 = fmul double %133, %134
%136 = load double, double* %19
%137 = load double, double* %31
%138 = fmul double %136, %137
%139 = fdiv double %135, %138
%140 = load double*, double** %20
store double %139, double* %140
ret void
}

LLVM IR (-O2):
define void @velocity_calc(i32 %0, i32 %1, i32 %2, double %3, double %4, double %5, double %6, double* nocapture writeonly %7, double* nocapture writeonly %8, double** nocapture %9, double** nocapture %10, double** nocapture %11) {
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %63
14: ; preds = %12
%15 = fmul double %5, 2.092000e-01
%16 = srem i32 %1, %2
%17 = icmp eq i32 %16, 0
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %14, %19
%20 = phi i64 [ 0, %14 ], [ %61, %19 ]
%21 = phi double [ 0.000000e+00, %14 ], [ %60, %19 ]
%22 = getelementptr inbounds double*, double** %9, i64 %20
%23 = load double*, double** %22
%24 = getelementptr inbounds double*, double** %10, i64 %20
%25 = load double*, double** %24
%26 = getelementptr inbounds double*, double** %11, i64 %20
%27 = load double*, double** %26
%28 = load double, double* %23
%29 = load double, double* %25
%30 = load double, double* %27
%31 = fadd double %29, %30
%32 = fmul double %15, %31
%33 = fdiv double %32, %4
%34 = fadd double %28, %33
store double %34, double* %23
%35 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %21)
%36 = select i1 %17, double %35, double %21
%37 = getelementptr inbounds double, double* %23, i64 1
%38 = load double, double* %37
%39 = getelementptr inbounds double, double* %25, i64 1
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %27, i64 1
%42 = load double, double* %41
%43 = fadd double %40, %42
%44 = fmul double %15, %43
%45 = fdiv double %44, %4
%46 = fadd double %38, %45
store double %46, double* %37
%47 = tail call double @llvm.fmuladd.f64(double %46, double %46, double %36)
%48 = select i1 %17, double %47, double %21
%49 = getelementptr inbounds double, double* %23, i64 2
%50 = load double, double* %49
%51 = getelementptr inbounds double, double* %25, i64 2
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %27, i64 2
%54 = load double, double* %53
%55 = fadd double %52, %54
%56 = fmul double %15, %55
%57 = fdiv double %56, %4
%58 = fadd double %50, %57
store double %58, double* %49
%59 = tail call double @llvm.fmuladd.f64(double %58, double %58, double %48)
%60 = select i1 %17, double %59, double %21
%61 = add nuw nsw i64 %20, 1
%62 = icmp eq i64 %61, %18
br i1 %62, label %63, label %19
63: ; preds = %19, %12
%64 = phi double [ 0.000000e+00, %12 ], [ %60, %19 ]
%65 = sitofp i32 %0 to double
%66 = fmul double %65, 3.000000e+00
%67 = fmul double %4, 5.000000e-01
%68 = fmul double %67, %64
%69 = fdiv double %68, 4.184000e-01
store double %69, double* %8
%70 = fdiv double %64, %66
%71 = fmul double %70, %3
%72 = fmul double %6, 1.000000e-04
%73 = fdiv double %71, %72
store double %73, double* %7
ret void
}