#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*/ force_gravity(double *, double *, double, double, double *);
void calculate_forces(double positions[4][2], double masses[4],
                      double forces[4][2]) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (i != j) {
        force_gravity(positions[i], positions[j], masses[i], masses[j],
                      forces[i]);
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<calculate_forces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11c4 <calculate_forces+0xb4>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11b1 <calculate_forces+0xa1>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     119e <calculate_forces+0x8e>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdx
call   1030 <force_gravity@plt>
jmp    11a3 <calculate_forces+0x93>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113c <calculate_forces+0x2c>
jmp    11b6 <calculate_forces+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <calculate_forces+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_forces>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x10(%rdi),%r12
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm1
mov    %r12,%rsi
call   1030 <force_gravity@plt>
lea    0x20(%r15),%rbp
movsd  (%rbx),%xmm0
movsd  0x10(%rbx),%xmm1
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rbp,(%rsp)
mov    %r14,%rdx
call   1030 <force_gravity@plt>
lea    0x30(%r15),%rsi
mov    %rsi,0x8(%rsp)
movsd  (%rbx),%xmm0
movsd  0x18(%rbx),%xmm1
mov    %r15,%rdi
mov    %r14,%rdx
call   1030 <force_gravity@plt>
lea    0x10(%r14),%r13
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
mov    %r12,%rdi
mov    %r15,0x10(%rsp)
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <force_gravity@plt>
movsd  0x8(%rbx),%xmm0
movsd  0x10(%rbx),%xmm1
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1030 <force_gravity@plt>
movsd  0x8(%rbx),%xmm0
movsd  0x18(%rbx),%xmm1
mov    %r12,%r15
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
mov    %rsi,%rbp
mov    %r13,%rdx
call   1030 <force_gravity@plt>
add    $0x20,%r14
mov    $0x2,%r12d
mov    (%rsp),%r13
jmp    1205 <calculate_forces+0xf5>
movsd  (%rbx,%r12,8),%xmm0
movsd  0x18(%rbx),%xmm1
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <force_gravity@plt>
add    $0x1,%r12
add    $0x10,%r13
add    $0x10,%r14
movsd  (%rbx,%r12,8),%xmm0
movsd  (%rbx),%xmm1
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
mov    %r14,%rdx
call   1030 <force_gravity@plt>
movsd  (%rbx,%r12,8),%xmm0
movsd  0x8(%rbx),%xmm1
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <force_gravity@plt>
cmp    $0x2,%r12
je     11e0 <calculate_forces+0xd0>
movsd  (%rbx,%r12,8),%xmm0
movsd  0x10(%rbx),%xmm1
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    %r14,%rdx
call   1030 <force_gravity@plt>
cmp    $0x3,%r12
jne    11e0 <calculate_forces+0xd0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @calculate_forces([2 x double]* %0, double* %1, [2 x double]* %2) {
%4 = alloca [2 x double]*
%5 = alloca double*
%6 = alloca [2 x double]*
%7 = alloca i32
%8 = alloca i32
store [2 x double]* %0, [2 x double]** %4
store double* %1, double** %5
store [2 x double]* %2, [2 x double]** %6
store i32 0, i32* %7
br label %9
9: ; preds = %52, %3
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %55
12: ; preds = %9
store i32 0, i32* %8
br label %13
13: ; preds = %48, %12
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %51
16: ; preds = %13
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load [2 x double]*, [2 x double]** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [2 x double], [2 x double]* %21, i64 %23
%25 = getelementptr inbounds [2 x double], [2 x double]* %24, i64 0, i64 0
%26 = load [2 x double]*, [2 x double]** %4
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [2 x double], [2 x double]* %26, i64 %28
%30 = getelementptr inbounds [2 x double], [2 x double]* %29, i64 0, i64 0
%31 = load double*, double** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %5
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load [2 x double]*, [2 x double]** %6
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [2 x double], [2 x double]* %41, i64 %43
%45 = getelementptr inbounds [2 x double], [2 x double]* %44, i64 0, i64 0
%46 = call i32 @force_gravity(double* %25, double* %30, double %35, double %40, double* %45)
br label %47
47: ; preds = %20, %16
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %13
51: ; preds = %13
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %9
55: ; preds = %9
ret void
}

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