double local_energy(double **r, double correlation5, double l,
                    double kinetic_factor, double four_epsilon, int dimension,
                    int number_particles) {
  int particle_i, particle_j, i, j, k;
  double local_energy, dist, dist6, lh, z1, z2, z3, *r_distance;
  local_energy = dist = 0;
  r_distance = (double *)malloc((dimension) * sizeof(double));
  lh = l / 2;
  for (particle_i = 0; particle_i < number_particles - 1; particle_i++) {
    for (particle_j = particle_i + 1; particle_j < number_particles;
         particle_j++) {
      dist = distance(r, r_distance, l, particle_i, particle_j, dimension);
      if (dist <= lh)
        local_energy += kinetic_factor / pow(dist, 7);
    }
  }
  return local_energy;
}


x86 assembly (clang, -O0):
<local_energy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %edx,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movslq -0x2c(%rbp),%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x88(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe76(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    125c <local_energy+0x12c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1249 <local_energy+0x119>
mov    -0x8(%rbp),%rdi
mov    -0x88(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    $0x1,%al
call   1050 <distance@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1236 <local_energy+0x106>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
movsd  0xdf0(%rip),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    123b <local_energy+0x10b>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b4 <local_energy+0x84>
jmp    124e <local_energy+0x11e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119a <local_energy+0x6a>
movsd  -0x50(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_energy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r12d
mov    %esi,%r14d
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
mov    %rdi,%r15
movslq %esi,%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
cmp    $0x2,%r12d
jl     121c <local_energy+0xec>
mov    %rax,%r13
movsd  0xe83(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
lea    -0x1(%r12),%eax
mov    %eax,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
jmp    11aa <local_energy+0x7a>
nop
mov    0xc(%rsp),%eax
cmp    0x8(%rsp),%eax
je     121c <local_energy+0xec>
mov    %eax,%ebx
lea    0x1(%rbx),%ebp
cmp    %r12d,%ebp
mov    %ebp,0xc(%rsp)
jl     11c8 <local_energy+0x98>
jmp    11a0 <local_energy+0x70>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%r12d
je     11a0 <local_energy+0x70>
mov    %r15,%rdi
mov    %r13,%rsi
movsd  0x10(%rsp),%xmm0
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
mov    $0x1,%al
call   1050 <distance@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     11c0 <local_energy+0x90>
movsd  0xe0b(%rip),%xmm1
call   1040 <pow@plt>
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
jmp    11c0 <local_energy+0x90>
movsd  (%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @local_energy(double** %0, double %1, double %2, double %3, double %4, i32 %5, i32 %6) {
%8 = alloca double**
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double*
store double** %0, double*** %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %20
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = call i8* @malloc(i64 %30)
%32 = bitcast i8* %31 to double*
store double* %32, double** %27
%33 = load double, double* %10
%34 = fdiv double %33, 2.000000e+00
store double %34, double* %23
store i32 0, i32* %15
br label %35
35: ; preds = %71, %7
%36 = load i32, i32* %15
%37 = load i32, i32* %14
%38 = sub nsw i32 %37, 1
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %74
40: ; preds = %35
%41 = load i32, i32* %15
%42 = add nsw i32 %41, 1
store i32 %42, i32* %16
br label %43
43: ; preds = %67, %40
%44 = load i32, i32* %16
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %70
47: ; preds = %43
%48 = load double**, double*** %8
%49 = load double*, double** %27
%50 = load double, double* %10
%51 = load i32, i32* %15
%52 = load i32, i32* %16
%53 = load i32, i32* %13
%54 = call i32 (double**, double*, double, i32, i32, i32, ...) bitcast (i32 (...)* @distance to i32 (double**, double*, double, i32, i32, i32, ...)*)(double** %48, double* %49, double %50, i32 %51, i32 %52, i32 %53)
%55 = sitofp i32 %54 to double
store double %55, double* %21
%56 = load double, double* %21
%57 = load double, double* %23
%58 = fcmp ole double %56, %57
br i1 %58, label %59, label %66
59: ; preds = %47
%60 = load double, double* %11
%61 = load double, double* %21
%62 = call double @pow(double %61, double 7.000000e+00)
%63 = fdiv double %60, %62
%64 = load double, double* %20
%65 = fadd double %64, %63
store double %65, double* %20
br label %66
66: ; preds = %59, %47
br label %67
67: ; preds = %66
%68 = load i32, i32* %16
%69 = add nsw i32 %68, 1
store i32 %69, i32* %16
br label %43
70: ; preds = %43
br label %71
71: ; preds = %70
%72 = load i32, i32* %15
%73 = add nsw i32 %72, 1
store i32 %73, i32* %15
br label %35
74: ; preds = %35
%75 = load double, double* %20
ret double %75
}

LLVM IR (-O2):
define double @local_energy(double** %0, double %1, double %2, double %3, double %4, i32 %5, i32 %6) {
%8 = sext i32 %5 to i64
%9 = shl nsw i64 %8, 3
%10 = tail call i8* @malloc(i64 %9)
%11 = bitcast i8* %10 to double*
%12 = fmul double %2, 5.000000e-01
%13 = add i32 %6, -1
%14 = icmp sgt i32 %6, 1
br i1 %14, label %18, label %37
15: ; preds = %33, %18
%16 = phi double [ %20, %18 ], [ %34, %33 ]
%17 = icmp eq i32 %21, %13
br i1 %17, label %37, label %18
18: ; preds = %7, %15
%19 = phi i32 [ %21, %15 ], [ 0, %7 ]
%20 = phi double [ %16, %15 ], [ 0.000000e+00, %7 ]
%21 = add nuw nsw i32 %19, 1
%22 = icmp slt i32 %21, %6
br i1 %22, label %23, label %15
23: ; preds = %18, %33
%24 = phi i32 [ %35, %33 ], [ %21, %18 ]
%25 = phi double [ %34, %33 ], [ %20, %18 ]
%26 = tail call i32 (double**, double*, double, i32, i32, i32, ...) bitcast (i32 (...)* @distance to i32 (double**, double*, double, i32, i32, i32, ...)*)(double** %0, double* %11, double %2, i32 %19, i32 %24, i32 %5)
%27 = sitofp i32 %26 to double
%28 = fcmp ult double %12, %27
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = tail call double @pow(double %27, double 7.000000e+00)
%31 = fdiv double %3, %30
%32 = fadd double %25, %31
br label %33
33: ; preds = %23, %29
%34 = phi double [ %32, %29 ], [ %25, %23 ]
%35 = add nuw i32 %24, 1
%36 = icmp eq i32 %35, %6
br i1 %36, label %15, label %23
37: ; preds = %15, %7
%38 = phi double [ 0.000000e+00, %7 ], [ %16, %15 ]
ret double %38
}