#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*/ assert(int);
int /*<<< orphan*/ g5_get_forceMC(int, int, double **, double *);
int g5_get_number_of_pipelines();
int /*<<< orphan*/ g5_runMC(int);
int /*<<< orphan*/ g5_set_xiMC(int, int, double **);
void g5_calculate_force_on_xMC(int devid, double (*x)[3], double (*a)[3],
                               double *p, int ni) {
  assert(devid < (128));
  int off;
  int np = g5_get_number_of_pipelines();
  for (off = 0; off < ni; off += np) {
    int nii = np < ni - off ? np : ni - off;
    g5_set_xiMC(devid, nii, x + off);
    g5_runMC(devid);
    g5_get_forceMC(devid, nii, a + off, p + off);
  }
}


x86 assembly (clang, -O0):
<g5_calculate_force_on_xMC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpl   $0x80,-0x4(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x0,%al
call   1030 <g5_get_number_of_pipelines@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1220 <g5_calculate_force_on_xMC+0xd0>
mov    -0x2c(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    11b8 <g5_calculate_force_on_xMC+0x68>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11c1 <g5_calculate_force_on_xMC+0x71>
mov    -0x24(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rdx
movslq -0x28(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdx
call   1050 <g5_set_xiMC@plt>
mov    -0x4(%rbp),%edi
call   1070 <g5_runMC@plt>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x18(%rbp),%rdx
movslq -0x28(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
call   1040 <g5_get_forceMC@plt>
mov    -0x2c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1190 <g5_calculate_force_on_xMC+0x40>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g5_calculate_force_on_xMC>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%ebp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%eax
xor    %edi,%edi
mov    %eax,0x4(%rsp)
cmp    $0x80,%eax
setl   %dil
call   1060 <assert@plt>
xor    %eax,%eax
call   1030 <g5_get_number_of_pipelines@plt>
test   %ebp,%ebp
jle    123c <g5_calculate_force_on_xMC+0xec>
mov    %r15,%rcx
cltq
mov    %ebp,%edx
mov    %rax,0x28(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x18(%rsp)
lea    (%rax,%rax,2),%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
mov    %rdx,0x20(%rsp)
mov    %rdx,%rax
mov    %rdx,%r12
mov    0x28(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,0x8(%rsp)
mov    %rbx,0x30(%rsp)
sub    %r15,%r12
mov    %r15d,%ebp
cmovle %eax,%ebp
mov    %r14,%rbx
mov    0x4(%rsp),%r14d
mov    %r14d,%edi
mov    %ebp,%esi
mov    0x8(%rsp),%rdx
call   1050 <g5_set_xiMC@plt>
mov    %r14d,%edi
call   1070 <g5_runMC@plt>
mov    %r14d,%edi
mov    %rbx,%r14
mov    0x30(%rsp),%rbx
mov    %ebp,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <g5_get_forceMC@plt>
mov    0x8(%rsp),%rcx
add    %r15,%r13
mov    0x10(%rsp),%rax
add    %rax,%rcx
add    %rax,%r14
add    0x18(%rsp),%rbx
mov    %r12,%rax
cmp    0x20(%rsp),%r13
jl     11d0 <g5_calculate_force_on_xMC+0x80>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @g5_calculate_force_on_xMC(i32 %0, [3 x double]* %1, [3 x double]* %2, double* %3, i32 %4) {
%6 = icmp slt i32 %0, 128
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 (...) @g5_get_number_of_pipelines()
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %30
11: ; preds = %5
%12 = sext i32 %9 to i64
%13 = zext i32 %4 to i64
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %28, %14 ]
%16 = sub nsw i64 %13, %15
%17 = icmp sgt i64 %16, %12
%18 = trunc i64 %16 to i32
%19 = select i1 %17, i32 %9, i32 %18
%20 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 %15
%21 = bitcast [3 x double]* %20 to double**
%22 = tail call i32 @g5_set_xiMC(i32 %0, i32 %19, double** %21)
%23 = tail call i32 @g5_runMC(i32 %0)
%24 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %15
%25 = bitcast [3 x double]* %24 to double**
%26 = getelementptr inbounds double, double* %3, i64 %15
%27 = tail call i32 @g5_get_forceMC(i32 %0, i32 %19, double** %25, double* %26)
%28 = add i64 %15, %12
%29 = icmp slt i64 %28, %13
br i1 %29, label %14, label %30
30: ; preds = %14, %5
ret void
}