#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*/ fatal_out_of_memory();
void *malloc(int);
unsigned char **new_matrix(const unsigned int width,
                           const unsigned int height) {
  unsigned int i;
  unsigned char **const matrix = malloc(sizeof(char *) * width);
  if (!matrix) {
    fatal_out_of_memory();
  }
  for (i = 0; i < width; i++) {
    matrix[i] = malloc(sizeof(char) * height);
    if (!matrix[i]) {
      fatal_out_of_memory();
    }
  }
  return matrix;
}


x86 assembly (clang, -O0):
<new_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1152 <new_matrix+0x32>
mov    $0x0,%al
call   1040 <fatal_out_of_memory@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11ad <new_matrix+0x8d>
mov    -0x8(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
jne    119a <new_matrix+0x7a>
mov    $0x0,%al
call   1040 <fatal_out_of_memory@plt>
jmp    119f <new_matrix+0x7f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <new_matrix+0x39>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     114a <new_matrix+0x2a>
test   %r14d,%r14d
jne    1156 <new_matrix+0x36>
jmp    1183 <new_matrix+0x63>
xor    %eax,%eax
call   1040 <fatal_out_of_memory@plt>
test   %r14d,%r14d
je     1183 <new_matrix+0x63>
mov    %r14d,%ebp
xor    %ebx,%ebx
jmp    1169 <new_matrix+0x49>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1183 <new_matrix+0x63>
mov    %r15d,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
jne    1160 <new_matrix+0x40>
xor    %eax,%eax
call   1040 <fatal_out_of_memory@plt>
jmp    1160 <new_matrix+0x40>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @new_matrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = zext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %6
%13 = load i8**, i8*** %6
%14 = icmp ne i8** %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (...) @fatal_out_of_memory()
br label %17
17: ; preds = %15, %2
store i32 0, i32* %5
br label %18
18: ; preds = %41, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %44
22: ; preds = %18
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
%28 = load i8**, i8*** %6
%29 = load i32, i32* %5
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
store i8* %27, i8** %31
%32 = load i8**, i8*** %6
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = icmp ne i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %22
%39 = call i32 (...) @fatal_out_of_memory()
br label %40
40: ; preds = %38, %22
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add i32 %42, 1
store i32 %43, i32* %5
br label %18
44: ; preds = %18
%45 = load i8**, i8*** %6
ret i8** %45
}

LLVM IR (-O2):
define noalias i8** @new_matrix(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8* %4 to i8**
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (...) @fatal_out_of_memory()
br label %9
9: ; preds = %7, %2
%10 = icmp eq i32 %0, 0
br i1 %10, label %23, label %11
11: ; preds = %9
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %20
%14 = phi i64 [ 0, %11 ], [ %21, %20 ]
%15 = tail call i8* @malloc(i32 %1)
%16 = getelementptr inbounds i8*, i8** %5, i64 %14
store i8* %15, i8** %16
%17 = icmp eq i8* %15, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (...) @fatal_out_of_memory()
br label %20
20: ; preds = %13, %18
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %13
23: ; preds = %20, %9
ret i8** %5
}