#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(unsigned int, int);
double **create_2D_array(unsigned int, unsigned int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double ***create_3D_array(unsigned n1, unsigned n2, unsigned n3) {
  unsigned i;
  double ***matrix = (double ***)calloc(n1, sizeof(double **));
  if (matrix == NULL) {
    fprintf(stderr, "memory issue in create_3D_array\n");
    exit(1);
  }
  for (i = 0; i < n1; i++)
    matrix[i] = create_2D_array(n2, n3);
  return matrix;
}


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)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <create_3D_array+0x4c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11c6 <create_3D_array+0x86>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <create_2D_array@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <create_3D_array+0x53>
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,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     119b <create_3D_array+0x5b>
mov    %rax,%r13
test   %r15d,%r15d
je     1189 <create_3D_array+0x49>
mov    %r15d,%ebp
xor    %ebx,%ebx
mov    %r12d,%edi
mov    %r14d,%esi
call   1060 <create_2D_array@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <create_3D_array+0x30>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"memory issue in create_3D_array\0A\00"
define double*** @create_3D_array(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %0, i32 8)
%5 = inttoptr i64 %4 to double***
%6 = icmp eq i64 %4, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = icmp eq i32 %0, 0
br i1 %8, label %21, label %9
9: ; preds = %7
%10 = zext i32 %0 to i64
br label %15
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %15
%16 = phi i64 [ 0, %9 ], [ %19, %15 ]
%17 = tail call double** @create_2D_array(i32 %1, i32 %2)
%18 = getelementptr inbounds double**, double*** %5, i64 %16
store double** %17, double*** %18
%19 = add nuw nsw i64 %16, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %21, label %15
21: ; preds = %15, %7
ret double*** %5
}