#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char **);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void alloc_2D_arr_memory(char ***str, int ROW, int COL) {
  *str = (char **)malloc(ROW * sizeof(char *));
  if (!(*str)) {
    fprintf(stderr, "Can't allocate memory!");
    exit(1);
  }
  int i;
  for (i = 0; i < ROW; i++) {
    (*str)[i] = (char *)calloc(COL, sizeof(char));
    if (!(*str)[i]) {
      fprintf(stderr, "Can't allocate memory!\n");
      free((*str));
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<alloc_2D_arr_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a8 <alloc_2D_arr_memory+0x58>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122e <alloc_2D_arr_memory+0xde>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    121b <alloc_2D_arr_memory+0xcb>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1220 <alloc_2D_arr_memory+0xd0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11af <alloc_2D_arr_memory+0x5f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_2D_arr_memory>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x0(,%r14,8),%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11d9 <alloc_2D_arr_memory+0x89>
test   %r14d,%r14d
jle    11a7 <alloc_2D_arr_memory+0x57>
mov    %r14d,%r14d
xor    %ebp,%ebp
nop
mov    %r15d,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    (%rbx),%rcx
mov    %rax,(%rcx,%rbp,8)
mov    (%rbx),%rax
cmpq   $0x0,(%rax,%rbp,8)
je     11b2 <alloc_2D_arr_memory+0x62>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1180 <alloc_2D_arr_memory+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Can't allocate memory!\00"
@.str.1 = [24 x i8] c"Can't allocate memory!\0A\00"
define void @alloc_2D_arr_memory(i8*** %0, i32 %1, i32 %2) {
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8*** %0, i8**** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8**
%14 = load i8***, i8**** %4
store i8** %13, i8*** %14
%15 = load i8***, i8**** %4
%16 = load i8**, i8*** %15
%17 = icmp ne i8** %16, null
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %3
store i32 0, i32* %7
br label %23
23: ; preds = %51, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %54
27: ; preds = %23
%28 = load i32, i32* %6
%29 = call i64 @calloc(i32 %28, i32 1)
%30 = inttoptr i64 %29 to i8*
%31 = load i8***, i8**** %4
%32 = load i8**, i8*** %31
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
store i8* %30, i8** %35
%36 = load i8***, i8**** %4
%37 = load i8**, i8*** %36
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = icmp ne i8* %41, null
br i1 %42, label %50, label %43
43: ; preds = %27
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%46 = load i8***, i8**** %4
%47 = load i8**, i8*** %46
%48 = call i32 @free(i8** %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %27
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %23
54: ; preds = %23
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Can't allocate memory!\00"
@.str.1 = [24 x i8] c"Can't allocate memory!\0A\00"
define void @alloc_2D_arr_memory(i8*** nocapture %0, i32 %1, i32 %2) {
%4 = shl i32 %1, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8**
store i8** %6, i8*** %0
%7 = icmp eq i64 %5, 0
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %35
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %18
%17 = icmp eq i64 %28, %11
br i1 %17, label %35, label %18
18: ; preds = %10, %16
%19 = phi i64 [ 0, %10 ], [ %28, %16 ]
%20 = tail call i64 @calloc(i32 %2, i32 1)
%21 = inttoptr i64 %20 to i8*
%22 = load i8**, i8*** %0
%23 = getelementptr inbounds i8*, i8** %22, i64 %19
store i8* %21, i8** %23
%24 = load i8**, i8*** %0
%25 = getelementptr inbounds i8*, i8** %24, i64 %19
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
%28 = add nuw nsw i64 %19, 1
br i1 %27, label %29, label %16
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%32 = load i8**, i8*** %0
%33 = tail call i32 @free(i8** %32)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %16, %8
ret void
}