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


x86 assembly (clang, -O0):
<allocate_char_RT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <allocate_char_2D_AP@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <allocate_char_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    123a <allocate_char_RT+0xfa>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1050 <allocate_char_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    11e3 <allocate_char_RT+0xa3>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%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_char_RT+0xd8>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ea <allocate_char_RT+0xaa>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <allocate_char_RT+0x4b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_char_RT>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%r15d
call   1030 <allocate_char_2D_AP@plt>
test   %rax,%rax
je     1259 <allocate_char_RT+0x119>
mov    %rax,%rbx
test   %r15d,%r15d
jle    1247 <allocate_char_RT+0x107>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
movslq %eax,%r13
mov    %r15d,%r15d
mov    %r13d,%ebp
lea    -0x1(%rbp),%rax
mov    %rax,0x10(%rsp)
mov    %ebp,%r14d
and    $0x3,%r14d
and    $0xfffffffc,%ebp
xor    %r12d,%r12d
jmp    11b2 <allocate_char_RT+0x72>
nopl   (%rax)
movb   $0x0,(%rax,%r13,1)
add    $0x1,%r12
cmp    %r15,%r12
je     1247 <allocate_char_RT+0x107>
mov    0x4(%rsp),%edi
call   1050 <allocate_char_1D@plt>
mov    %rax,(%rbx,%r12,8)
test   %rax,%rax
je     1259 <allocate_char_RT+0x119>
cmpl   $0x0,0x8(%rsp)
jle    11a0 <allocate_char_RT+0x60>
cmpq   $0x3,0x10(%rsp)
jae    11e0 <allocate_char_RT+0xa0>
xor    %ecx,%ecx
jmp    121c <allocate_char_RT+0xdc>
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x30,(%rax,%rcx,1)
mov    (%rbx,%r12,8),%rax
movb   $0x30,0x1(%rax,%rcx,1)
mov    (%rbx,%r12,8),%rax
movb   $0x30,0x2(%rax,%rcx,1)
mov    (%rbx,%r12,8),%rax
movb   $0x30,0x3(%rax,%rcx,1)
add    $0x4,%rcx
mov    (%rbx,%r12,8),%rax
cmp    %rcx,%rbp
jne    11f0 <allocate_char_RT+0xb0>
test   %r14,%r14
je     11a0 <allocate_char_RT+0x60>
mov    %r14,%rdx
nopl   0x0(%rax,%rax,1)
movb   $0x30,(%rax,%rcx,1)
add    $0x1,%rcx
mov    (%rbx,%r12,8),%rax
add    $0xffffffffffffffff,%rdx
jne    1230 <allocate_char_RT+0xf0>
jmp    11a0 <allocate_char_RT+0x60>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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