#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *malloc(int);
int /*<<< orphan*/ stderr;
void *create_array(int length, int size) {
  void *array;
  if (length == 0 || size == 0) {
    fprintf(stderr, "can't create an array of 0 length. [%d](%d)\n", length,
            size);
    return NULL;
  }
  array = malloc(length * size);
  if (array == NULL) {
    fprintf(stderr, "fatal error: can't malloc space for array.\n");
    exit(EXIT_FAILURE);
  }
  return array;
}


x86 assembly (clang, -O0):
<create_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1152 <create_array+0x22>
cmpl   $0x0,-0x10(%rbp)
jne    117c <create_array+0x4c>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <create_array+0x94>
mov    -0xc(%rbp),%edi
imul   -0x10(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <create_array+0x8c>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_array>:
push   %rbx
mov    %esi,%ecx
mov    %edi,%edx
test   %edi,%edi
je     1174 <create_array+0x44>
test   %ecx,%ecx
je     1174 <create_array+0x44>
imul   %edx,%ecx
mov    %ecx,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118d <create_array+0x5d>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xece(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"can't create an array of 0 length. [%d](%d)\0A\00"
@.str.1 = [44 x i8] c"fatal error: can't malloc space for array.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @create_array(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9, %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
store i8* null, i8** %3
br label %31
17: ; preds = %9
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = mul nsw i32 %18, %19
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = load i8*, i8** %6
store i8* %30, i8** %3
br label %31
31: ; preds = %29, %12
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"can't create an array of 0 length. [%d](%d)\0A\00"
@.str.1 = [44 x i8] c"fatal error: can't malloc space for array.\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @create_array(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
%4 = icmp eq i32 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %18
9: ; preds = %2
%10 = mul nsw i32 %1, %0
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %9, %6
%19 = phi i8* [ null, %6 ], [ %11, %9 ]
ret i8* %19
}