#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 **create_2D_array(int, int);
int ***malloc(int);
int ***create_3D_array(int max_rows, int max_cols, int max_3D) {
  int ***three_d_array = malloc(max_3D * sizeof(int *));
  for (int i = 0; i < max_3D; i++) {
    three_d_array[i] = create_2D_array(max_rows, max_cols);
  }
  return three_d_array;
}


x86 assembly (clang, -O0):
<create_3D_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117f <create_3D_array+0x5f>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <create_2D_array@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <create_3D_array+0x2b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_3D_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%r12d
lea    0x0(,%r15,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r13
test   %r15d,%r15d
jle    1169 <create_3D_array+0x49>
mov    %r15d,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r12d,%edi
mov    %r14d,%esi
call   1040 <create_2D_array@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <create_3D_array+0x30>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32*** @create_3D_array(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32***
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i32*** @malloc(i32 %12)
store i32*** %13, i32**** %7
store i32 0, i32* %8
br label %14
14: ; preds = %26, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32** @create_2D_array(i32 %19, i32 %20)
%22 = load i32***, i32**** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32**, i32*** %22, i64 %24
store i32** %21, i32*** %25
br label %26
26: ; preds = %18
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %14
29: ; preds = %14
%30 = load i32***, i32**** %7
ret i32*** %30
}

LLVM IR (-O2):
define noalias i32*** @create_3D_array(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %2, 3
%5 = tail call i32*** @malloc(i32 %4)
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %10
9: ; preds = %10, %3
ret i32*** %5
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %14, %10 ]
%12 = tail call i32** @create_2D_array(i32 %0, i32 %1)
%13 = getelementptr inbounds i32**, i32*** %5, i64 %11
store i32** %12, i32*** %13
%14 = add nuw nsw i64 %11, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %9, label %10
}