#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*/ printf(char *);
char **get_2d_mem_char(int dim1, int dim2) {
  char **array_2d;
  int k;
  if (!(array_2d = (char **)calloc(dim1, sizeof(char *)))) {
    printf("Cannot allocate memory in get_2d_mem_char\n");
    exit(1);
  }
  for (k = 0; k < dim1; k++) {
    if (!(array_2d[k] = (char *)calloc(dim2, sizeof(char)))) {
      printf("Cannot allocate memory in get_2d_mem_char\n");
      exit(1);
    }
  }
  return array_2d;
}


x86 assembly (clang, -O0):
<get_2d_mem_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    116f <get_2d_mem_char+0x3f>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ce <get_2d_mem_char+0x9e>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11bb <get_2d_mem_char+0x8b>
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11c0 <get_2d_mem_char+0x90>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <get_2d_mem_char+0x46>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_2d_mem_char>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     118b <get_2d_mem_char+0x5b>
mov    %rax,%r12
test   %r14d,%r14d
jle    117f <get_2d_mem_char+0x4f>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     118b <get_2d_mem_char+0x5b>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <get_2d_mem_char+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"Cannot allocate memory in get_2d_mem_char\0A\00"
define i8** @get_2d_mem_char(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to i8**
store i8** %9, i8*** %5
%10 = icmp ne i8** %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
store i32 0, i32* %6
br label %15
15: ; preds = %32, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = load i32, i32* %4
%21 = call i64 @calloc(i32 %20, i32 1)
%22 = inttoptr i64 %21 to i8*
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
store i8* %22, i8** %26
%27 = icmp ne i8* %22, null
br i1 %27, label %31, label %28
28: ; preds = %19
%29 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %19
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %15
35: ; preds = %15
%36 = load i8**, i8*** %5
ret i8** %36
}

LLVM IR (-O2):
@str.1 = [42 x i8] c"Cannot allocate memory in get_2d_mem_char\00"
define i8** @get_2d_mem_char(i32 %0, i32 %1) {
%3 = tail call i64 @calloc(i32 %0, i32 8)
%4 = inttoptr i64 %3 to i8**
%5 = icmp eq i64 %3, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %25
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %15
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %15
%14 = icmp eq i64 %21, %9
br i1 %14, label %25, label %15
15: ; preds = %8, %13
%16 = phi i64 [ 0, %8 ], [ %21, %13 ]
%17 = tail call i64 @calloc(i32 %1, i32 1)
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds i8*, i8** %4, i64 %16
store i8* %18, i8** %19
%20 = icmp eq i64 %17, 0
%21 = add nuw nsw i64 %16, 1
br i1 %20, label %22, label %13
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %13, %6
ret i8** %4
}