#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 mat_modulo_l(long, long const);
void reduce_grid_address(long address[3], const long D_diag[3]) {
  int i;
  for (i = 0; i < 3; i++) {
    address[i] = mat_modulo_l(address[i], D_diag[i]);
  }
}


x86 assembly (clang, -O0):
<reduce_grid_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    116b <reduce_grid_address+0x5b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <mat_modulo_l@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <reduce_grid_address+0x17>
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @reduce_grid_address(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i32
store i64* %0, i64** %3
store i64* %1, i64** %4
store i32 0, i32* %5
br label %6
6: ; preds = %25, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load i64*, i64** %3
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i64, i64* %10, i64 %12
%14 = load i64, i64* %13
%15 = load i64*, i64** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %15, i64 %17
%19 = load i64, i64* %18
%20 = call i64 @mat_modulo_l(i64 %14, i64 %19)
%21 = load i64*, i64** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i64, i64* %21, i64 %23
store i64 %20, i64* %24
br label %25
25: ; preds = %9
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @reduce_grid_address(i64* nocapture %0, i64* nocapture %1) {
%3 = load i64, i64* %0
%4 = load i64, i64* %1
%5 = tail call i64 @mat_modulo_l(i64 %3, i64 %4)
store i64 %5, i64* %0
%6 = getelementptr inbounds i64, i64* %0, i64 1
%7 = load i64, i64* %6
%8 = getelementptr inbounds i64, i64* %1, i64 1
%9 = load i64, i64* %8
%10 = tail call i64 @mat_modulo_l(i64 %7, i64 %9)
store i64 %10, i64* %6
%11 = getelementptr inbounds i64, i64* %0, i64 2
%12 = load i64, i64* %11
%13 = getelementptr inbounds i64, i64* %1, i64 2
%14 = load i64, i64* %13
%15 = tail call i64 @mat_modulo_l(i64 %12, i64 %14)
store i64 %15, i64* %11
ret void
}