#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 */
size_t get_grid_point(int *, int const *);
int /*<<< orphan*/ get_vector_modulo(int *, int *);
void kpt_get_neighboring_grid_points(
    int neighboring_grid_points[], const int grid_point,
    int relative_grid_address[][3], const int num_relative_grid_address,
    const int mesh[3], int bz_grid_address[][3], const int bz_map[]) {
  int mesh_double[3], bzmesh[3], bzmesh_double[3], address_double[3],
      bz_address_double[3];
  int i, j, bz_gp;
  for (i = 0; i < 3; i++) {
    mesh_double[i] = mesh[i] * 2;
    bzmesh[i] = mesh[i] * 2;
    bzmesh_double[i] = bzmesh[i] * 2;
  }
  for (i = 0; i < num_relative_grid_address; i++) {
    for (j = 0; j < 3; j++) {
      address_double[j] =
          (bz_grid_address[grid_point][j] + relative_grid_address[i][j]) * 2;
      bz_address_double[j] = address_double[j];
    }
    get_vector_modulo(bz_address_double, bzmesh_double);
    bz_gp = bz_map[get_grid_point(bz_address_double, bzmesh)];
    if (bz_gp == -1) {
      get_vector_modulo(address_double, mesh_double);
      neighboring_grid_points[i] = get_grid_point(address_double, mesh);
    } else {
      neighboring_grid_points[i] = bz_gp;
    }
  }
}


x86 assembly (clang, -O0):
<kpt_get_neighboring_grid_points>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x70(%rbp)
cmpl   $0x3,-0x70(%rbp)
jge    11a3 <kpt_get_neighboring_grid_points+0x83>
mov    -0x28(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
shl    $0x1,%ecx
movslq -0x70(%rbp),%rax
mov    %ecx,-0x3c(%rbp,%rax,4)
mov    -0x28(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
shl    $0x1,%ecx
movslq -0x70(%rbp),%rax
mov    %ecx,-0x48(%rbp,%rax,4)
movslq -0x70(%rbp),%rax
mov    -0x48(%rbp,%rax,4),%ecx
shl    $0x1,%ecx
movslq -0x70(%rbp),%rax
mov    %ecx,-0x54(%rbp,%rax,4)
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    114c <kpt_get_neighboring_grid_points+0x2c>
movl   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12a2 <kpt_get_neighboring_grid_points+0x182>
movl   $0x0,-0x74(%rbp)
cmpl   $0x3,-0x74(%rbp)
jge    121c <kpt_get_neighboring_grid_points+0xfc>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%rax
movslq -0x70(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
movslq -0x74(%rbp),%rdx
add    (%rax,%rdx,4),%ecx
shl    $0x1,%ecx
movslq -0x74(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
movslq -0x74(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%ecx
movslq -0x74(%rbp),%rax
mov    %ecx,-0x6c(%rbp,%rax,4)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11bd <kpt_get_neighboring_grid_points+0x9d>
lea    -0x6c(%rbp),%rdi
lea    -0x54(%rbp),%rsi
call   1040 <get_vector_modulo@plt>
mov    0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x6c(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <get_grid_point@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0xffffffff,-0x78(%rbp)
jne    1281 <kpt_get_neighboring_grid_points+0x161>
lea    -0x60(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1040 <get_vector_modulo@plt>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <get_grid_point@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    128f <kpt_get_neighboring_grid_points+0x16f>
mov    -0x78(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1294 <kpt_get_neighboring_grid_points+0x174>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    11aa <kpt_get_neighboring_grid_points+0x8a>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kpt_get_neighboring_grid_points>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%rbx
mov    (%r8),%eax
lea    (%rax,%rax,1),%edx
mov    %edx,0x34(%rsp)
mov    %edx,0x28(%rsp)
shl    $0x2,%eax
mov    %eax,0x1c(%rsp)
mov    0x4(%r8),%eax
lea    (%rax,%rax,1),%edx
mov    %edx,0x38(%rsp)
mov    %edx,0x2c(%rsp)
shl    $0x2,%eax
mov    %eax,0x20(%rsp)
mov    %r8,0x40(%rsp)
mov    0x8(%r8),%eax
lea    (%rax,%rax,1),%edx
mov    %edx,0x3c(%rsp)
mov    %edx,0x30(%rsp)
shl    $0x2,%eax
mov    %eax,0x24(%rsp)
test   %ecx,%ecx
jle    1246 <kpt_get_neighboring_grid_points+0x126>
mov    %rdi,%r15
movslq %esi,%rax
mov    %ecx,%r14d
lea    (%rax,%rax,2),%rax
lea    (%r9,%rax,4),%r13
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0x4(%rsp),%r12
jmp    11b5 <kpt_get_neighboring_grid_points+0x95>
nopl   (%rax)
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
add    $0xc,%rbx
cmp    %rbp,%r14
je     1246 <kpt_get_neighboring_grid_points+0x126>
mov    -0x8(%rbx),%eax
add    0x0(%r13),%eax
add    %eax,%eax
mov    %eax,0x10(%rsp)
mov    %eax,0x4(%rsp)
mov    -0x4(%rbx),%eax
add    0x4(%r13),%eax
add    %eax,%eax
mov    %eax,0x14(%rsp)
mov    %eax,0x8(%rsp)
mov    (%rbx),%eax
add    0x8(%r13),%eax
add    %eax,%eax
mov    %eax,0x18(%rsp)
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
lea    0x1c(%rsp),%rsi
call   1040 <get_vector_modulo@plt>
mov    %r12,%rdi
lea    0x28(%rsp),%rsi
call   1030 <get_grid_point@plt>
mov    0x80(%rsp),%rcx
mov    (%rcx,%rax,4),%eax
cmp    $0xffffffff,%eax
jne    11a0 <kpt_get_neighboring_grid_points+0x80>
mov    %r14,%r12
mov    %r15,%r14
lea    0x10(%rsp),%r15
mov    %r15,%rdi
lea    0x34(%rsp),%rsi
call   1040 <get_vector_modulo@plt>
mov    %r15,%rdi
mov    %r14,%r15
mov    %r12,%r14
lea    0x4(%rsp),%r12
mov    0x40(%rsp),%rsi
call   1030 <get_grid_point@plt>
jmp    11a0 <kpt_get_neighboring_grid_points+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @kpt_get_neighboring_grid_points(i32* nocapture writeonly %0, i32 %1, [3 x i32]* nocapture %2, i32 %3, i32* %4, [3 x i32]* nocapture %5, i32* nocapture %6) {
%8 = alloca [3 x i32]
%9 = alloca [3 x i32]
%10 = alloca [3 x i32]
%11 = alloca [3 x i32]
%12 = alloca [3 x i32]
%13 = bitcast [3 x i32]* %8 to i8*
%14 = bitcast [3 x i32]* %9 to i8*
%15 = bitcast [3 x i32]* %10 to i8*
%16 = bitcast [3 x i32]* %11 to i8*
%17 = bitcast [3 x i32]* %12 to i8*
%18 = load i32, i32* %4
%19 = shl nsw i32 %18, 1
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
store i32 %19, i32* %20
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
store i32 %19, i32* %21
%22 = shl nsw i32 %18, 2
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
store i32 %22, i32* %23
%24 = getelementptr inbounds i32, i32* %4, i64 1
%25 = load i32, i32* %24
%26 = shl nsw i32 %25, 1
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
store i32 %26, i32* %27
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 1
store i32 %26, i32* %28
%29 = shl nsw i32 %25, 2
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 1
store i32 %29, i32* %30
%31 = getelementptr inbounds i32, i32* %4, i64 2
%32 = load i32, i32* %31
%33 = shl nsw i32 %32, 1
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
store i32 %33, i32* %34
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 2
store i32 %33, i32* %35
%36 = shl nsw i32 %32, 2
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 2
store i32 %36, i32* %37
%38 = icmp sgt i32 %3, 0
br i1 %38, label %39, label %82
39: ; preds = %7
%40 = sext i32 %1 to i64
%41 = getelementptr inbounds [3 x i32], [3 x i32]* %12, i64 0, i64 0
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%43 = zext i32 %3 to i64
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 %40, i64 0
%45 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 %40, i64 1
%46 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 1
%47 = getelementptr inbounds [3 x i32], [3 x i32]* %12, i64 0, i64 1
%48 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 %40, i64 2
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 2
%50 = getelementptr inbounds [3 x i32], [3 x i32]* %12, i64 0, i64 2
br label %51
51: ; preds = %39, %77
%52 = phi i64 [ 0, %39 ], [ %80, %77 ]
%53 = load i32, i32* %44
%54 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 %52, i64 0
%55 = load i32, i32* %54
%56 = add nsw i32 %55, %53
%57 = shl nsw i32 %56, 1
store i32 %57, i32* %42
store i32 %57, i32* %41
%58 = load i32, i32* %45
%59 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 %52, i64 1
%60 = load i32, i32* %59
%61 = add nsw i32 %60, %58
%62 = shl nsw i32 %61, 1
store i32 %62, i32* %46
store i32 %62, i32* %47
%63 = load i32, i32* %48
%64 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 %52, i64 2
%65 = load i32, i32* %64
%66 = add nsw i32 %65, %63
%67 = shl nsw i32 %66, 1
store i32 %67, i32* %49
store i32 %67, i32* %50
%68 = call i32 @get_vector_modulo(i32* %41, i32* %23)
%69 = call i64 @get_grid_point(i32* %41, i32* %21)
%70 = getelementptr inbounds i32, i32* %6, i64 %69
%71 = load i32, i32* %70
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %77
73: ; preds = %51
%74 = call i32 @get_vector_modulo(i32* %42, i32* %20)
%75 = call i64 @get_grid_point(i32* %42, i32* %4)
%76 = trunc i64 %75 to i32
br label %77
77: ; preds = %51, %73
%78 = phi i32 [ %76, %73 ], [ %71, %51 ]
%79 = getelementptr inbounds i32, i32* %0, i64 %52
store i32 %78, i32* %79
%80 = add nuw nsw i64 %52, 1
%81 = icmp eq i64 %80, %43
br i1 %81, label %82, label %51
82: ; preds = %77, %7
ret void
}