#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 */
void *calloc(int, int);
int /*<<< orphan*/ error_and_exit();
int **calloc_int_mat(int dim1, int dim2) {
  int i;
  int **mat;
  mat = calloc(sizeof(int *), dim1);
  if (mat == NULL)
    error_and_exit();
  for (i = 0; i < dim1; i++) {
    mat[i] = calloc(sizeof(int), dim2);
    if (mat[i] == NULL)
      error_and_exit();
  }
  return mat;
}


x86 assembly (clang, -O0):
<calloc_int_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x8,%edi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1151 <calloc_int_mat+0x31>
mov    $0x0,%al
call   1040 <error_and_exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ad <calloc_int_mat+0x8d>
mov    -0x8(%rbp),%esi
mov    $0x4,%edi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    119a <calloc_int_mat+0x7a>
mov    $0x0,%al
call   1040 <error_and_exit@plt>
jmp    119f <calloc_int_mat+0x7f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <calloc_int_mat+0x38>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc_int_mat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x8,%edi
mov    %r14d,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     114a <calloc_int_mat+0x2a>
test   %r14d,%r14d
jg     1156 <calloc_int_mat+0x36>
jmp    1188 <calloc_int_mat+0x68>
xor    %eax,%eax
call   1040 <error_and_exit@plt>
test   %r14d,%r14d
jle    1188 <calloc_int_mat+0x68>
mov    %r14d,%ebp
xor    %ebx,%ebx
jmp    1169 <calloc_int_mat+0x49>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1188 <calloc_int_mat+0x68>
mov    $0x4,%edi
mov    %r15d,%esi
call   1030 <calloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
jne    1160 <calloc_int_mat+0x40>
xor    %eax,%eax
call   1040 <error_and_exit@plt>
jmp    1160 <calloc_int_mat+0x40>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32** @calloc_int_mat(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i8* @calloc(i32 8, i32 %7)
%9 = bitcast i8* %8 to i32**
store i32** %9, i32*** %6
%10 = load i32**, i32*** %6
%11 = icmp eq i32** %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @error_and_exit()
br label %14
14: ; preds = %12, %2
store i32 0, i32* %5
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = load i32, i32* %4
%21 = call i8* @calloc(i32 4, i32 %20)
%22 = bitcast i8* %21 to i32*
%23 = load i32**, i32*** %6
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
store i32* %22, i32** %26
%27 = load i32**, i32*** %6
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
%31 = load i32*, i32** %30
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %19
%34 = call i32 (...) @error_and_exit()
br label %35
35: ; preds = %33, %19
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %15
39: ; preds = %15
%40 = load i32**, i32*** %6
ret i32** %40
}

LLVM IR (-O2):
define noalias i32** @calloc_int_mat(i32 %0, i32 %1) {
%3 = tail call i8* @calloc(i32 8, i32 %0)
%4 = bitcast i8* %3 to i32**
%5 = icmp eq i8* %3, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @error_and_exit()
br label %8
8: ; preds = %6, %2
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %23
10: ; preds = %8
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %20
%13 = phi i64 [ 0, %10 ], [ %21, %20 ]
%14 = tail call i8* @calloc(i32 4, i32 %1)
%15 = getelementptr inbounds i32*, i32** %4, i64 %13
%16 = bitcast i32** %15 to i8**
store i8* %14, i8** %16
%17 = icmp eq i8* %14, null
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 (...) @error_and_exit()
br label %20
20: ; preds = %12, %18
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %20, %8
ret i32** %4
}