#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int **int_alloc2(int n, int m) {
  int **v, i;
  if ((v = (int **)malloc(n * sizeof(int *))) == NULL) {
    fprintf(stderr, "FATAL ERROR: Out of memory\n");
    exit(1);
  }
  for (i = 0; i < n; i++)
    if ((v[i] = (int *)malloc(m * sizeof(int))) == NULL) {
      fprintf(stderr, "FATAL ERROR: Out of memory\n");
      exit(1);
    }
  return v;
}


x86 assembly (clang, -O0):
<int_alloc2>:
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,-0x10(%rbp)
cmp    $0x0,%rax
jne    117a <int_alloc2+0x4a>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e4 <int_alloc2+0xb4>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11d1 <int_alloc2+0xa1>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11d6 <int_alloc2+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <int_alloc2+0x51>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_alloc2>:
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     1196 <int_alloc2+0x66>
mov    %rax,%r12
test   %r14d,%r14d
jle    118a <int_alloc2+0x5a>
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     1196 <int_alloc2+0x66>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <int_alloc2+0x40>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"FATAL ERROR: Out of memory\0A\00"
define i32** @int_alloc2(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 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %5
%13 = icmp eq i32** %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 0, i32* %6
br label %19
19: ; preds = %40, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %43
23: ; preds = %19
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = load i32**, i32*** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
store i32* %29, i32** %33
%34 = icmp eq i32* %29, null
br i1 %34, label %35, label %39
35: ; preds = %23
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %23
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %19
43: ; preds = %19
%44 = load i32**, i32*** %5
ret i32** %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"FATAL ERROR: Out of memory\0A\00"
define i32** @int_alloc2(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 %12, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %29
9: ; preds = %7
%10 = shl i32 %1, 2
%11 = zext i32 %0 to i64
br label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %18
%17 = icmp eq i64 %24, %11
br i1 %17, label %29, label %18
18: ; preds = %9, %16
%19 = phi i64 [ 0, %9 ], [ %24, %16 ]
%20 = tail call i64 @malloc(i32 %10)
%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
%24 = add nuw nsw i64 %19, 1
br i1 %23, label %25, label %16
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %16, %7
ret i32** %5
}