#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*/ omp_set_num_threads(int);
void update_neighborlist(double ****neighbor, double *amount_neighbor,
                         double particles[][3], double radius, int amount,
                         double region) {
  int i, j, k;
  omp_set_num_threads(8);
#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
}


x86 assembly (clang, -O0):
<update_neighborlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    $0x8,%edi
call   1030 <omp_set_num_threads@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1286 <update_neighborlist+0x166>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1245 <update_neighborlist+0x125>
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     1232 <update_neighborlist+0x112>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x38(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
movsd  -0x30(%rbp),%xmm0
call   1040 <distance_periodic@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    122d <update_neighborlist+0x10d>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    1224 <update_neighborlist+0x104>
mov    -0x18(%rbp),%rdx
movslq -0x38(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdx
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x40(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d1 <update_neighborlist+0xb1>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1232 <update_neighborlist+0x112>
jmp    1237 <update_neighborlist+0x117>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    116c <update_neighborlist+0x4c>
cvtsi2sdl -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rcx
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1152 <update_neighborlist+0x32>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_neighborlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
mov    %ecx,%ebx
movsd  %xmm0,(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
mov    $0x8,%edi
call   1030 <omp_set_num_threads@plt>
test   %ebx,%ebx
jle    122a <update_neighborlist+0x10a>
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %ebx,%ebp
xor    %r14d,%r14d
jmp    119f <update_neighborlist+0x7f>
nop
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mov    0x8(%rsp),%rcx
lea    (%rcx,%r14,8),%rax
movsd  %xmm0,(%rcx,%r14,8)
mov    0x0(%r13,%r14,8),%rcx
mov    (%rcx),%rcx
mov    %rax,(%rcx)
add    $0x1,%r14
cmp    %rbp,%r14
je     122a <update_neighborlist+0x10a>
lea    (%r14,%r14,2),%rax
mov    0x10(%rsp),%rbx
lea    (%rbx,%rax,8),%rax
mov    %rax,0x20(%rsp)
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    11cd <update_neighborlist+0xad>
nopl   0x0(%rax)
add    $0x1,%r12
add    $0x18,%rbx
cmp    %r12,%rbp
je     1170 <update_neighborlist+0x50>
cmp    %r12,%r14
je     11c0 <update_neighborlist+0xa0>
mov    0x20(%rsp),%rdi
mov    %rbx,%rsi
movsd  0x18(%rsp),%xmm0
call   1040 <distance_periodic@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    11c0 <update_neighborlist+0xa0>
movslq %r15d,%rax
add    $0x1,%r15d
mov    0x0(%r13,%r14,8),%rcx
mov    0x8(%rcx,%rax,8),%rcx
mov    %rbx,(%rcx)
lea    0x8(%rbx),%rcx
mov    0x0(%r13,%r14,8),%rdx
mov    0x8(%rdx,%rax,8),%rdx
mov    %rcx,0x8(%rdx)
lea    0x10(%rbx),%rcx
mov    0x0(%r13,%r14,8),%rdx
mov    0x8(%rdx,%rax,8),%rax
mov    %rcx,0x10(%rax)
jmp    11c0 <update_neighborlist+0xa0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @update_neighborlist(double**** %0, double* %1, [3 x double]* %2, double %3, i32 %4, double %5) {
%7 = alloca double****
%8 = alloca double*
%9 = alloca [3 x double]*
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
store double**** %0, double***** %7
store double* %1, double** %8
store [3 x double]* %2, [3 x double]** %9
store double %3, double* %10
store i32 %4, i32* %11
store double %5, double* %12
%18 = call i32 @omp_set_num_threads(i32 8)
store i32 0, i32* %13
br label %19
19: ; preds = %105, %6
%20 = load i32, i32* %13
%21 = load i32, i32* %11
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %108
23: ; preds = %19
store i32 0, i32* %16
store i32 0, i32* %14
br label %24
24: ; preds = %83, %23
%25 = load i32, i32* %14
%26 = load i32, i32* %11
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %86
28: ; preds = %24
%29 = load i32, i32* %13
%30 = load i32, i32* %14
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %82
32: ; preds = %28
%33 = load [3 x double]*, [3 x double]** %9
%34 = load i32, i32* %13
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [3 x double], [3 x double]* %33, i64 %35
%37 = getelementptr inbounds [3 x double], [3 x double]* %36, i64 0, i64 0
%38 = load [3 x double]*, [3 x double]** %9
%39 = load i32, i32* %14
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [3 x double], [3 x double]* %38, i64 %40
%42 = getelementptr inbounds [3 x double], [3 x double]* %41, i64 0, i64 0
%43 = load double, double* %12
%44 = call double @distance_periodic(double* %37, double* %42, double %43)
store double %44, double* %17
%45 = load double, double* %17
%46 = load double, double* %10
%47 = load double, double* %10
%48 = fmul double %46, %47
%49 = fcmp olt double %45, %48
br i1 %49, label %50, label %81
50: ; preds = %32
store i32 0, i32* %15
br label %51
51: ; preds = %75, %50
%52 = load i32, i32* %15
%53 = icmp slt i32 %52, 3
br i1 %53, label %54, label %78
54: ; preds = %51
%55 = load [3 x double]*, [3 x double]** %9
%56 = load i32, i32* %14
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [3 x double], [3 x double]* %55, i64 %57
%59 = load i32, i32* %15
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [3 x double], [3 x double]* %58, i64 0, i64 %60
%62 = load double****, double***** %7
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double***, double**** %62, i64 %64
%66 = load double***, double**** %65
%67 = load i32, i32* %16
%68 = add nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double**, double*** %66, i64 %69
%71 = load double**, double*** %70
%72 = load i32, i32* %15
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double*, double** %71, i64 %73
store double* %61, double** %74
br label %75
75: ; preds = %54
%76 = load i32, i32* %15
%77 = add nsw i32 %76, 1
store i32 %77, i32* %15
br label %51
78: ; preds = %51
%79 = load i32, i32* %16
%80 = add nsw i32 %79, 1
store i32 %80, i32* %16
br label %81
81: ; preds = %78, %32
br label %82
82: ; preds = %81, %28
br label %83
83: ; preds = %82
%84 = load i32, i32* %14
%85 = add nsw i32 %84, 1
store i32 %85, i32* %14
br label %24
86: ; preds = %24
%87 = load i32, i32* %16
%88 = sitofp i32 %87 to double
%89 = load double*, double** %8
%90 = load i32, i32* %13
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
store double %88, double* %92
%93 = load double*, double** %8
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %93, i64 %95
%97 = load double****, double***** %7
%98 = load i32, i32* %13
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double***, double**** %97, i64 %99
%101 = load double***, double**** %100
%102 = getelementptr inbounds double**, double*** %101, i64 0
%103 = load double**, double*** %102
%104 = getelementptr inbounds double*, double** %103, i64 0
store double* %96, double** %104
br label %105
105: ; preds = %86
%106 = load i32, i32* %13
%107 = add nsw i32 %106, 1
store i32 %107, i32* %13
br label %19
108: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @update_neighborlist(double**** nocapture %0, double* %1, [3 x double]* %2, double %3, i32 %4, double %5) {
%7 = tail call i32 @omp_set_num_threads(i32 8)
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %52
9: ; preds = %6
%10 = fmul double %3, %3
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %44, %9
%13 = phi i64 [ 0, %9 ], [ %50, %44 ]
%14 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %13, i64 0
%15 = getelementptr inbounds double***, double**** %0, i64 %13
br label %16
16: ; preds = %12, %40
%17 = phi i64 [ 0, %12 ], [ %42, %40 ]
%18 = phi i32 [ 0, %12 ], [ %41, %40 ]
%19 = icmp eq i64 %13, %17
br i1 %19, label %40, label %20
20: ; preds = %16
%21 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %17, i64 0
%22 = tail call double @distance_periodic(double* %14, double* %21, double %5)
%23 = fcmp olt double %22, %10
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = add nsw i32 %18, 1
%26 = sext i32 %25 to i64
%27 = load double***, double**** %15
%28 = getelementptr inbounds double**, double*** %27, i64 %26
%29 = load double**, double*** %28
store double* %21, double** %29
%30 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %17, i64 1
%31 = load double***, double**** %15
%32 = getelementptr inbounds double**, double*** %31, i64 %26
%33 = load double**, double*** %32
%34 = getelementptr inbounds double*, double** %33, i64 1
store double* %30, double** %34
%35 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %17, i64 2
%36 = load double***, double**** %15
%37 = getelementptr inbounds double**, double*** %36, i64 %26
%38 = load double**, double*** %37
%39 = getelementptr inbounds double*, double** %38, i64 2
store double* %35, double** %39
br label %40
40: ; preds = %20, %24, %16
%41 = phi i32 [ %18, %16 ], [ %25, %24 ], [ %18, %20 ]
%42 = add nuw nsw i64 %17, 1
%43 = icmp eq i64 %42, %11
br i1 %43, label %44, label %16
44: ; preds = %40
%45 = sitofp i32 %41 to double
%46 = getelementptr inbounds double, double* %1, i64 %13
store double %45, double* %46
%47 = getelementptr inbounds double***, double**** %0, i64 %13
%48 = load double***, double**** %47
%49 = load double**, double*** %48
store double* %46, double** %49
%50 = add nuw nsw i64 %13, 1
%51 = icmp eq i64 %50, %11
br i1 %51, label %52, label %12
52: ; preds = %44, %6
ret void
}