#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 *allocateVector(int);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int **allocateMatrix(int rowSize, int colSize) {
  int i;
  int **matrix = (int **)malloc(rowSize * sizeof(int *));
  if (matrix == NULL) {
    printf("Allocation error: matrix\n");
    exit(-1);
  }
  for (i = 0; i < rowSize; i++) {
    matrix[i] = allocateVector(colSize);
    if (matrix[i] == NULL) {
      printf("Allocation error: matrix[%d]\n", i);
      exit(-1);
    }
  }
  return matrix;
}


x86 assembly (clang, -O0):
<allocateMatrix>:
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    1184 <allocateMatrix+0x44>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ef <allocateMatrix+0xaf>
mov    -0x8(%rbp),%edi
call   1050 <allocateVector@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    11dc <allocateMatrix+0x9c>
mov    -0xc(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    11e1 <allocateMatrix+0xa1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <allocateMatrix+0x4b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateMatrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x0(,%rbp,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c2 <allocateMatrix+0x72>
mov    %rax,%r15
test   %ebp,%ebp
jle    119a <allocateMatrix+0x4a>
mov    %ebp,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1060 <allocateVector@plt>
mov    %rax,(%r15,%rbp,8)
test   %rax,%rax
je     11a8 <allocateMatrix+0x58>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <allocateMatrix+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe51(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Allocation error: matrix\0A\00"
@.str.1 = [30 x i8] c"Allocation error: matrix[%d]\0A\00"
define i32** @allocateMatrix(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*** %6
%13 = load i32**, i32*** %6
%14 = icmp eq i32** %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
store i32 0, i32* %5
br label %19
19: ; preds = %41, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32* @allocateVector(i32 %24)
%26 = load i32**, i32*** %6
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32*, i32** %26, i64 %28
store i32* %25, i32** %29
%30 = load i32**, i32*** %6
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
%34 = load i32*, i32** %33
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %23
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %23
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %19
44: ; preds = %19
%45 = load i32**, i32*** %6
ret i32** %45
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Allocation error: matrix[%d]\0A\00"
@str = [25 x i8] c"Allocation error: matrix\00"
define i32** @allocateMatrix(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 %11, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %26
9: ; preds = %7
%10 = zext i32 %0 to i64
br label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %9, %23
%15 = phi i64 [ 0, %9 ], [ %24, %23 ]
%16 = tail call i32* @allocateVector(i32 %1)
%17 = getelementptr inbounds i32*, i32** %5, i64 %15
store i32* %16, i32** %17
%18 = icmp eq i32* %16, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = trunc i64 %15 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %14
%24 = add nuw nsw i64 %15, 1
%25 = icmp eq i64 %24, %10
br i1 %25, label %26, label %14
26: ; preds = %23, %7
ret i32** %5
}