#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 /*<<< orphan*/ abort();
char **calloc(unsigned int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char ***malloc(unsigned int);
int /*<<< orphan*/ stderr;
char ***alloc_matrix(unsigned rows, unsigned columns) {
  char ***matrix = malloc(rows * sizeof(char **));
  if (matrix == NULL) {
    fprintf(stderr, "malloc failed!\n");
  }
  if (!matrix)
    abort();
  for (unsigned row = 0; row < rows; row++) {
    matrix[row] = calloc(columns, sizeof(char *));
    if (!matrix[row])
      abort();
    for (unsigned column = 0; column < columns; column++) {
      matrix[row][column] = NULL;
    }
  }
  return matrix;
}


x86 assembly (clang, -O0):
<alloc_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <alloc_matrix+0x40>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1192 <alloc_matrix+0x52>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1223 <alloc_matrix+0xe3>
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d9 <alloc_matrix+0x99>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1210 <alloc_matrix+0xd0>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x18(%rbp),%ecx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e0 <alloc_matrix+0xa0>
jmp    1215 <alloc_matrix+0xd5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <alloc_matrix+0x59>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %edi,%r12d
lea    0x0(,%r12,8),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11cd <alloc_matrix+0x7d>
mov    %rax,%r14
test   %r12d,%r12d
je     11c1 <alloc_matrix+0x71>
mov    %ebp,%r15d
shl    $0x3,%r15
mov    %r12d,%r12d
xor    %ebx,%ebx
jmp    1199 <alloc_matrix+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r12
je     11c1 <alloc_matrix+0x71>
mov    %ebp,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     11e2 <alloc_matrix+0x92>
test   %ebp,%ebp
je     1190 <alloc_matrix+0x40>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
jmp    1190 <alloc_matrix+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

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