#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 /*<<< orphan*/ puts(char *);
unsigned char *nam_access(unsigned char *matrix, unsigned int n_nodes,
                          unsigned int col, unsigned int row) {
  unsigned int index = 0;
  if (!matrix) {
    puts("nam_access: matrix was null");
    return 0;
  }
  if (col >= n_nodes) {
    puts("nam_access: provided column was greater than n_nodes");
    return 0;
  }
  if (row >= n_nodes) {
    puts("nam_access: provided row was greater than n_nodes");
    return 0;
  }
  index = row * n_nodes + col;
  if (index >= (n_nodes * n_nodes)) {
    puts("nam_access: illegal index");
    return 0;
  }
  return &(matrix[index]);
}


x86 assembly (clang, -O0):
<nam_access>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <nam_access+0x40>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <nam_access+0xd0>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     1175 <nam_access+0x65>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <nam_access+0xd0>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     119a <nam_access+0x8a>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <nam_access+0xd0>
mov    -0x1c(%rbp),%eax
imul   -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x14(%rbp),%ecx
cmp    %ecx,%eax
jb     11d2 <nam_access+0xc2>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <nam_access+0xd0>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nam_access>:
push   %rax
test   %rdi,%rdi
je     1134 <nam_access+0x24>
cmp    %esi,%edx
jae    113d <nam_access+0x2d>
cmp    %esi,%ecx
jae    1146 <nam_access+0x36>
imul   %esi,%ecx
add    %edx,%ecx
imul   %esi,%esi
cmp    %esi,%ecx
jae    114f <nam_access+0x3f>
mov    %rdi,%rax
mov    %ecx,%ecx
add    %rcx,%rax
pop    %rcx
ret
lea    0xec5(%rip),%rdi
jmp    1156 <nam_access+0x46>
lea    0xed8(%rip),%rdi
jmp    1156 <nam_access+0x46>
lea    0xf04(%rip),%rdi
jmp    1156 <nam_access+0x46>
lea    0xf2d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"nam_access: matrix was null\00"
@.str.1 = [53 x i8] c"nam_access: provided column was greater than n_nodes\00"
@.str.2 = [50 x i8] c"nam_access: provided row was greater than n_nodes\00"
@.str.3 = [26 x i8] c"nam_access: illegal index\00"
define i8* @nam_access(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %45
15: ; preds = %4
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp uge i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @puts(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %5
br label %45
21: ; preds = %15
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp uge i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @puts(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %5
br label %45
27: ; preds = %21
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = mul i32 %28, %29
%31 = load i32, i32* %8
%32 = add i32 %30, %31
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = load i32, i32* %7
%35 = load i32, i32* %7
%36 = mul i32 %34, %35
%37 = icmp uge i32 %33, %36
br i1 %37, label %38, label %40
38: ; preds = %27
%39 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %5
br label %45
40: ; preds = %27
%41 = load i8*, i8** %6
%42 = load i32, i32* %10
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8* %44, i8** %5
br label %45
45: ; preds = %40, %38, %25, %19, %13
%46 = load i8*, i8** %5
ret i8* %46
}

LLVM IR (-O2):
@.str = [28 x i8] c"nam_access: matrix was null\00"
@.str.1 = [53 x i8] c"nam_access: provided column was greater than n_nodes\00"
@.str.2 = [50 x i8] c"nam_access: provided row was greater than n_nodes\00"
@.str.3 = [26 x i8] c"nam_access: illegal index\00"
define i8* @nam_access(i8* readnone %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %26
8: ; preds = %4
%9 = icmp ult i32 %2, %1
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %26
12: ; preds = %8
%13 = icmp ult i32 %3, %1
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %26
16: ; preds = %12
%17 = mul i32 %3, %1
%18 = add i32 %17, %2
%19 = mul i32 %1, %1
%20 = icmp ult i32 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %26
23: ; preds = %16
%24 = zext i32 %18 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
br label %26
26: ; preds = %23, %21, %14, %10, %6
%27 = phi i8* [ null, %10 ], [ null, %14 ], [ null, %21 ], [ %25, %23 ], [ null, %6 ]
ret i8* %27
}