#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 */
long get_grid_index_single_mesh(long *, long const *);
long mat_modulo_l(long, long const);
long get_double_grid_index(const long address_double[3], const long mesh[3]) {
  long i;
  long address[3];
  for (i = 0; i < 3; i++) {
    if (address_double[i] % 2 == 0) {
      address[i] = address_double[i] / 2;
    } else {
      address[i] = (address_double[i] - 1) / 2;
    }
    address[i] = mat_modulo_l(address[i], mesh[i]);
  }
  return get_grid_index_single_mesh(address, mesh);
}


x86 assembly (clang, -O0):
<get_double_grid_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x3,-0x18(%rbp)
jge    11e7 <get_double_grid_index+0xc7>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    118a <get_double_grid_index+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
jmp    11b0 <get_double_grid_index+0x90>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
sub    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <mat_modulo_l@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <get_double_grid_index+0x18>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <get_grid_index_single_mesh@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_double_grid_index>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
sar    %rdi
mov    (%rsi),%rsi
call   1030 <mat_modulo_l@plt>
mov    %rax,(%rsp)
mov    0x8(%rbx),%rdi
sar    %rdi
mov    0x8(%r14),%rsi
call   1030 <mat_modulo_l@plt>
mov    %rax,0x8(%rsp)
mov    0x10(%rbx),%rdi
sar    %rdi
mov    0x10(%r14),%rsi
call   1030 <mat_modulo_l@plt>
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <get_grid_index_single_mesh@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @get_double_grid_index(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca [3 x i64]
store i64* %0, i64** %3
store i64* %1, i64** %4
store i64 0, i64* %5
br label %7
7: ; preds = %45, %2
%8 = load i64, i64* %5
%9 = icmp slt i64 %8, 3
br i1 %9, label %10, label %48
10: ; preds = %7
%11 = load i64*, i64** %3
%12 = load i64, i64* %5
%13 = getelementptr inbounds i64, i64* %11, i64 %12
%14 = load i64, i64* %13
%15 = srem i64 %14, 2
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %10
%18 = load i64*, i64** %3
%19 = load i64, i64* %5
%20 = getelementptr inbounds i64, i64* %18, i64 %19
%21 = load i64, i64* %20
%22 = sdiv i64 %21, 2
%23 = load i64, i64* %5
%24 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 %23
store i64 %22, i64* %24
br label %34
25: ; preds = %10
%26 = load i64*, i64** %3
%27 = load i64, i64* %5
%28 = getelementptr inbounds i64, i64* %26, i64 %27
%29 = load i64, i64* %28
%30 = sub nsw i64 %29, 1
%31 = sdiv i64 %30, 2
%32 = load i64, i64* %5
%33 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 %32
store i64 %31, i64* %33
br label %34
34: ; preds = %25, %17
%35 = load i64, i64* %5
%36 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = load i64*, i64** %4
%39 = load i64, i64* %5
%40 = getelementptr inbounds i64, i64* %38, i64 %39
%41 = load i64, i64* %40
%42 = call i64 @mat_modulo_l(i64 %37, i64 %41)
%43 = load i64, i64* %5
%44 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 %43
store i64 %42, i64* %44
br label %45
45: ; preds = %34
%46 = load i64, i64* %5
%47 = add nsw i64 %46, 1
store i64 %47, i64* %5
br label %7
48: ; preds = %7
%49 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 0
%50 = load i64*, i64** %4
%51 = call i64 @get_grid_index_single_mesh(i64* %49, i64* %50)
ret i64 %51
}

LLVM IR (-O2):
define i64 @get_double_grid_index(i64* nocapture %0, i64* %1) {
%3 = alloca [3 x i64]
%4 = bitcast [3 x i64]* %3 to i8*
%5 = load i64, i64* %0
%6 = and i64 %5, -2
%7 = sdiv i64 %6, 2
%8 = getelementptr inbounds [3 x i64], [3 x i64]* %3, i64 0, i64 0
%9 = load i64, i64* %1
%10 = tail call i64 @mat_modulo_l(i64 %7, i64 %9)
store i64 %10, i64* %8
%11 = getelementptr inbounds i64, i64* %0, i64 1
%12 = load i64, i64* %11
%13 = and i64 %12, -2
%14 = sdiv i64 %13, 2
%15 = getelementptr inbounds [3 x i64], [3 x i64]* %3, i64 0, i64 1
%16 = getelementptr inbounds i64, i64* %1, i64 1
%17 = load i64, i64* %16
%18 = tail call i64 @mat_modulo_l(i64 %14, i64 %17)
store i64 %18, i64* %15
%19 = getelementptr inbounds i64, i64* %0, i64 2
%20 = load i64, i64* %19
%21 = and i64 %20, -2
%22 = sdiv i64 %21, 2
%23 = getelementptr inbounds [3 x i64], [3 x i64]* %3, i64 0, i64 2
%24 = getelementptr inbounds i64, i64* %1, i64 2
%25 = load i64, i64* %24
%26 = tail call i64 @mat_modulo_l(i64 %22, i64 %25)
store i64 %26, i64* %23
%27 = call i64 @get_grid_index_single_mesh(i64* %8, i64* %1)
ret i64 %27
}