#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 kpt_get_grid_point_double_mesh(int *, int const *);
void thm_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 bzmesh[3], address_double[3], bz_address_double[3];
  int i, j, bz_gp;
  for (i = 0; i < 3; i++) {
    bzmesh[i] = mesh[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];
    }
    bz_gp = bz_map[kpt_get_grid_point_double_mesh(bz_address_double, bzmesh)];
    if (bz_gp == -1) {
      neighboring_grid_points[i] =
          kpt_get_grid_point_double_mesh(address_double, mesh);
    } else {
      neighboring_grid_points[i] = bz_gp;
    }
  }
}


x86 assembly (clang, -O0):
<thm_get_neighboring_grid_points>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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,-0x58(%rbp)
cmpl   $0x3,-0x58(%rbp)
jge    1167 <thm_get_neighboring_grid_points+0x57>
mov    -0x28(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
shl    $0x1,%ecx
movslq -0x58(%rbp),%rax
mov    %ecx,-0x3c(%rbp,%rax,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1139 <thm_get_neighboring_grid_points+0x29>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    124c <thm_get_neighboring_grid_points+0x13c>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jge    11e0 <thm_get_neighboring_grid_points+0xd0>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%rax
movslq -0x58(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
movslq -0x5c(%rbp),%rdx
add    (%rax,%rdx,4),%ecx
shl    $0x1,%ecx
movslq -0x5c(%rbp),%rax
mov    %ecx,-0x48(%rbp,%rax,4)
movslq -0x5c(%rbp),%rax
mov    -0x48(%rbp,%rax,4),%ecx
movslq -0x5c(%rbp),%rax
mov    %ecx,-0x54(%rbp,%rax,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1181 <thm_get_neighboring_grid_points+0x71>
mov    0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x54(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1030 <kpt_get_grid_point_double_mesh@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x60(%rbp)
cmpl   $0xffffffff,-0x60(%rbp)
jne    122b <thm_get_neighboring_grid_points+0x11b>
lea    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <kpt_get_grid_point_double_mesh@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1239 <thm_get_neighboring_grid_points+0x129>
mov    -0x60(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    123e <thm_get_neighboring_grid_points+0x12e>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    116e <thm_get_neighboring_grid_points+0x5e>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thm_get_neighboring_grid_points>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    (%r8),%eax
add    %eax,%eax
mov    %eax,0x24(%rsp)
mov    0x4(%r8),%eax
add    %eax,%eax
mov    %eax,0x28(%rsp)
mov    %r8,0x30(%rsp)
mov    0x8(%r8),%eax
add    %eax,%eax
mov    %eax,0x2c(%rsp)
test   %ecx,%ecx
jle    11db <thm_get_neighboring_grid_points+0xcb>
mov    %rdx,%rbx
mov    %rdi,%r15
movslq %esi,%rax
mov    %ecx,%r14d
lea    (%rax,%rax,2),%rax
lea    (%r9,%rax,4),%rbp
add    $0x8,%rbx
xor    %r12d,%r12d
lea    0x24(%rsp),%r13
jmp    1181 <thm_get_neighboring_grid_points+0x71>
nopw   0x0(%rax,%rax,1)
mov    %eax,(%r15,%r12,4)
add    $0x1,%r12
add    $0xc,%rbx
cmp    %r12,%r14
je     11db <thm_get_neighboring_grid_points+0xcb>
mov    -0x8(%rbx),%eax
add    0x0(%rbp),%eax
add    %eax,%eax
mov    %eax,0x18(%rsp)
mov    %eax,0xc(%rsp)
mov    -0x4(%rbx),%eax
add    0x4(%rbp),%eax
add    %eax,%eax
mov    %eax,0x1c(%rsp)
mov    %eax,0x10(%rsp)
mov    (%rbx),%eax
add    0x8(%rbp),%eax
add    %eax,%eax
mov    %eax,0x20(%rsp)
mov    %eax,0x14(%rsp)
lea    0xc(%rsp),%rdi
mov    %r13,%rsi
call   1030 <kpt_get_grid_point_double_mesh@plt>
mov    0x70(%rsp),%rcx
mov    (%rcx,%rax,4),%eax
cmp    $0xffffffff,%eax
jne    1170 <thm_get_neighboring_grid_points+0x60>
lea    0x18(%rsp),%rdi
mov    0x30(%rsp),%rsi
call   1030 <kpt_get_grid_point_double_mesh@plt>
jmp    1170 <thm_get_neighboring_grid_points+0x60>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @thm_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 = bitcast [3 x i32]* %8 to i8*
%12 = bitcast [3 x i32]* %9 to i8*
%13 = bitcast [3 x i32]* %10 to i8*
%14 = load i32, i32* %4
%15 = shl nsw i32 %14, 1
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
store i32 %15, i32* %16
%17 = getelementptr inbounds i32, i32* %4, i64 1
%18 = load i32, i32* %17
%19 = shl nsw i32 %18, 1
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
store i32 %19, i32* %20
%21 = getelementptr inbounds i32, i32* %4, i64 2
%22 = load i32, i32* %21
%23 = shl nsw i32 %22, 1
%24 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
store i32 %23, i32* %24
%25 = icmp sgt i32 %3, 0
br i1 %25, label %26, label %67
26: ; preds = %7
%27 = sext i32 %1 to i64
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%30 = zext i32 %3 to i64
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 %27, i64 0
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 %27, i64 1
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 1
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 1
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 %27, i64 2
%36 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 2
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 2
br label %38
38: ; preds = %26, %62
%39 = phi i64 [ 0, %26 ], [ %65, %62 ]
%40 = load i32, i32* %31
%41 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 %39, i64 0
%42 = load i32, i32* %41
%43 = add nsw i32 %42, %40
%44 = shl nsw i32 %43, 1
store i32 %44, i32* %29
store i32 %44, i32* %28
%45 = load i32, i32* %32
%46 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 %39, i64 1
%47 = load i32, i32* %46
%48 = add nsw i32 %47, %45
%49 = shl nsw i32 %48, 1
store i32 %49, i32* %33
store i32 %49, i32* %34
%50 = load i32, i32* %35
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 %39, i64 2
%52 = load i32, i32* %51
%53 = add nsw i32 %52, %50
%54 = shl nsw i32 %53, 1
store i32 %54, i32* %36
store i32 %54, i32* %37
%55 = call i64 @kpt_get_grid_point_double_mesh(i32* %28, i32* %16)
%56 = getelementptr inbounds i32, i32* %6, i64 %55
%57 = load i32, i32* %56
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %38
%60 = call i64 @kpt_get_grid_point_double_mesh(i32* %29, i32* %4)
%61 = trunc i64 %60 to i32
br label %62
62: ; preds = %38, %59
%63 = phi i32 [ %61, %59 ], [ %57, %38 ]
%64 = getelementptr inbounds i32, i32* %0, i64 %39
store i32 %63, i32* %64
%65 = add nuw nsw i64 %39, 1
%66 = icmp eq i64 %65, %30
br i1 %66, label %67, label %38
67: ; preds = %62, %7
ret void
}