#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 */
int /*<<< orphan*/ coulomb_force_one_pair(double const *, double const *,
                                          double, double, double *);
void ca_coulomb_force(const double *positions, double charge, double dt,
                      int num_ptcls, double delta, double k, double *forces) {
  double kij = charge * charge * dt * k;
  const double *r0;
  double *f;
  const double *r1;
  int i, j;
  for (i = 0; i < num_ptcls; ++i) {
    r0 = &positions[i * 3];
    f = &forces[i * 3];
    for (j = 0; j < num_ptcls; ++j) {
      if (j == i)
        continue;
      r1 = &positions[j * 3];
      coulomb_force_one_pair(r0, r1, kij, delta, f);
    }
  }
}


x86 assembly (clang, -O0):
<ca_coulomb_force>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1205 <ca_coulomb_force+0xf5>
mov    -0x8(%rbp),%rax
imul   $0x3,-0x5c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
imul   $0x3,-0x5c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f2 <ca_coulomb_force+0xe2>
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jne    11b3 <ca_coulomb_force+0xa3>
jmp    11e4 <ca_coulomb_force+0xd4>
mov    -0x8(%rbp),%rax
imul   $0x3,-0x60(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x58(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x50(%rbp),%rdx
call   1030 <coulomb_force_one_pair@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1196 <ca_coulomb_force+0x86>
jmp    11f7 <ca_coulomb_force+0xe7>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1157 <ca_coulomb_force+0x47>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ca_coulomb_force>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x8(%rsp)
movsd  %xmm2,0x20(%rsp)
test   %esi,%esi
jle    11be <ca_coulomb_force+0xae>
mov    %rdi,%r15
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %esi,%eax
mov    %rax,(%rsp)
lea    (%rax,%rax,2),%rbp
xor    %r14d,%r14d
xor    %eax,%eax
jmp    1173 <ca_coulomb_force+0x63>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
add    $0x1,%rax
add    $0x3,%r14
cmp    (%rsp),%rax
je     11be <ca_coulomb_force+0xae>
mov    %rax,0x10(%rsp)
lea    (%rax,%rax,2),%eax
lea    (%r15,%rax,8),%r12
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,8),%rbx
xor    %r13d,%r13d
jmp    1199 <ca_coulomb_force+0x89>
nopl   (%rax)
add    $0x3,%r13
cmp    %r13,%rbp
je     1160 <ca_coulomb_force+0x50>
cmp    %r13,%r14
je     1190 <ca_coulomb_force+0x80>
mov    %r13d,%eax
lea    (%r15,%rax,8),%rsi
mov    %r12,%rdi
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %rbx,%rdx
call   1030 <coulomb_force_one_pair@plt>
jmp    1190 <ca_coulomb_force+0x80>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ca_coulomb_force(double* %0, double %1, double %2, i32 %3, double %4, double %5, double* %6) {
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%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
store double* %0, double** %8
store double %1, double* %9
store double %2, double* %10
store i32 %3, i32* %11
store double %4, double* %12
store double %5, double* %13
store double* %6, double** %14
%21 = load double, double* %9
%22 = load double, double* %9
%23 = fmul double %21, %22
%24 = load double, double* %10
%25 = fmul double %23, %24
%26 = load double, double* %13
%27 = fmul double %25, %26
store double %27, double* %15
store i32 0, i32* %19
br label %28
28: ; preds = %68, %7
%29 = load i32, i32* %19
%30 = load i32, i32* %11
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %71
32: ; preds = %28
%33 = load double*, double** %8
%34 = load i32, i32* %19
%35 = mul nsw i32 %34, 3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %33, i64 %36
store double* %37, double** %16
%38 = load double*, double** %14
%39 = load i32, i32* %19
%40 = mul nsw i32 %39, 3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
store double* %42, double** %17
store i32 0, i32* %20
br label %43
43: ; preds = %64, %32
%44 = load i32, i32* %20
%45 = load i32, i32* %11
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %67
47: ; preds = %43
%48 = load i32, i32* %20
%49 = load i32, i32* %19
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %47
br label %64
52: ; preds = %47
%53 = load double*, double** %8
%54 = load i32, i32* %20
%55 = mul nsw i32 %54, 3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %53, i64 %56
store double* %57, double** %18
%58 = load double*, double** %16
%59 = load double*, double** %18
%60 = load double, double* %15
%61 = load double, double* %12
%62 = load double*, double** %17
%63 = call i32 @coulomb_force_one_pair(double* %58, double* %59, double %60, double %61, double* %62)
br label %64
64: ; preds = %52, %51
%65 = load i32, i32* %20
%66 = add nsw i32 %65, 1
store i32 %66, i32* %20
br label %43
67: ; preds = %43
br label %68
68: ; preds = %67
%69 = load i32, i32* %19
%70 = add nsw i32 %69, 1
store i32 %70, i32* %19
br label %28
71: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @ca_coulomb_force(double* %0, double %1, double %2, i32 %3, double %4, double %5, double* %6) {
%8 = fmul double %1, %1
%9 = fmul double %8, %2
%10 = fmul double %9, %5
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = zext i32 %3 to i64
br label %14
14: ; preds = %31, %12
%15 = phi i64 [ 0, %12 ], [ %32, %31 ]
%16 = mul i64 %15, 3
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = getelementptr inbounds double, double* %6, i64 %17
br label %20
20: ; preds = %14, %28
%21 = phi i64 [ 0, %14 ], [ %29, %28 ]
%22 = icmp eq i64 %21, %15
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = mul i64 %21, 3
%25 = and i64 %24, 4294967295
%26 = getelementptr inbounds double, double* %0, i64 %25
%27 = tail call i32 @coulomb_force_one_pair(double* %18, double* %26, double %10, double %4, double* %19)
br label %28
28: ; preds = %20, %23
%29 = add nuw nsw i64 %21, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %20
31: ; preds = %28
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, %13
br i1 %33, label %34, label %14
34: ; preds = %31, %7
ret void
}