#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 */
scalar_t__ calloc(int, int);
double pow(double, int);
double sqrt(double);
double *nuclear_mep(int nr_nuclei, double charges[nr_nuclei],
                    double coordinates[3 * nr_nuclei], int grid_size,
                    double grid[3 * grid_size]) {
  double *mep = (double *)calloc(grid_size, sizeof(double));
  for (int i = 0; i < nr_nuclei; i++) {
    for (int j = 0; j < grid_size; j++) {
      double dist = pow((coordinates[i * 3] - grid[j * 3]), 2) +
                    pow((coordinates[i * 3 + 1] - grid[j * 3 + 1]), 2) +
                    pow((coordinates[i * 3 + 2] - grid[j * 3 + 2]), 2);
      mep[j] += charges[i] / sqrt(dist);
    }
  }
  return mep;
}


x86 assembly (clang, -O0):
<nuclear_mep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    128d <nuclear_mep+0x15d>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    127a <nuclear_mep+0x14a>
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
imul   $0x3,-0x38(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
imul   $0x3,-0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
imul   $0x3,-0x38(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1175 <nuclear_mep+0x45>
jmp    127f <nuclear_mep+0x14f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1162 <nuclear_mep+0x32>
mov    -0x30(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nuclear_mep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,0x18(%rsp)
mov    %rdx,%rbx
mov    %rsi,0x30(%rsp)
mov    %edi,%r13d
mov    %ecx,0x14(%rsp)
mov    %ecx,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rbp
test   %r13d,%r13d
jle    1286 <nuclear_mep+0x156>
mov    %r13d,%eax
mov    %rax,0x20(%rsp)
mov    0x14(%rsp),%eax
mov    %rax,0x28(%rsp)
addq   $0x10,0x18(%rsp)
xor    %r15d,%r15d
jmp    119f <nuclear_mep+0x6f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    0x20(%rsp),%r15
je     1286 <nuclear_mep+0x156>
cmpl   $0x0,0x14(%rsp)
jle    1190 <nuclear_mep+0x60>
lea    (%r15,%r15,2),%eax
mov    %rax,0x40(%rsp)
lea    (%r15,%r15,2),%eax
add    $0x1,%eax
mov    %rax,0x38(%rsp)
lea    (%r15,%r15,2),%r14d
add    $0x2,%r14d
mov    0x18(%rsp),%r13
xor    %r12d,%r12d
jmp    1202 <nuclear_mep+0xd2>
nopl   (%rax)
movsd  %xmm1,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0x0(%rbp,%r12,8),%xmm1
movsd  %xmm1,0x0(%rbp,%r12,8)
add    $0x1,%r12
add    $0x18,%r13
cmp    %r12,0x28(%rsp)
je     1190 <nuclear_mep+0x60>
mov    0x40(%rsp),%rax
movsd  (%rbx,%rax,8),%xmm0
subsd  -0x10(%r13),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x38(%rsp),%rax
movsd  (%rbx,%rax,8),%xmm0
subsd  -0x8(%r13),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx,%r14,8),%xmm0
subsd  0x0(%r13),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
addsd  0x8(%rsp),%xmm0
mov    0x30(%rsp),%rax
movsd  (%rax,%r15,8),%xmm1
ucomisd 0xd89(%rip),%xmm0
jb     11d0 <nuclear_mep+0xa0>
sqrtsd %xmm0,%xmm0
jmp    11e1 <nuclear_mep+0xb1>
mov    %rbp,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double* @nuclear_mep(i32 %0, double* nocapture %1, double* nocapture %2, i32 %3, double* nocapture %4) {
%6 = tail call i64 @calloc(i32 %3, i32 8)
%7 = inttoptr i64 %6 to double*
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = icmp sgt i32 %3, 0
%11 = zext i32 %0 to i64
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %9, %28
%14 = phi i64 [ 0, %9 ], [ %29, %28 ]
br i1 %10, label %15, label %28
15: ; preds = %13
%16 = trunc i64 %14 to i32
%17 = mul nsw i32 %16, 3
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds double, double* %2, i64 %18
%20 = add nuw nsw i32 %17, 1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds double, double* %2, i64 %21
%23 = add nuw nsw i32 %17, 2
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds double, double* %2, i64 %24
%26 = getelementptr inbounds double, double* %1, i64 %14
br label %31
27: ; preds = %28, %5
ret double* %7
28: ; preds = %31, %13
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %27, label %13
31: ; preds = %15, %31
%32 = phi i64 [ 0, %15 ], [ %59, %31 ]
%33 = load double, double* %19
%34 = mul nuw nsw i64 %32, 3
%35 = getelementptr inbounds double, double* %4, i64 %34
%36 = load double, double* %35
%37 = fsub double %33, %36
%38 = tail call double @pow(double %37, i32 2)
%39 = load double, double* %22
%40 = add nuw nsw i64 %34, 1
%41 = getelementptr inbounds double, double* %4, i64 %40
%42 = load double, double* %41
%43 = fsub double %39, %42
%44 = tail call double @pow(double %43, i32 2)
%45 = fadd double %38, %44
%46 = load double, double* %25
%47 = add nuw nsw i64 %34, 2
%48 = getelementptr inbounds double, double* %4, i64 %47
%49 = load double, double* %48
%50 = fsub double %46, %49
%51 = tail call double @pow(double %50, i32 2)
%52 = fadd double %45, %51
%53 = load double, double* %26
%54 = tail call double @sqrt(double %52)
%55 = fdiv double %53, %54
%56 = getelementptr inbounds double, double* %7, i64 %32
%57 = load double, double* %56
%58 = fadd double %57, %55
store double %58, double* %56
%59 = add nuw nsw i64 %32, 1
%60 = icmp eq i64 %59, %12
br i1 %60, label %28, label %31
}