#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 *allocate_int_1D(int);
int **allocate_int_2D_AP(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int **allocate_int_RT(int nrow, int ncol) {
  int i, j;
  int **pointerarray = allocate_int_2D_AP(nrow);
  if (pointerarray == NULL) {
    fprintf(stderr, "PE: Memory allocation fails!\n");
    exit(1);
  }
  for (i = 0; i < nrow; i++) {
    pointerarray[i] = allocate_int_1D(ncol);
    if (pointerarray[i] == NULL) {
      fprintf(stderr, "PE: Memory allocation fails!\n");
      exit(1);
    }
    for (j = 0; j < ncol; j++) {
      pointerarray[i][j] = 0;
    }
  }
  return (pointerarray);
}


x86 assembly (clang, -O0):
<allocate_int_RT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <allocate_int_2D_AP@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <allocate_int_RT+0x44>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    122b <allocate_int_RT+0xeb>
mov    -0x8(%rbp),%edi
call   1050 <allocate_int_1D@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    11e0 <allocate_int_RT+0xa0>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1218 <allocate_int_RT+0xd8>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e7 <allocate_int_RT+0xa7>
jmp    121d <allocate_int_RT+0xdd>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <allocate_int_RT+0x4b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_int_RT>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
call   1030 <allocate_int_2D_AP@plt>
test   %rax,%rax
je     11b8 <allocate_int_RT+0x68>
mov    %rax,%r14
test   %ebp,%ebp
jle    11ac <allocate_int_RT+0x5c>
mov    %ebx,%r15d
shl    $0x2,%r15
mov    %ebp,%r12d
xor    %ebp,%ebp
jmp    1189 <allocate_int_RT+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     11ac <allocate_int_RT+0x5c>
mov    %ebx,%edi
call   1060 <allocate_int_1D@plt>
mov    %rax,(%r14,%rbp,8)
test   %rax,%rax
je     11b8 <allocate_int_RT+0x68>
test   %ebx,%ebx
jle    1180 <allocate_int_RT+0x30>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
jmp    1180 <allocate_int_RT+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define i32** @allocate_int_RT(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = call i32** @allocate_int_2D_AP(i32 %8)
store i32** %9, i32*** %7
%10 = load i32**, i32*** %7
%11 = icmp eq i32** %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i32 0, i32* %5
br label %17
17: ; preds = %56, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %59
21: ; preds = %17
%22 = load i32, i32* %4
%23 = call i32* @allocate_int_1D(i32 %22)
%24 = load i32**, i32*** %7
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32*, i32** %24, i64 %26
store i32* %23, i32** %27
%28 = load i32**, i32*** %7
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
%32 = load i32*, i32** %31
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %21
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %21
store i32 0, i32* %6
br label %39
39: ; preds = %52, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load i32**, i32*** %7
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32*, i32** %44, i64 %46
%48 = load i32*, i32** %47
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
store i32 0, i32* %51
br label %52
52: ; preds = %43
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %39
55: ; preds = %39
br label %56
56: ; preds = %55
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %17
59: ; preds = %17
%60 = load i32**, i32*** %7
ret i32** %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define i32** @allocate_int_RT(i32 %0, i32 %1) {
%3 = tail call i32** @allocate_int_2D_AP(i32 %0)
%4 = icmp eq i32** %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %31
7: ; preds = %5
%8 = icmp sgt i32 %1, 0
%9 = zext i32 %1 to i64
%10 = shl nuw nsw i64 %9, 2
%11 = zext i32 %0 to i64
br label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7, %28
%17 = phi i64 [ 0, %7 ], [ %29, %28 ]
%18 = tail call i32* @allocate_int_1D(i32 %1)
%19 = bitcast i32* %18 to i8*
%20 = getelementptr inbounds i32*, i32** %3, i64 %17
store i32* %18, i32** %20
%21 = icmp eq i32* %18, null
br i1 %21, label %24, label %22
22: ; preds = %16
br i1 %8, label %23, label %28
23: ; preds = %22
br label %28
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %23, %22
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %31, label %16
31: ; preds = %28, %5
ret i32** %3
}