#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 */
scalar_t__ malloc(size_t);
unsigned char **pgm_create_matrix(size_t width, size_t height) {
  unsigned char **matrix =
      (unsigned char **)malloc(width * sizeof(unsigned char *));
  for (size_t x = 0; x < width; x++) {
    matrix[x] = (unsigned char *)malloc(height * sizeof(unsigned char));
  }
  return matrix;
}


x86 assembly (clang, -O0):
<pgm_create_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1174 <pgm_create_matrix+0x64>
mov    -0x10(%rbp),%rdi
shl    $0x0,%rdi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1139 <pgm_create_matrix+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgm_create_matrix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdi,8),%rdi
call   1030 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
je     1155 <pgm_create_matrix+0x45>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <pgm_create_matrix+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @pgm_create_matrix(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8**
%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 i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8**
store i8** %10, i8*** %5
store i64 0, i64* %6
br label %11
11: ; preds = %23, %2
%12 = load i64, i64* %6
%13 = load i64, i64* %3
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i64, i64* %4
%17 = mul i64 %16, 1
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
%20 = load i8**, i8*** %5
%21 = load i64, i64* %6
%22 = getelementptr inbounds i8*, i8** %20, i64 %21
store i8* %19, i8** %22
br label %23
23: ; preds = %15
%24 = load i64, i64* %6
%25 = add i64 %24, 1
store i64 %25, i64* %6
br label %11
26: ; preds = %11
%27 = load i8**, i8*** %5
ret i8** %27
}

LLVM IR (-O2):
define i8** @pgm_create_matrix(i64 %0, i64 %1) {
%3 = shl i64 %0, 3
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8**
%6 = icmp eq i64 %0, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %2
ret i8** %5
8: ; preds = %2, %8
%9 = phi i64 [ %13, %8 ], [ 0, %2 ]
%10 = tail call i64 @malloc(i64 %1)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8*, i8** %5, i64 %9
store i8* %11, i8** %12
%13 = add nuw i64 %9, 1
%14 = icmp eq i64 %13, %0
br i1 %14, label %7, label %8
}