#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 distance(int *, int *, int *, int, int);
scalar_t__ populateNeighborList(int *, int *, int, int **);
int /*<<< orphan*/ printf(char *, int);
int buildNeighborList(int position_x[32], int position_y[32],
                      int position_z[32], int NL[32][32]) {
  int totalPairs, i, j, k;
  totalPairs = 0;
  int distIJ;
  for (i = 0; i < 32; i++) {
    int currList[32];
    int currDist[32];
    for (k = 0; k < 32; k++) {
      currList[k] = 0;
      currDist[k] = 999999999;
    }
    for (j = 0; j < 32; j++) {
      if (i == j) {
        continue;
      }
      distIJ = distance(position_x, position_y, position_z, i, j);
      currList[j] = j;
      currDist[j] = distIJ;
    }
    totalPairs += populateNeighborList(currDist, currList, i, NL);
  }
  printf("total pairs - %i \n", totalPairs);
  return totalPairs;
}


x86 assembly (clang, -O0):
<buildNeighborList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x20,-0x28(%rbp)
jge    123c <buildNeighborList+0x10c>
movl   $0x0,-0x30(%rbp)
cmpl   $0x20,-0x30(%rbp)
jge    11a0 <buildNeighborList+0x70>
movslq -0x30(%rbp),%rax
movl   $0x0,-0xc0(%rbp,%rax,4)
movslq -0x30(%rbp),%rax
movl   $0x3b9ac9ff,-0x140(%rbp,%rax,4)
ff c9 9a 3b
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116a <buildNeighborList+0x3a>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x20,-0x2c(%rbp)
jge    1207 <buildNeighborList+0xd7>
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    11c2 <buildNeighborList+0x92>
jmp    11f9 <buildNeighborList+0xc9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
call   1050 <distance@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%ecx
movslq -0x2c(%rbp),%rax
mov    %ecx,-0xc0(%rbp,%rax,4)
mov    -0x34(%rbp),%ecx
movslq -0x2c(%rbp),%rax
mov    %ecx,-0x140(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a7 <buildNeighborList+0x77>
lea    -0x140(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <populateNeighborList@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1159 <buildNeighborList+0x29>
mov    -0x24(%rbp),%esi
lea    0xdba(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildNeighborList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    118a <buildNeighborList+0x5a>
cs nopw 0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
lea    0x90(%rsp),%rsi
mov    %ebp,%edx
mov    0x8(%rsp),%rcx
call   1030 <populateNeighborList@plt>
add    %eax,%r13d
add    $0x1,%rbp
cmp    $0x20,%rbp
je     1245 <buildNeighborList+0x115>
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0x100(%rsp)
movaps 0xe2c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
xor    %r14d,%r14d
jmp    121e <buildNeighborList+0xee>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
cmp    $0x20,%r14
je     1160 <buildNeighborList+0x30>
cmp    %r14,%rbp
je     1210 <buildNeighborList+0xe0>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1050 <distance@plt>
mov    %r14d,0x90(%rsp,%r14,4)
mov    %eax,0x10(%rsp,%r14,4)
jmp    1210 <buildNeighborList+0xe0>
lea    0xdc4(%rip),%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
mov    %r13d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"total pairs - %i \0A\00"
define i32 @buildNeighborList(i32* %0, i32* %1, i32* %2, [32 x i32]* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [32 x i32]*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [32 x i32]
%15 = alloca [32 x i32]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store [32 x i32]* %3, [32 x i32]** %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %16
16: ; preds = %71, %4
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 32
br i1 %18, label %19, label %74
19: ; preds = %16
store i32 0, i32* %12
br label %20
20: ; preds = %30, %19
%21 = load i32, i32* %12
%22 = icmp slt i32 %21, 32
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [32 x i32], [32 x i32]* %14, i64 0, i64 %25
store i32 0, i32* %26
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [32 x i32], [32 x i32]* %15, i64 0, i64 %28
store i32 999999999, i32* %29
br label %30
30: ; preds = %23
%31 = load i32, i32* %12
%32 = add nsw i32 %31, 1
store i32 %32, i32* %12
br label %20
33: ; preds = %20
store i32 0, i32* %11
br label %34
34: ; preds = %57, %33
%35 = load i32, i32* %11
%36 = icmp slt i32 %35, 32
br i1 %36, label %37, label %60
37: ; preds = %34
%38 = load i32, i32* %10
%39 = load i32, i32* %11
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
br label %57
42: ; preds = %37
%43 = load i32*, i32** %5
%44 = load i32*, i32** %6
%45 = load i32*, i32** %7
%46 = load i32, i32* %10
%47 = load i32, i32* %11
%48 = call i32 @distance(i32* %43, i32* %44, i32* %45, i32 %46, i32 %47)
store i32 %48, i32* %13
%49 = load i32, i32* %11
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [32 x i32], [32 x i32]* %14, i64 0, i64 %51
store i32 %49, i32* %52
%53 = load i32, i32* %13
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [32 x i32], [32 x i32]* %15, i64 0, i64 %55
store i32 %53, i32* %56
br label %57
57: ; preds = %42, %41
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %34
60: ; preds = %34
%61 = getelementptr inbounds [32 x i32], [32 x i32]* %15, i64 0, i64 0
%62 = getelementptr inbounds [32 x i32], [32 x i32]* %14, i64 0, i64 0
%63 = load i32, i32* %10
%64 = load [32 x i32]*, [32 x i32]** %8
%65 = bitcast [32 x i32]* %64 to i32**
%66 = call i64 @populateNeighborList(i32* %61, i32* %62, i32 %63, i32** %65)
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = add nsw i64 %68, %66
%70 = trunc i64 %69 to i32
store i32 %70, i32* %9
br label %71
71: ; preds = %60
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %16
74: ; preds = %16
%75 = load i32, i32* %9
%76 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %9
ret i32 %77
}

LLVM IR (-O2):
@.str = [19 x i8] c"total pairs - %i \0A\00"
define i32 @buildNeighborList(i32* %0, i32* %1, i32* %2, [32 x i32]* %3) {
%5 = alloca [32 x i32]
%6 = bitcast [32 x i32]* %5 to i8*
%7 = alloca [32 x i32]
%8 = bitcast [32 x i32]* %7 to i8*
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%11 = bitcast [32 x i32]* %3 to i32**
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 4
%13 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 8
%14 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 12
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 16
%16 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 20
%17 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 24
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 28
%19 = bitcast [32 x i32]* %7 to <4 x i32>*
%20 = bitcast i32* %12 to <4 x i32>*
%21 = bitcast i32* %13 to <4 x i32>*
%22 = bitcast i32* %14 to <4 x i32>*
%23 = bitcast i32* %15 to <4 x i32>*
%24 = bitcast i32* %16 to <4 x i32>*
%25 = bitcast i32* %17 to <4 x i32>*
%26 = bitcast i32* %18 to <4 x i32>*
br label %27
27: ; preds = %4, %42
%28 = phi i64 [ 0, %4 ], [ %47, %42 ]
%29 = phi i32 [ 0, %4 ], [ %46, %42 ]
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %19
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %20
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %21
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %22
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %23
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %24
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %25
store <4 x i32> <i32 999999999, i32 999999999, i32 999999999, i32 999999999>, <4 x i32>* %26
%30 = trunc i64 %28 to i32
br label %31
31: ; preds = %27, %39
%32 = phi i64 [ 0, %27 ], [ %40, %39 ]
%33 = icmp eq i64 %28, %32
br i1 %33, label %39, label %34
34: ; preds = %31
%35 = trunc i64 %32 to i32
%36 = call i32 @distance(i32* %0, i32* %1, i32* %2, i32 %30, i32 %35)
%37 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %32
store i32 %35, i32* %37
%38 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 %32
store i32 %36, i32* %38
br label %39
39: ; preds = %31, %34
%40 = add nuw nsw i64 %32, 1
%41 = icmp eq i64 %40, 32
br i1 %41, label %42, label %31
42: ; preds = %39
%43 = trunc i64 %28 to i32
%44 = call i64 @populateNeighborList(i32* %9, i32* %10, i32 %43, i32** %11)
%45 = trunc i64 %44 to i32
%46 = add i32 %29, %45
%47 = add nuw nsw i64 %28, 1
%48 = icmp eq i64 %47, 32
br i1 %48, label %49, label %27
49: ; preds = %42
%50 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %46)
ret i32 %46
}