#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 *);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
long **alloc2DMatrix(size_t xsize, size_t ysize) {
  long **matrix;
  long i;
  matrix = malloc(xsize * sizeof(long *));
  if (matrix == NULL) {
    fprintf(stderr, "?FATAL ERROR 1376 Out of memory\n");
    exit(1);
  }
  for (i = 0; i < (long)xsize; i++) {
    matrix[i] = malloc(ysize * sizeof(long));
    if (matrix[i] == NULL) {
      fprintf(stderr, "?FATAL ERROR 1377 Out of memory\n");
      exit(1);
    }
  }
  return matrix;
}


x86 assembly (clang, -O0):
<alloc2DMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <alloc2DMatrix+0x4b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11f5 <alloc2DMatrix+0xc5>
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11df <alloc2DMatrix+0xaf>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11e4 <alloc2DMatrix+0xb4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1183 <alloc2DMatrix+0x53>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc2DMatrix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdi,8),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     11a8 <alloc2DMatrix+0x78>
mov    %rax,%r12
test   %r15,%r15
jle    117a <alloc2DMatrix+0x4a>
shl    $0x3,%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     1189 <alloc2DMatrix+0x59>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <alloc2DMatrix+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
jmp    1199 <alloc2DMatrix+0x69>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"?FATAL ERROR 1376 Out of memory\0A\00"
@.str.1 = [33 x i8] c"?FATAL ERROR 1377 Out of memory\0A\00"
define noalias i64** @alloc2DMatrix(i64 %0, i64 %1) {
%3 = shl i64 %0, 3
%4 = tail call i8* @malloc(i64 %3)
%5 = bitcast i8* %4 to i64**
%6 = icmp eq i8* %4, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = icmp sgt i64 %0, 0
br i1 %8, label %9, label %28
9: ; preds = %7
%10 = shl i64 %1, 3
br label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %17
%16 = icmp eq i64 %23, %0
br i1 %16, label %28, label %17
17: ; preds = %9, %15
%18 = phi i64 [ 0, %9 ], [ %23, %15 ]
%19 = tail call i8* @malloc(i64 %10)
%20 = getelementptr inbounds i64*, i64** %5, i64 %18
%21 = bitcast i64** %20 to i8**
store i8* %19, i8** %21
%22 = icmp eq i8* %19, null
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %24, label %15
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %15, %7
ret i64** %5
}