#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__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void *emalloc(size_t size) {
  void *retval;
  if (!size)
    return NULL;
  errno = 0;
  retval = malloc(size);
  if (!retval) {
    perror("CRITICAL ERROR");
    exit(-1);
  }
  if (!retval) {
    fprintf(stderr, "Fatal Error: Unable to allocate memory\n");
    exit(-1);
  }
  return retval;
}


x86 assembly (clang, -O0):
<emalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <emalloc+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <emalloc+0x92>
mov    0x2e6d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a0 <emalloc+0x60>
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11ca <emalloc+0x8a>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emalloc>:
push   %rax
test   %rdi,%rdi
je     1150 <emalloc+0x20>
mov    0x2ea3(%rip),%rax
movq   $0x0,(%rax)
call   1030 <malloc@plt>
test   %rax,%rax
je     1154 <emalloc+0x24>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
lea    0xea5(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [15 x i8] c"CRITICAL ERROR\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"Fatal Error: Unable to allocate memory\0A\00"
define i8* @emalloc(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp ne i64 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %25
8: ; preds = %1
store i64 0, i64* @errno
%9 = load i64, i64* %3
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %16
%24 = load i8*, i8** %4
store i8* %24, i8** %2
br label %25
25: ; preds = %23, %7
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [15 x i8] c"CRITICAL ERROR\00"
@stderr = global i32 0
define noalias i8* @emalloc(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %9, label %3
3: ; preds = %1
store i64 0, i64* @errno
%4 = tail call i8* @malloc(i64 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %3, %1
%10 = phi i8* [ null, %1 ], [ %4, %3 ]
ret i8* %10
}