#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*/ free(double *);
int /*<<< orphan*/ getNormal(double *, double *);
double *malloc(int);
void computeNormalXForces(int nbPoints, double *forcesToRead,
                          double *positionsToRead, double *arrayToFill) {
  double *currentNormal = malloc(sizeof(double) * 3);
  int idxPart, i;
  for (idxPart = 0; idxPart < nbPoints; ++idxPart) {
    getNormal(&positionsToRead[idxPart], currentNormal);
    for (i = 0; i < 3; ++i) {
      arrayToFill[idxPart] += currentNormal[i] * forcesToRead[idxPart + i];
    }
  }
  free(currentNormal);
}


x86 assembly (clang, -O0):
<computeNormalXForces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11eb <computeNormalXForces+0xbb>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <getNormal@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    11d8 <computeNormalXForces+0xa8>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1187 <computeNormalXForces+0x57>
jmp    11dd <computeNormalXForces+0xad>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115c <computeNormalXForces+0x2c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeNormalXForces>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11b7 <computeNormalXForces+0x87>
mov    %ebp,%r13d
shl    $0x3,%r13
xor    %ebp,%ebp
lea    (%r14,%rbp,1),%rdi
mov    %rbx,%rsi
call   1040 <getNormal@plt>
movsd  (%rbx),%xmm0
mulsd  (%r15,%rbp,1),%xmm0
addsd  (%r12,%rbp,1),%xmm0
movsd  %xmm0,(%r12,%rbp,1)
movsd  0x8(%rbx),%xmm1
mulsd  0x8(%r15,%rbp,1),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rbp,1)
movsd  0x10(%rbx),%xmm0
mulsd  0x10(%r15,%rbp,1),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%rbp,1)
add    $0x8,%rbp
cmp    %rbp,%r13
jne    1160 <computeNormalXForces+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

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