#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*/ error_and_exit();
void *malloc(int);
int ***malloc_int_array(int dim1, int dim2, int dim3) {
  int i, j;
  int ***array;
  array = malloc(sizeof(int **) * dim1);
  if (array == NULL)
    error_and_exit();
  for (i = 0; i < dim1; i++) {
    array[i] = malloc(sizeof(int *) * dim2);
    if (array[i] == NULL)
      error_and_exit();
    for (j = 0; j < dim2; j++) {
      array[i][j] = malloc(sizeof(int) * dim3);
      if (array[i][j] == NULL)
        error_and_exit();
    }
  }
  return array;
}


x86 assembly (clang, -O0):
<malloc_int_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1156 <malloc_int_array+0x36>
mov    $0x0,%al
call   1030 <error_and_exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1222 <malloc_int_array+0x102>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11a1 <malloc_int_array+0x81>
mov    $0x0,%al
call   1030 <error_and_exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120f <malloc_int_array+0xef>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11fc <malloc_int_array+0xdc>
mov    $0x0,%al
call   1030 <error_and_exit@plt>
jmp    1201 <malloc_int_array+0xe1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <malloc_int_array+0x88>
jmp    1214 <malloc_int_array+0xf4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <malloc_int_array+0x3d>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_int_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,0x8(%rsp)
mov    %edi,%ebp
lea    0x0(,%rbp,8),%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1156 <malloc_int_array+0x36>
test   %ebp,%ebp
jg     1165 <malloc_int_array+0x45>
jmp    1203 <malloc_int_array+0xe3>
xor    %eax,%eax
call   1030 <error_and_exit@plt>
test   %ebp,%ebp
jle    1203 <malloc_int_array+0xe3>
mov    0x8(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0x4(%rsp)
shl    $0x2,%ebx
mov    %ebp,%r13d
mov    %eax,%r14d
xor    %r15d,%r15d
jmp    1199 <malloc_int_array+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
cmp    %r13,%r15
je     1203 <malloc_int_array+0xe3>
mov    0x4(%rsp),%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rax
mov    %rbp,(%rax,%r15,8)
test   %rbp,%rbp
je     11c0 <malloc_int_array+0xa0>
cmpl   $0x0,0x8(%rsp)
jg     11ce <malloc_int_array+0xae>
jmp    1190 <malloc_int_array+0x70>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <error_and_exit@plt>
cmpl   $0x0,0x8(%rsp)
jle    1190 <malloc_int_array+0x70>
xor    %r12d,%r12d
jmp    11e9 <malloc_int_array+0xc9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r12
cmp    %r12,%r14
je     1190 <malloc_int_array+0x70>
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%rbp,%r12,8)
test   %rax,%rax
jne    11e0 <malloc_int_array+0xc0>
xor    %eax,%eax
call   1030 <error_and_exit@plt>
jmp    11e0 <malloc_int_array+0xc0>
mov    0x10(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32*** @malloc_int_array(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32***
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
%15 = bitcast i8* %14 to i32***
store i32*** %15, i32**** %9
%16 = load i32***, i32**** %9
%17 = icmp eq i32*** %16, null
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 (...) @error_and_exit()
br label %20
20: ; preds = %18, %3
store i32 0, i32* %7
br label %21
21: ; preds = %81, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %84
25: ; preds = %21
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = mul i64 8, %27
%29 = trunc i64 %28 to i32
%30 = call i8* @malloc(i32 %29)
%31 = bitcast i8* %30 to i32**
%32 = load i32***, i32**** %9
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32**, i32*** %32, i64 %34
store i32** %31, i32*** %35
%36 = load i32***, i32**** %9
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32**, i32*** %36, i64 %38
%40 = load i32**, i32*** %39
%41 = icmp eq i32** %40, null
br i1 %41, label %42, label %44
42: ; preds = %25
%43 = call i32 (...) @error_and_exit()
br label %44
44: ; preds = %42, %25
store i32 0, i32* %8
br label %45
45: ; preds = %77, %44
%46 = load i32, i32* %8
%47 = load i32, i32* %5
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %80
49: ; preds = %45
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = mul i64 4, %51
%53 = trunc i64 %52 to i32
%54 = call i8* @malloc(i32 %53)
%55 = bitcast i8* %54 to i32*
%56 = load i32***, i32**** %9
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32**, i32*** %56, i64 %58
%60 = load i32**, i32*** %59
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32*, i32** %60, i64 %62
store i32* %55, i32** %63
%64 = load i32***, i32**** %9
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32**, i32*** %64, i64 %66
%68 = load i32**, i32*** %67
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32*, i32** %68, i64 %70
%72 = load i32*, i32** %71
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %76
74: ; preds = %49
%75 = call i32 (...) @error_and_exit()
br label %76
76: ; preds = %74, %49
br label %77
77: ; preds = %76
%78 = load i32, i32* %8
%79 = add nsw i32 %78, 1
store i32 %79, i32* %8
br label %45
80: ; preds = %45
br label %81
81: ; preds = %80
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 1
store i32 %83, i32* %7
br label %21
84: ; preds = %21
%85 = load i32***, i32**** %9
ret i32*** %85
}

LLVM IR (-O2):
define noalias i32*** @malloc_int_array(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %0, 3
%5 = tail call i8* @malloc(i32 %4)
%6 = bitcast i8* %5 to i32***
%7 = icmp eq i8* %5, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (...) @error_and_exit()
br label %10
10: ; preds = %8, %3
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %42
12: ; preds = %10
%13 = shl i32 %1, 3
%14 = icmp sgt i32 %1, 0
%15 = shl i32 %2, 2
%16 = zext i32 %0 to i64
%17 = zext i32 %1 to i64
br label %18
18: ; preds = %12, %39
%19 = phi i64 [ 0, %12 ], [ %40, %39 ]
%20 = tail call i8* @malloc(i32 %13)
%21 = getelementptr inbounds i32**, i32*** %6, i64 %19
%22 = bitcast i32*** %21 to i8**
store i8* %20, i8** %22
%23 = icmp eq i8* %20, null
%24 = bitcast i8* %20 to i32**
br i1 %23, label %25, label %27
25: ; preds = %18
%26 = tail call i32 (...) @error_and_exit()
br label %27
27: ; preds = %25, %18
br i1 %14, label %28, label %39
28: ; preds = %27, %36
%29 = phi i64 [ %37, %36 ], [ 0, %27 ]
%30 = tail call i8* @malloc(i32 %15)
%31 = getelementptr inbounds i32*, i32** %24, i64 %29
%32 = bitcast i32** %31 to i8**
store i8* %30, i8** %32
%33 = icmp eq i8* %30, null
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 (...) @error_and_exit()
br label %36
36: ; preds = %28, %34
%37 = add nuw nsw i64 %29, 1
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %28
39: ; preds = %36, %27
%40 = add nuw nsw i64 %19, 1
%41 = icmp eq i64 %40, %16
br i1 %41, label %42, label %18
42: ; preds = %39, %10
ret i32*** %6
}