#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__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ ivclear(int *, int, int);
int **initarray_2Dint(int numrows, int numcolumns, int initval) {
  int i, j;
  int **array;
  if ((array = (int **)calloc((numrows), sizeof(int *))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", numrows);
  for (i = 0; i < numrows; i++) {
    if ((array[i] = (int *)calloc((numcolumns), sizeof(int))) == NULL)
      fatalx("Unable to allocate %d unit(s) for item \n", numcolumns);
    if (initval != 0)
      ivclear(array[i], initval, numcolumns);
  }
  return array;
}


x86 assembly (clang, -O0):
<initarray_2Dint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116b <initarray_2Dint+0x3b>
mov    -0x4(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1030 <fatalx@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e4 <initarray_2Dint+0xb4>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    -0x20(%rbp),%rcx
movslq -0x10(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11b0 <initarray_2Dint+0x80>
mov    -0x8(%rbp),%esi
lea    0xe55(%rip),%rdi
call   1030 <fatalx@plt>
cmpl   $0x0,-0xc(%rbp)
je     11d1 <initarray_2Dint+0xa1>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1050 <ivclear@plt>
jmp    11d6 <initarray_2Dint+0xa6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <initarray_2Dint+0x42>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initarray_2Dint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     115c <initarray_2Dint+0x2c>
test   %r15d,%r15d
jg     1170 <initarray_2Dint+0x40>
jmp    11d0 <initarray_2Dint+0xa0>
lea    0xe9d(%rip),%rdi
mov    %r15d,%esi
call   1030 <fatalx@plt>
test   %r15d,%r15d
jle    11d0 <initarray_2Dint+0xa0>
mov    %r15d,%r12d
xor    %ebx,%ebx
lea    0xe84(%rip),%r15
jmp    1189 <initarray_2Dint+0x59>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r12
je     11d0 <initarray_2Dint+0xa0>
mov    %ebp,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
je     11b0 <initarray_2Dint+0x80>
test   %r14d,%r14d
jne    11bf <initarray_2Dint+0x8f>
jmp    1180 <initarray_2Dint+0x50>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <fatalx@plt>
test   %r14d,%r14d
je     1180 <initarray_2Dint+0x50>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <ivclear@plt>
jmp    1180 <initarray_2Dint+0x50>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define i32** @initarray_2Dint(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32**
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = call i64 @calloc(i32 %10, i32 8)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %9
%13 = icmp eq i32** %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* %4
%16 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %3
store i32 0, i32* %7
br label %18
18: ; preds = %47, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i64 @calloc(i32 %23, i32 4)
%25 = inttoptr i64 %24 to i32*
%26 = load i32**, i32*** %9
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32*, i32** %26, i64 %28
store i32* %25, i32** %29
%30 = icmp eq i32* %25, null
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* %5
%33 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %22
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i32**, i32*** %9
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32*, i32** %38, i64 %40
%42 = load i32*, i32** %41
%43 = load i32, i32* %6
%44 = load i32, i32* %5
%45 = call i32 @ivclear(i32* %42, i32 %43, i32 %44)
br label %46
46: ; preds = %37, %34
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %18
50: ; preds = %18
%51 = load i32**, i32*** %9
ret i32** %51
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define i32** @initarray_2Dint(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %0, i32 8)
%5 = inttoptr i64 %4 to i32**
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %9
9: ; preds = %7, %3
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %29
11: ; preds = %9
%12 = icmp eq i32 %2, 0
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %11, %26
%15 = phi i64 [ 0, %11 ], [ %27, %26 ]
%16 = tail call i64 @calloc(i32 %1, i32 4)
%17 = inttoptr i64 %16 to i32*
%18 = getelementptr inbounds i32*, i32** %5, i64 %15
store i32* %17, i32** %18
%19 = icmp eq i64 %16, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %22
22: ; preds = %20, %14
br i1 %12, label %26, label %23
23: ; preds = %22
%24 = load i32*, i32** %18
%25 = tail call i32 @ivclear(i32* %24, i32 %2, i32 %1)
br label %26
26: ; preds = %22, %23
%27 = add nuw nsw i64 %15, 1
%28 = icmp eq i64 %27, %13
br i1 %28, label %29, label %14
29: ; preds = %26, %9
ret i32** %5
}