#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*/ EXIT_FAILURE;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int ***int_mat3_alloc(int n, int k, int v) {
  int i, j;
  int ***mat;
  mat = (int ***)calloc(n, sizeof(int **));
  if (mat == NULL) {
    fprintf(stderr, "could not allocate memory");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < n; i++) {
    mat[i] = (int **)calloc(k, sizeof(int *));
    if (mat[i] == NULL) {
      fprintf(stderr, "could not allocate memory");
      exit(EXIT_FAILURE);
    }
    for (j = 0; j < k; j++) {
      mat[i][j] = (int *)calloc(v, sizeof(int));
      if (mat[i][j] == NULL) {
        fprintf(stderr, "could not allocate memory");
        exit(EXIT_FAILURE);
      }
    }
  }
  return mat;
}


x86 assembly (clang, -O0):
<int_mat3_alloc>:
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,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1180 <int_mat3_alloc+0x50>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1280 <int_mat3_alloc+0x150>
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@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    11e5 <int_mat3_alloc+0xb5>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126d <int_mat3_alloc+0x13d>
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@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    125a <int_mat3_alloc+0x12a>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    125f <int_mat3_alloc+0x12f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ec <int_mat3_alloc+0xbc>
jmp    1272 <int_mat3_alloc+0x142>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <int_mat3_alloc+0x57>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_mat3_alloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11df <int_mat3_alloc+0xaf>
mov    %rax,%rbp
test   %r15d,%r15d
jle    11cd <int_mat3_alloc+0x9d>
mov    %r15d,%eax
mov    %rax,(%rsp)
mov    %r14d,%r13d
xor    %ebx,%ebx
jmp    117a <int_mat3_alloc+0x4a>
nopl   (%rax)
add    $0x1,%rbx
cmp    (%rsp),%rbx
je     11cd <int_mat3_alloc+0x9d>
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
test   %rax,%rax
je     11df <int_mat3_alloc+0xaf>
test   %r14d,%r14d
jle    1170 <int_mat3_alloc+0x40>
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r12d,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    0x0(%rbp,%rbx,8),%rcx
mov    %rax,(%rcx,%r15,8)
mov    0x0(%rbp,%rbx,8),%rax
cmpq   $0x0,(%rax,%r15,8)
je     11df <int_mat3_alloc+0xaf>
add    $0x1,%r15
cmp    %r15,%r13
jne    11a0 <int_mat3_alloc+0x70>
jmp    1170 <int_mat3_alloc+0x40>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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