#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;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ puts(char *);
int **malloc_mat(int col, int line) {
  int **mat = malloc(col * sizeof(int *));
  if (mat == NULL)
    return NULL;
  for (int i = 0; i < col; i++) {
    mat[i] = malloc(line * sizeof(int));
    if (mat[i] == NULL) {
      puts("[-]Can't allocate memory");
      exit(EXIT_FAILURE);
    }
  }
  return mat;
}


x86 assembly (clang, -O0):
<malloc_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1169 <malloc_mat+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11e2 <malloc_mat+0xb2>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11da <malloc_mat+0xaa>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11c7 <malloc_mat+0x97>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    11cc <malloc_mat+0x9c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1170 <malloc_mat+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_mat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     118c <malloc_mat+0x5c>
mov    %rax,%r12
test   %r14d,%r14d
jle    118f <malloc_mat+0x5f>
shl    $0x2,%r15d
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     119b <malloc_mat+0x6b>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <malloc_mat+0x40>
jmp    118f <malloc_mat+0x5f>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"[-]Can't allocate memory\00"
@EXIT_FAILURE = global i32 0
define i32** @malloc_mat(i32 %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
%13 = bitcast i8* %12 to i32**
store i32** %13, i32*** %6
%14 = load i32**, i32*** %6
%15 = icmp eq i32** %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32** null, i32*** %3
br label %49
17: ; preds = %2
store i32 0, i32* %7
br label %18
18: ; preds = %44, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
%28 = bitcast i8* %27 to i32*
%29 = load i32**, i32*** %6
%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*** %6
%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 %43
39: ; preds = %22
%40 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %22
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %18
47: ; preds = %18
%48 = load i32**, i32*** %6
store i32** %48, i32*** %3
br label %49
49: ; preds = %47, %16
%50 = load i32**, i32*** %3
ret i32** %50
}

LLVM IR (-O2):
@.str = [25 x i8] c"[-]Can't allocate memory\00"
@EXIT_FAILURE = global i32 0
define noalias i32** @malloc_mat(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8* %4 to i32**
%6 = icmp eq i8* %4, null
br i1 %6, label %25, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %25
9: ; preds = %7
%10 = shl i32 %1, 2
%11 = zext i32 %0 to i64
br label %14
12: ; preds = %14
%13 = icmp eq i64 %20, %11
br i1 %13, label %25, label %14
14: ; preds = %9, %12
%15 = phi i64 [ 0, %9 ], [ %20, %12 ]
%16 = tail call i8* @malloc(i32 %10)
%17 = getelementptr inbounds i32*, i32** %5, i64 %15
%18 = bitcast i32** %17 to i8**
store i8* %16, i8** %18
%19 = icmp eq i8* %16, null
%20 = add nuw nsw i64 %15, 1
br i1 %19, label %21, label %12
21: ; preds = %14
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %12, %7, %2
%26 = phi i32** [ null, %2 ], [ %5, %7 ], [ %5, %12 ]
ret i32** %26
}