#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 */
scalar_t__ eca_calloc(size_t, int, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, int);
int **imatrix(int NumRows, int NumCols) {
  int i;
  int **temp;
  temp = (int **)eca_calloc((size_t)NumRows, sizeof(int *), "(size_t)NumRows",
                            "sizeof(int *)");
  if (temp == NULL) {
    printf("\n\nimatrix failed to allocate to array of pointers of length %d",
           NumRows);
    exit(1);
  }
  for (i = 0; i < NumRows; i++) {
    temp[i] = (int *)eca_calloc((size_t)NumCols, sizeof(int), "(size_t)NumCols",
                                "sizeof(int)");
    if (temp[i] == NULL) {
      printf("\n\nimatrix failed to allocate to array of ints of length %d",
             NumCols);
      exit(1);
    }
  }
  return (temp);
}


x86 assembly (clang, -O0):
<imatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rdi
mov    $0x8,%esi
lea    0xeb2(%rip),%rdx
lea    0xebb(%rip),%rcx
call   1040 <eca_calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1182 <imatrix+0x52>
mov    -0x4(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ff <imatrix+0xcf>
movslq -0x8(%rbp),%rdi
mov    $0x4,%esi
lea    0xeb8(%rip),%rdx
lea    0xec1(%rip),%rcx
call   1040 <eca_calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11ec <imatrix+0xbc>
mov    -0x8(%rbp),%esi
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11f1 <imatrix+0xc1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <imatrix+0x59>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
mov    %edi,%r15d
movslq %edi,%rdi
lea    0xeb4(%rip),%rdx
lea    0xebd(%rip),%rcx
mov    $0x8,%esi
call   1040 <eca_calloc@plt>
test   %rax,%rax
je     11e2 <imatrix+0xb2>
mov    %rax,%r13
test   %r15d,%r15d
jle    11b6 <imatrix+0x86>
movslq 0x4(%rsp),%rbp
mov    %r15d,%ebx
xor    %r14d,%r14d
lea    0xedd(%rip),%r15
lea    0xee6(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x4,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1040 <eca_calloc@plt>
mov    %rax,0x0(%r13,%r14,8)
test   %rax,%rax
je     11c8 <imatrix+0x98>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1190 <imatrix+0x60>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeaa(%rip),%rdi
mov    0x4(%rsp),%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe35(%rip),%rdi
mov    %r15d,%esi
jmp    11d3 <imatrix+0xa3>

LLVM IR (-O0):
@.str = [16 x i8] c"(size_t)NumRows\00"
@.str.1 = [14 x i8] c"sizeof(int *)\00"
@.str.2 = [63 x i8] c"\0A\0Aimatrix failed to allocate to array of pointers of length %d\00"
@.str.3 = [16 x i8] c"(size_t)NumCols\00"
@.str.4 = [12 x i8] c"sizeof(int)\00"
@.str.5 = [59 x i8] c"\0A\0Aimatrix failed to allocate to array of ints of length %d\00"
define i32** @imatrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = call i64 @eca_calloc(i64 %8, i32 8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = inttoptr i64 %9 to i32**
store i32** %10, i32*** %6
%11 = load i32**, i32*** %6
%12 = icmp eq i32** %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 0, i32* %5
br label %18
18: ; preds = %42, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = call i64 @eca_calloc(i64 %24, i32 4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%26 = inttoptr i64 %25 to i32*
%27 = load i32**, i32*** %6
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
store i32* %26, i32** %30
%31 = load i32**, i32*** %6
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %22
%38 = load i32, i32* %4
%39 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %22
br label %42
42: ; preds = %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %18
45: ; preds = %18
%46 = load i32**, i32*** %6
ret i32** %46
}

LLVM IR (-O2):
@.str = [16 x i8] c"(size_t)NumRows\00"
@.str.1 = [14 x i8] c"sizeof(int *)\00"
@.str.2 = [63 x i8] c"\0A\0Aimatrix failed to allocate to array of pointers of length %d\00"
@.str.3 = [16 x i8] c"(size_t)NumCols\00"
@.str.4 = [12 x i8] c"sizeof(int)\00"
@.str.5 = [59 x i8] c"\0A\0Aimatrix failed to allocate to array of ints of length %d\00"
define i32** @imatrix(i32 %0, i32 %1) {
%3 = sext i32 %0 to i64
%4 = tail call i64 @eca_calloc(i64 %3, i32 8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = inttoptr i64 %4 to i32**
%6 = icmp eq i64 %4, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %27
9: ; preds = %7
%10 = sext i32 %1 to i64
%11 = zext i32 %0 to i64
br label %17
12: ; preds = %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %17
%16 = icmp eq i64 %23, %11
br i1 %16, label %27, label %17
17: ; preds = %9, %15
%18 = phi i64 [ 0, %9 ], [ %23, %15 ]
%19 = tail call i64 @eca_calloc(i64 %10, i32 4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%20 = inttoptr i64 %19 to i32*
%21 = getelementptr inbounds i32*, i32** %5, i64 %18
store i32* %20, i32** %21
%22 = icmp eq i64 %19, 0
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %24, label %15
24: ; preds = %17
%25 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), i32 %1)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %15, %7
ret i32** %5
}