#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 elem(int *, int, int, int);
int /*<<< orphan*/ puts(int);
void test() {
  int mat[][3] = {{1, 2, 3}, {4, 5, 6}, {7, 5, 6}, {9, 9, 2}};
  puts(elem(&mat[0][0], 3, 2, 0) == 7);
  puts(elem(&mat[0][0], 3, 0, 0) == 1);
  puts(elem(&mat[0][0], 3, 3, 2) == 2);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x30(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x30,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rdi
mov    $0x3,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <elem@plt>
cmp    $0x7,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
mov    $0x3,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <elem@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
mov    $0x3,%edx
mov    $0x2,%ecx
mov    %edx,%esi
call   1050 <elem@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbx
sub    $0x30,%rsp
movaps 0xef4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1040 <elem@plt>
xor    %edi,%edi
cmp    $0x7,%eax
sete   %dil
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <elem@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
mov    $0x2,%ecx
call   1040 <elem@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test.mat = [4 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 5, i32 6], [3 x i32] [i32 9, i32 9, i32 2]]
define void @test() {
%1 = alloca [4 x [3 x i32]]
%2 = bitcast [4 x [3 x i32]]* %1 to i8*
%3 = getelementptr inbounds [4 x [3 x i32]], [4 x [3 x i32]]* %1, i64 0, i64 0
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%5 = call i32 @elem(i32* %4, i32 3, i32 2, i32 0)
%6 = icmp eq i32 %5, 7
%7 = zext i1 %6 to i32
%8 = call i32 @puts(i32 %7)
%9 = getelementptr inbounds [4 x [3 x i32]], [4 x [3 x i32]]* %1, i64 0, i64 0
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%11 = call i32 @elem(i32* %10, i32 3, i32 0, i32 0)
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i32
%14 = call i32 @puts(i32 %13)
%15 = getelementptr inbounds [4 x [3 x i32]], [4 x [3 x i32]]* %1, i64 0, i64 0
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %15, i64 0, i64 0
%17 = call i32 @elem(i32* %16, i32 3, i32 3, i32 2)
%18 = icmp eq i32 %17, 2
%19 = zext i1 %18 to i32
%20 = call i32 @puts(i32 %19)
ret void
}

LLVM IR (-O2):
@__const.test.mat = [4 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 5, i32 6], [3 x i32] [i32 9, i32 9, i32 2]]
define void @test() {
%1 = alloca [4 x [3 x i32]]
%2 = bitcast [4 x [3 x i32]]* %1 to i8*
%3 = getelementptr inbounds [4 x [3 x i32]], [4 x [3 x i32]]* %1, i64 0, i64 0, i64 0
%4 = call i32 @elem(i32* %3, i32 3, i32 2, i32 0)
%5 = icmp eq i32 %4, 7
%6 = zext i1 %5 to i32
%7 = call i32 @puts(i32 %6)
%8 = call i32 @elem(i32* %3, i32 3, i32 0, i32 0)
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
%11 = call i32 @puts(i32 %10)
%12 = call i32 @elem(i32* %3, i32 3, i32 3, i32 2)
%13 = icmp eq i32 %12, 2
%14 = zext i1 %13 to i32
%15 = call i32 @puts(i32 %14)
ret void
}