#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double inv_distance(double, double, double, double, double, double);
void get_particles_E(int N, double *m, double *x, double *y, double *z,
                     double *V2, double *Ek, double *Ep, double G) {
  int i = 0, j = 0, k = 0;
  double Ep_tmp, invd;
  for (i = 0; i < N; i++) {
    Ek[i] = 0.5 * m[i] * V2[i];
    Ep_tmp = 0.0;
    for (j = 0; j < N; j++) {
      k = 0;
      if (i != j) {
        invd = inv_distance(x[i], x[j], y[i], y[j], z[i], z[j]);
        Ep_tmp += -G * m[i] * m[j] * invd;
      }
    }
    Ep[i] = Ep_tmp;
  }
}


x86 assembly (clang, -O0):
<get_particles_E>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1299 <get_particles_E+0x189>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  0xe8c(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1279 <get_particles_E+0x169>
movl   $0x0,-0x44(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     1266 <get_particles_E+0x156>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm4
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm5
call   1030 <inv_distance@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    126b <get_particles_E+0x15b>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11a2 <get_particles_E+0x92>
movsd  -0x50(%rbp),%xmm0
mov    0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1158 <get_particles_E+0x48>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_particles_E>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movapd %xmm0,(%rsp)
mov    %r9,0x10(%rsp)
mov    %r8,0x18(%rsp)
test   %edi,%edi
jle    1215 <get_particles_E+0x105>
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
movapd (%rsp),%xmm0
xorpd  0xeb5(%rip),%xmm0
movapd %xmm0,(%rsp)
mov    %edi,%ebp
xor    %r14d,%r14d
jmp    1178 <get_particles_E+0x68>
nopw   0x0(%rax,%rax,1)
mov    0x68(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
add    $0x1,%r14
cmp    %rbp,%r14
je     1215 <get_particles_E+0x105>
movsd  (%rbx,%r14,8),%xmm0
mulsd  0xe8a(%rip),%xmm0
mov    0x10(%rsp),%rax
mulsd  (%rax,%r14,8),%xmm0
mov    0x60(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
xorpd  %xmm0,%xmm0
xor    %r15d,%r15d
jmp    11b9 <get_particles_E+0xa9>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15
cmp    %r15,%rbp
je     1160 <get_particles_E+0x50>
cmp    %r15,%r14
je     11b0 <get_particles_E+0xa0>
movsd  %xmm0,0x20(%rsp)
movsd  0x0(%r13,%r14,8),%xmm0
movsd  0x0(%r13,%r15,8),%xmm1
movsd  (%r12,%r14,8),%xmm2
movsd  (%r12,%r15,8),%xmm3
mov    0x18(%rsp),%rax
movsd  (%rax,%r14,8),%xmm4
movsd  (%rax,%r15,8),%xmm5
call   1030 <inv_distance@plt>
movsd  (%rbx,%r14,8),%xmm1
mulsd  (%rsp),%xmm1
mulsd  (%rbx,%r15,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
jmp    11b0 <get_particles_E+0xa0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @get_particles_E(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, double* nocapture %4, double* nocapture %5, double* nocapture writeonly %6, double* nocapture writeonly %7, double %8) {
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %55
11: ; preds = %9
%12 = fneg double %8
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %51, %11
%15 = phi i64 [ 0, %11 ], [ %53, %51 ]
%16 = getelementptr inbounds double, double* %1, i64 %15
%17 = load double, double* %16
%18 = fmul double %17, 5.000000e-01
%19 = getelementptr inbounds double, double* %5, i64 %15
%20 = load double, double* %19
%21 = fmul double %18, %20
%22 = getelementptr inbounds double, double* %6, i64 %15
store double %21, double* %22
%23 = getelementptr inbounds double, double* %2, i64 %15
%24 = getelementptr inbounds double, double* %3, i64 %15
%25 = getelementptr inbounds double, double* %4, i64 %15
br label %26
26: ; preds = %14, %47
%27 = phi i64 [ 0, %14 ], [ %49, %47 ]
%28 = phi double [ 0.000000e+00, %14 ], [ %48, %47 ]
%29 = icmp eq i64 %15, %27
br i1 %29, label %47, label %30
30: ; preds = %26
%31 = load double, double* %23
%32 = getelementptr inbounds double, double* %2, i64 %27
%33 = load double, double* %32
%34 = load double, double* %24
%35 = getelementptr inbounds double, double* %3, i64 %27
%36 = load double, double* %35
%37 = load double, double* %25
%38 = getelementptr inbounds double, double* %4, i64 %27
%39 = load double, double* %38
%40 = tail call double @inv_distance(double %31, double %33, double %34, double %36, double %37, double %39)
%41 = load double, double* %16
%42 = fmul double %41, %12
%43 = getelementptr inbounds double, double* %1, i64 %27
%44 = load double, double* %43
%45 = fmul double %42, %44
%46 = tail call double @llvm.fmuladd.f64(double %45, double %40, double %28)
br label %47
47: ; preds = %26, %30
%48 = phi double [ %46, %30 ], [ %28, %26 ]
%49 = add nuw nsw i64 %27, 1
%50 = icmp eq i64 %49, %13
br i1 %50, label %51, label %26
51: ; preds = %47
%52 = getelementptr inbounds double, double* %7, i64 %15
store double %48, double* %52
%53 = add nuw nsw i64 %15, 1
%54 = icmp eq i64 %53, %13
br i1 %54, label %55, label %14
55: ; preds = %51, %9
ret void
}