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


x86 assembly (clang, -O0):
<create_4D_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1185 <create_4D_array+0x65>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <create_3D_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    114e <create_4D_array+0x2e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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