#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 **allocate_int_RT(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int ****allocate_int_RT_4D(int N_X, int K, int nrow, int ncol) {
  int n_X, k;
  int ****pointerarray = (int ****)malloc(N_X * sizeof(int ***));
  if (pointerarray == NULL) {
    fprintf(stderr, "PE: Memory allocation fails!\n");
    exit(1);
  }
  for (n_X = 0; n_X < N_X; n_X++) {
    pointerarray[n_X] = (int ***)malloc(K * sizeof(int **));
    if (pointerarray[n_X] == NULL) {
      fprintf(stderr, "PE: Memory allocation fails!\n");
      exit(1);
    }
    for (k = 0; k < K; k++) {
      pointerarray[n_X][k] = allocate_int_RT(nrow, ncol);
    }
  }
  return (pointerarray);
}


x86 assembly (clang, -O0):
<allocate_int_RT_4D>:
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 -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <allocate_int_RT_4D+0x51>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    124a <allocate_int_RT_4D+0x10a>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11f4 <allocate_int_RT_4D+0xb4>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1237 <allocate_int_RT_4D+0xf7>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <allocate_int_RT@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fb <allocate_int_RT_4D+0xbb>
jmp    123c <allocate_int_RT_4D+0xfc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1198 <allocate_int_RT_4D+0x58>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_int_RT_4D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rsi,0x8(%rsp)
mov    %edi,%r13d
lea    0x0(,%r13,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ff <allocate_int_RT_4D+0xbf>
mov    %rax,%rbx
test   %r13d,%r13d
jle    11ed <allocate_int_RT_4D+0xad>
mov    0x8(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0x4(%rsp)
mov    %r13d,%ecx
mov    %rcx,0x10(%rsp)
mov    %eax,%r14d
xor    %r12d,%r12d
jmp    11ab <allocate_int_RT_4D+0x6b>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    0x10(%rsp),%r12
je     11ed <allocate_int_RT_4D+0xad>
mov    0x4(%rsp),%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx,%r12,8)
test   %rax,%rax
je     11ff <allocate_int_RT_4D+0xbf>
cmpl   $0x0,0x8(%rsp)
jle    11a0 <allocate_int_RT_4D+0x60>
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15d,%esi
call   1030 <allocate_int_RT@plt>
mov    (%rbx,%r12,8),%rcx
mov    %rax,(%rcx,%r13,8)
add    $0x1,%r13
cmp    %r13,%r14
jne    11d0 <allocate_int_RT_4D+0x90>
jmp    11a0 <allocate_int_RT_4D+0x60>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define i32**** @allocate_int_RT_4D(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
%11 = alloca i32****
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32****
store i32**** %17, i32***** %11
%18 = load i32****, i32***** %11
%19 = icmp eq i32**** %18, null
br i1 %19, label %20, label %24
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %4
store i32 0, i32* %9
br label %25
25: ; preds = %71, %24
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %74
29: ; preds = %25
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i32***
%36 = load i32****, i32***** %11
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32***, i32**** %36, i64 %38
store i32*** %35, i32**** %39
%40 = load i32****, i32***** %11
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32***, i32**** %40, i64 %42
%44 = load i32***, i32**** %43
%45 = icmp eq i32*** %44, null
br i1 %45, label %46, label %50
46: ; preds = %29
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %29
store i32 0, i32* %10
br label %51
51: ; preds = %67, %50
%52 = load i32, i32* %10
%53 = load i32, i32* %6
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %70
55: ; preds = %51
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = call i32** @allocate_int_RT(i32 %56, i32 %57)
%59 = load i32****, i32***** %11
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32***, i32**** %59, i64 %61
%63 = load i32***, i32**** %62
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32**, i32*** %63, i64 %65
store i32** %58, i32*** %66
br label %67
67: ; preds = %55
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
br label %51
70: ; preds = %51
br label %71
71: ; preds = %70
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %25
74: ; preds = %25
%75 = load i32****, i32***** %11
ret i32**** %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define i32**** @allocate_int_RT_4D(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %0, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32****
%8 = icmp eq i64 %6, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %41
11: ; preds = %9
%12 = shl i32 %1, 3
%13 = icmp sgt i32 %1, 0
%14 = zext i32 %0 to i64
%15 = zext i32 %1 to i64
br label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11, %38
%21 = phi i64 [ 0, %11 ], [ %39, %38 ]
%22 = tail call i64 @malloc(i32 %12)
%23 = inttoptr i64 %22 to i32***
%24 = getelementptr inbounds i32***, i32**** %7, i64 %21
store i32*** %23, i32**** %24
%25 = icmp eq i64 %22, 0
br i1 %25, label %27, label %26
26: ; preds = %20
br i1 %13, label %31, label %38
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %26, %31
%32 = phi i64 [ %36, %31 ], [ 0, %26 ]
%33 = tail call i32** @allocate_int_RT(i32 %2, i32 %3)
%34 = load i32***, i32**** %24
%35 = getelementptr inbounds i32**, i32*** %34, i64 %32
store i32** %33, i32*** %35
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, %15
br i1 %37, label %38, label %31
38: ; preds = %31, %26
%39 = add nuw nsw i64 %21, 1
%40 = icmp eq i64 %39, %14
br i1 %40, label %41, label %20
41: ; preds = %38, %9
ret i32**** %7
}