#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);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
void **matrix(int row, int col, int num_bytes) {
  int loop;
  void **pointer;
  pointer = (void **)malloc((unsigned long)(row * sizeof(void *)));
  if (!pointer) {
    printf("\nNo enough memory to store a matrix with");
    printf(" \nrow = %d  col = %d num_bytes = %d\n", row, col, num_bytes);
    exit(1);
  }
  for (loop = 0; loop < row; loop++) {
    pointer[loop] = (void *)malloc((unsigned long)(col * num_bytes));
    if (!pointer[loop]) {
      printf("\nNo enough memory to store a matrix with");
      printf(" \ncol = %d\n", col);
      exit(1);
    }
  }
  return pointer;
}


x86 assembly (clang, -O0):
<matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <matrix+0x5c>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120c <matrix+0xdc>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
movslq %eax,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11f9 <matrix+0xc9>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11fe <matrix+0xce>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <matrix+0x63>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%r12d
movslq %edi,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     11c6 <matrix+0x96>
mov    %rax,%r13
test   %r12d,%r12d
jle    118b <matrix+0x5b>
imul   %r14d,%r15d
movslq %r15d,%r15
mov    %r12d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
test   %rax,%rax
je     119d <matrix+0x6d>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <matrix+0x40>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe4e(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"\0ANo enough memory to store a matrix with\00"
@.str.1 = [37 x i8] c" \0Arow = %d col = %d num_bytes = %d\0A\00"
@.str.2 = [12 x i8] c" \0Acol = %d\0A\00"
define i8** @matrix(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8**
store i8** %13, i8*** %8
%14 = load i8**, i8*** %8
%15 = icmp ne i8** %14, null
br i1 %15, label %23, label %16
16: ; preds = %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %3
store i32 0, i32* %7
br label %24
24: ; preds = %51, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %54
28: ; preds = %24
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = mul nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8*
%35 = load i8**, i8*** %8
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
store i8* %34, i8** %38
%39 = load i8**, i8*** %8
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %50, label %45
45: ; preds = %28
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %28
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %24
54: ; preds = %24
%55 = load i8**, i8*** %8
ret i8** %55
}

LLVM IR (-O2):
@.str = [41 x i8] c"\0ANo enough memory to store a matrix with\00"
@.str.1 = [37 x i8] c" \0Arow = %d col = %d num_bytes = %d\0A\00"
@.str.2 = [12 x i8] c" \0Acol = %d\0A\00"
define i8** @matrix(i32 %0, i32 %1, i32 %2) {
%4 = sext i32 %0 to i64
%5 = shl nsw i64 %4, 3
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8**
%8 = icmp eq i64 %6, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %32
11: ; preds = %9
%12 = mul nsw i32 %2, %1
%13 = sext i32 %12 to i64
%14 = zext i32 %0 to i64
br label %21
15: ; preds = %3
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %21
%20 = icmp eq i64 %27, %14
br i1 %20, label %32, label %21
21: ; preds = %11, %19
%22 = phi i64 [ 0, %11 ], [ %27, %19 ]
%23 = tail call i64 @malloc(i64 %13)
%24 = inttoptr i64 %23 to i8*
%25 = getelementptr inbounds i8*, i8** %7, i64 %22
store i8* %24, i8** %25
%26 = icmp eq i64 %23, 0
%27 = add nuw nsw i64 %22, 1
br i1 %26, label %28, label %19
28: ; preds = %21
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %19, %9
ret i8** %7
}