#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);
void *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
void *eca_malloc(size_t bytes, char *VarName) {
  void *temp;
  if (bytes == 0)
    return NULL;
  if ((temp = malloc(bytes)) == NULL) {
    printf("\n\nMEMORY ALLOCATION FAILURE:");
    printf("\nAttempted function: malloc(%s)", VarName);
    printf("\n%s = %d bytes", VarName, (int)bytes);
    printf("\n\nExiting to system...\n\n");
    exit(1);
  }
  return (temp);
}


x86 assembly (clang, -O0):
<eca_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <eca_malloc+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11c7 <eca_malloc+0x97>
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11bf <eca_malloc+0x8f>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eca_malloc>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a1 <eca_malloc+0x61>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <malloc@plt>
test   %rax,%rax
jne    11a3 <eca_malloc+0x63>
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"\0A\0AMEMORY ALLOCATION FAILURE:\00"
@.str.1 = [32 x i8] c"\0AAttempted function: malloc(%s)\00"
@.str.2 = [15 x i8] c"\0A%s = %d bytes\00"
@.str.3 = [25 x i8] c"\0A\0AExiting to system...\0A\0A\00"
define i8* @eca_malloc(i64 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %26
10: ; preds = %2
%11 = load i64, i64* %4
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %5
%19 = load i64, i64* %4
%20 = trunc i64 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %10
%25 = load i8*, i8** %6
store i8* %25, i8** %3
br label %26
26: ; preds = %24, %9
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@.str = [29 x i8] c"\0A\0AMEMORY ALLOCATION FAILURE:\00"
@.str.1 = [32 x i8] c"\0AAttempted function: malloc(%s)\00"
@.str.2 = [15 x i8] c"\0A%s = %d bytes\00"
@str = [24 x i8] c"\0A\0AExiting to system...\0A\00"
define noalias i8* @eca_malloc(i64 %0, i8* %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = tail call i8* @malloc(i64 %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = trunc i64 %0 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %4, %2
%15 = phi i8* [ null, %2 ], [ %5, %4 ]
ret i8* %15
}