#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*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int **imatrix(int num_row, int num_col) {
  int i, j;
  int **m;
  m = (int **)malloc(num_row * sizeof(int *));
  if (!m) {
    fprintf(stderr, "%s\n",
            "[ERROR]: Allocation failure for points to rows in imatrix()");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < num_row; i++) {
    m[i] = (int *)malloc(num_col * sizeof(int));
    if (!m[i]) {
      fprintf(stderr, "%s %d %s\n", "[ERROR]: Allocation failure for the row ",
              i, " in imatrix()");
      exit(EXIT_FAILURE);
    }
    for (j = 0; j < num_col; j++) {
      m[i][j] = 0;
    }
  }
  return m;
}


x86 assembly (clang, -O0):
<imatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1188 <imatrix+0x58>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xed6(%rip),%rsi
lea    0xe8d(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    124d <imatrix+0x11d>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@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    1202 <imatrix+0xd2>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%ecx
lea    0xe5d(%rip),%rsi
lea    0xe60(%rip),%rdx
lea    0xe41(%rip),%r8
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123a <imatrix+0x10a>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1209 <imatrix+0xd9>
jmp    123f <imatrix+0x10f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118f <imatrix+0x5f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1205 <imatrix+0xc5>
mov    %rax,%r15
test   %ebx,%ebx
jle    11be <imatrix+0x7e>
lea    0x0(,%r14,4),%r13d
mov    %r14d,%r12d
shl    $0x2,%r12
mov    %ebx,%ebp
xor    %ebx,%ebx
jmp    1199 <imatrix+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11be <imatrix+0x7e>
mov    %r13d,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     11d0 <imatrix+0x90>
test   %r14d,%r14d
jle    1190 <imatrix+0x50>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1030 <memset@plt>
jmp    1190 <imatrix+0x50>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
lea    0xe5f(%rip),%rdx
lea    0xe40(%rip),%r8
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
lea    0xde4(%rip),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11f7 <imatrix+0xb7>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [60 x i8] c"[ERROR]: Allocation failure for points to rows in imatrix()\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [10 x i8] c"%s %d %s\0A\00"
@.str.3 = [41 x i8] c"[ERROR]: Allocation failure for the row \00"
@.str.4 = [14 x i8] c" in imatrix()\00"
define i32** @imatrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32**
store i32** %13, i32*** %7
%14 = load i32**, i32*** %7
%15 = icmp ne i32** %14, null
br i1 %15, label %21, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
store i32 0, i32* %5
br label %22
22: ; preds = %67, %21
%23 = load i32, i32* %5
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %70
26: ; preds = %22
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 4
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i32*
%33 = load i32**, i32*** %7
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
store i32* %32, i32** %36
%37 = load i32**, i32*** %7
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32*, i32** %37, i64 %39
%41 = load i32*, i32** %40
%42 = icmp ne i32* %41, null
br i1 %42, label %49, label %43
43: ; preds = %26
%44 = load i32, i32* @stderr
%45 = load i32, i32* %5
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %45, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %26
store i32 0, i32* %6
br label %50
50: ; preds = %63, %49
%51 = load i32, i32* %6
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load i32**, i32*** %7
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32*, i32** %55, i64 %57
%59 = load i32*, i32** %58
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
store i32 0, i32* %62
br label %63
63: ; preds = %54
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %50
66: ; preds = %50
br label %67
67: ; preds = %66
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %22
70: ; preds = %22
%71 = load i32**, i32*** %7
ret i32** %71
}

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