#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(int);
int /*<<< orphan*/ message_exit(char *);
unsigned char **malloc_char_image(int xres, int yres) {
  unsigned char **image;
  int j;
  image = (unsigned char **)malloc(sizeof(unsigned char *) * yres);
  if (image == NULL)
    message_exit("char");
  for (j = 0; j < yres; j++) {
    image[j] = (unsigned char *)malloc(sizeof(unsigned char) * xres);
    if (image[j] == NULL)
      message_exit("char");
  }
  return (image);
}


x86 assembly (clang, -O0):
<malloc_char_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <malloc_char_image+0x38>
lea    0xead(%rip),%rdi
call   1040 <message_exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bb <malloc_char_image+0x9b>
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11a8 <malloc_char_image+0x88>
lea    0xe5d(%rip),%rdi
call   1040 <message_exit@plt>
jmp    11ad <malloc_char_image+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115f <malloc_char_image+0x3f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_char_image>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     114a <malloc_char_image+0x2a>
test   %r14d,%r14d
jg     115b <malloc_char_image+0x3b>
jmp    1194 <malloc_char_image+0x74>
lea    0xeaf(%rip),%rdi
call   1040 <message_exit@plt>
test   %r14d,%r14d
jle    1194 <malloc_char_image+0x74>
mov    %r14d,%ebp
xor    %ebx,%ebx
lea    0xe99(%rip),%r14
jmp    1179 <malloc_char_image+0x59>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1194 <malloc_char_image+0x74>
mov    %r15d,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
jne    1170 <malloc_char_image+0x50>
mov    %r14,%rdi
call   1040 <message_exit@plt>
jmp    1170 <malloc_char_image+0x50>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"char\00"
define i8** @malloc_char_image(i32 %0, i32 %1) {
%3 = shl i32 %1, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8**
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @message_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %24
11: ; preds = %9
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %21
%14 = phi i64 [ 0, %11 ], [ %22, %21 ]
%15 = tail call i64 @malloc(i32 %0)
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds i8*, i8** %5, i64 %14
store i8* %16, i8** %17
%18 = icmp eq i64 %15, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @message_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %13, %19
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %24, label %13
24: ; preds = %21, %9
ret i8** %5
}