#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 */
double distance_periodic(double *, double *, double);
int /*<<< orphan*/ max_abs(double **, int);
double sqrt(int /*<<< orphan*/);
void update_neighborlist(double ****neighbor, double *amount_neighbor,
                         double particles[][3], double velocities[][3],
                         int amount, double region, int refresh, double rc,
                         double dt) {
  int i, j, k;
  double vmax, radius;
  static int called = 0;
  if (called % refresh == 0) {
    vmax = sqrt(max_abs(velocities, amount));
    radius = rc + refresh * vmax * dt;
#pragma omp parallel for private(j, k)
    for (i = 0; i < amount; i++) {
      int l = 0;
      for (j = 0; j < amount; j++) {
        if (i != j) {
          double distance_ij =
              distance_periodic(particles[i], particles[j], region);
          if (distance_ij < radius * radius) {
            for (k = 0; k < 3; k++) {
              neighbor[i][l + 1][k] = &particles[j][k];
            }
            l++;
          }
        }
      }
      amount_neighbor[i] = (double)l;
      neighbor[i][0][0] = &amount_neighbor[i];
    }
#pragma omp barrier
  }
  called++;
}


x86 assembly (clang, -O0):
<update_neighborlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movsd  %xmm1,-0x40(%rbp)
movsd  %xmm2,-0x48(%rbp)
mov    0x2ed4(%rip),%eax
cltd
idivl  -0x34(%rbp)
cmp    $0x0,%edx
jne    12ee <update_neighborlist+0x1be>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <max_abs@plt>
mov    %eax,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12e9 <update_neighborlist+0x1b9>
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12a8 <update_neighborlist+0x178>
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
je     1295 <update_neighborlist+0x165>
mov    -0x18(%rbp),%rdi
movslq -0x4c(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x50(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
movsd  -0x30(%rbp),%xmm0
call   1040 <distance_periodic@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1290 <update_neighborlist+0x160>
movl   $0x0,-0x54(%rbp)
cmpl   $0x3,-0x54(%rbp)
jge    1287 <update_neighborlist+0x157>
mov    -0x18(%rbp),%rdx
movslq -0x50(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdx
movslq -0x54(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x6c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x54(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1234 <update_neighborlist+0x104>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1295 <update_neighborlist+0x165>
jmp    129a <update_neighborlist+0x16a>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11cf <update_neighborlist+0x9f>
cvtsi2sdl -0x6c(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rcx
movslq -0x4c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11b5 <update_neighborlist+0x85>
jmp    12ee <update_neighborlist+0x1be>
mov    0x2d48(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d3f(%rip)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_neighborlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm0,0x30(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,0x10(%rsp)
mov    0x2ee3(%rip),%eax
cltd
idiv   %r9d
test   %edx,%edx
je     1177 <update_neighborlist+0x47>
addl   $0x1,0x2ed4(%rip)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r9d,%ebp
mov    %r8d,%ebx
mov    %rcx,%rdi
mov    %r8d,%esi
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x18(%rsp)
call   1030 <max_abs@plt>
mov    %eax,%edi
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
test   %ebx,%ebx
jle    1161 <update_neighborlist+0x31>
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%ebp
xor    %r14d,%r14d
jmp    1203 <update_neighborlist+0xd3>
nop
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mov    0x20(%rsp),%rcx
lea    (%rcx,%r14,8),%rax
movsd  %xmm0,(%rcx,%r14,8)
mov    0x10(%rsp),%rcx
mov    (%rcx,%r14,8),%rcx
mov    (%rcx),%rcx
mov    %rax,(%rcx)
add    $0x1,%r14
cmp    %rbp,%r14
je     1161 <update_neighborlist+0x31>
lea    (%r14,%r14,2),%rax
mov    0x28(%rsp),%rbx
lea    (%rbx,%rax,8),%r13
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    122d <update_neighborlist+0xfd>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x18,%rbx
cmp    %r12,%rbp
je     11d0 <update_neighborlist+0xa0>
cmp    %r12,%r14
je     1220 <update_neighborlist+0xf0>
mov    %r13,%rdi
mov    %rbx,%rsi
movsd  0x30(%rsp),%xmm0
call   1040 <distance_periodic@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1220 <update_neighborlist+0xf0>
movslq %r15d,%rax
add    $0x1,%r15d
mov    0x10(%rsp),%rsi
mov    (%rsi,%r14,8),%rcx
mov    0x8(%rcx,%rax,8),%rcx
mov    %rbx,(%rcx)
lea    0x8(%rbx),%rcx
mov    (%rsi,%r14,8),%rdx
mov    0x8(%rdx,%rax,8),%rdx
mov    %rcx,0x8(%rdx)
lea    0x10(%rbx),%rcx
mov    (%rsi,%r14,8),%rdx
mov    0x8(%rdx,%rax,8),%rax
mov    %rcx,0x10(%rax)
jmp    1220 <update_neighborlist+0xf0>

LLVM IR (-O0):
@update_neighborlist.called = internal global i32 0
define void @update_neighborlist(double**** %0, double* %1, [3 x double]* %2, [3 x double]* %3, i32 %4, double %5, i32 %6, double %7, double %8) {
%10 = alloca double****
%11 = alloca double*
%12 = alloca [3 x double]*
%13 = alloca [3 x double]*
%14 = alloca i32
%15 = alloca double
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca double
%23 = alloca double
%24 = alloca i32
%25 = alloca double
store double**** %0, double***** %10
store double* %1, double** %11
store [3 x double]* %2, [3 x double]** %12
store [3 x double]* %3, [3 x double]** %13
store i32 %4, i32* %14
store double %5, double* %15
store i32 %6, i32* %16
store double %7, double* %17
store double %8, double* %18
%26 = load i32, i32* @update_neighborlist.called
%27 = load i32, i32* %16
%28 = srem i32 %26, %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %133
30: ; preds = %9
%31 = load [3 x double]*, [3 x double]** %13
%32 = bitcast [3 x double]* %31 to double**
%33 = load i32, i32* %14
%34 = call i32 @max_abs(double** %32, i32 %33)
%35 = call double @sqrt(i32 %34)
store double %35, double* %22
%36 = load double, double* %17
%37 = load i32, i32* %16
%38 = sitofp i32 %37 to double
%39 = load double, double* %22
%40 = fmul double %38, %39
%41 = load double, double* %18
%42 = call double @llvm.fmuladd.f64(double %40, double %41, double %36)
store double %42, double* %23
store i32 0, i32* %19
br label %43
43: ; preds = %129, %30
%44 = load i32, i32* %19
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %132
47: ; preds = %43
store i32 0, i32* %24
store i32 0, i32* %20
br label %48
48: ; preds = %107, %47
%49 = load i32, i32* %20
%50 = load i32, i32* %14
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %110
52: ; preds = %48
%53 = load i32, i32* %19
%54 = load i32, i32* %20
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %106
56: ; preds = %52
%57 = load [3 x double]*, [3 x double]** %12
%58 = load i32, i32* %19
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [3 x double], [3 x double]* %57, i64 %59
%61 = getelementptr inbounds [3 x double], [3 x double]* %60, i64 0, i64 0
%62 = load [3 x double]*, [3 x double]** %12
%63 = load i32, i32* %20
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [3 x double], [3 x double]* %62, i64 %64
%66 = getelementptr inbounds [3 x double], [3 x double]* %65, i64 0, i64 0
%67 = load double, double* %15
%68 = call double @distance_periodic(double* %61, double* %66, double %67)
store double %68, double* %25
%69 = load double, double* %25
%70 = load double, double* %23
%71 = load double, double* %23
%72 = fmul double %70, %71
%73 = fcmp olt double %69, %72
br i1 %73, label %74, label %105
74: ; preds = %56
store i32 0, i32* %21
br label %75
75: ; preds = %99, %74
%76 = load i32, i32* %21
%77 = icmp slt i32 %76, 3
br i1 %77, label %78, label %102
78: ; preds = %75
%79 = load [3 x double]*, [3 x double]** %12
%80 = load i32, i32* %20
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [3 x double], [3 x double]* %79, i64 %81
%83 = load i32, i32* %21
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [3 x double], [3 x double]* %82, i64 0, i64 %84
%86 = load double****, double***** %10
%87 = load i32, i32* %19
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double***, double**** %86, i64 %88
%90 = load double***, double**** %89
%91 = load i32, i32* %24
%92 = add nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double**, double*** %90, i64 %93
%95 = load double**, double*** %94
%96 = load i32, i32* %21
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds double*, double** %95, i64 %97
store double* %85, double** %98
br label %99
99: ; preds = %78
%100 = load i32, i32* %21
%101 = add nsw i32 %100, 1
store i32 %101, i32* %21
br label %75
102: ; preds = %75
%103 = load i32, i32* %24
%104 = add nsw i32 %103, 1
store i32 %104, i32* %24
br label %105
105: ; preds = %102, %56
br label %106
106: ; preds = %105, %52
br label %107
107: ; preds = %106
%108 = load i32, i32* %20
%109 = add nsw i32 %108, 1
store i32 %109, i32* %20
br label %48
110: ; preds = %48
%111 = load i32, i32* %24
%112 = sitofp i32 %111 to double
%113 = load double*, double** %11
%114 = load i32, i32* %19
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds double, double* %113, i64 %115
store double %112, double* %116
%117 = load double*, double** %11
%118 = load i32, i32* %19
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %117, i64 %119
%121 = load double****, double***** %10
%122 = load i32, i32* %19
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds double***, double**** %121, i64 %123
%125 = load double***, double**** %124
%126 = getelementptr inbounds double**, double*** %125, i64 0
%127 = load double**, double*** %126
%128 = getelementptr inbounds double*, double** %127, i64 0
store double* %120, double** %128
br label %129
129: ; preds = %110
%130 = load i32, i32* %19
%131 = add nsw i32 %130, 1
store i32 %131, i32* %19
br label %43
132: ; preds = %43
br label %133
133: ; preds = %132, %9
%134 = load i32, i32* @update_neighborlist.called
%135 = add nsw i32 %134, 1
store i32 %135, i32* @update_neighborlist.called
ret void
}

LLVM IR (-O2):
@update_neighborlist.called = internal unnamed_addr global i32 0
define void @update_neighborlist(double**** nocapture %0, double* %1, [3 x double]* %2, [3 x double]* %3, i32 %4, double %5, i32 %6, double %7, double %8) {
%10 = load i32, i32* @update_neighborlist.called
%11 = srem i32 %10, %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %64
13: ; preds = %9
%14 = bitcast [3 x double]* %3 to double**
%15 = tail call i32 @max_abs(double** %14, i32 %4)
%16 = tail call double @sqrt(i32 %15)
%17 = icmp sgt i32 %4, 0
br i1 %17, label %18, label %64
18: ; preds = %13
%19 = sitofp i32 %6 to double
%20 = fmul double %16, %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %8, double %7)
%22 = fmul double %21, %21
%23 = zext i32 %4 to i64
br label %24
24: ; preds = %56, %18
%25 = phi i64 [ 0, %18 ], [ %62, %56 ]
%26 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %25, i64 0
%27 = getelementptr inbounds double***, double**** %0, i64 %25
br label %28
28: ; preds = %24, %52
%29 = phi i64 [ 0, %24 ], [ %54, %52 ]
%30 = phi i32 [ 0, %24 ], [ %53, %52 ]
%31 = icmp eq i64 %25, %29
br i1 %31, label %52, label %32
32: ; preds = %28
%33 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %29, i64 0
%34 = tail call double @distance_periodic(double* %26, double* %33, double %5)
%35 = fcmp olt double %34, %22
br i1 %35, label %36, label %52
36: ; preds = %32
%37 = add nsw i32 %30, 1
%38 = sext i32 %37 to i64
%39 = load double***, double**** %27
%40 = getelementptr inbounds double**, double*** %39, i64 %38
%41 = load double**, double*** %40
store double* %33, double** %41
%42 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %29, i64 1
%43 = load double***, double**** %27
%44 = getelementptr inbounds double**, double*** %43, i64 %38
%45 = load double**, double*** %44
%46 = getelementptr inbounds double*, double** %45, i64 1
store double* %42, double** %46
%47 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %29, i64 2
%48 = load double***, double**** %27
%49 = getelementptr inbounds double**, double*** %48, i64 %38
%50 = load double**, double*** %49
%51 = getelementptr inbounds double*, double** %50, i64 2
store double* %47, double** %51
br label %52
52: ; preds = %32, %36, %28
%53 = phi i32 [ %30, %28 ], [ %37, %36 ], [ %30, %32 ]
%54 = add nuw nsw i64 %29, 1
%55 = icmp eq i64 %54, %23
br i1 %55, label %56, label %28
56: ; preds = %52
%57 = sitofp i32 %53 to double
%58 = getelementptr inbounds double, double* %1, i64 %25
store double %57, double* %58
%59 = getelementptr inbounds double***, double**** %0, i64 %25
%60 = load double***, double**** %59
%61 = load double**, double*** %60
store double* %58, double** %61
%62 = add nuw nsw i64 %25, 1
%63 = icmp eq i64 %62, %23
br i1 %63, label %64, label %24
64: ; preds = %56, %13, %9
%65 = load i32, i32* @update_neighborlist.called
%66 = add nsw i32 %65, 1
store i32 %66, i32* @update_neighborlist.called
ret void
}