#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*/ cdiAbortC(int /*<<< orphan*/ *, char const *, char const *,
                             int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
void *malloc(size_t);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *cdiXmalloc(size_t size, const char *filename, const char *functionname,
                 int line) {
  void *value = malloc(size);
  if (size == 0 || value != NULL)
    ;
  else
    cdiAbortC(NULL, (filename), (functionname), (line), "malloc failed: %s",
              strerror(errno));
  return value;
}


x86 assembly (clang, -O0):
<cdiXmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116a <cdiXmalloc+0x3a>
cmpq   $0x0,-0x28(%rbp)
je     116f <cdiXmalloc+0x3f>
jmp    11b1 <cdiXmalloc+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
lea    0xe54(%rip),%r8
call   1030 <cdiAbortC@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdiXmalloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rbp,%rbp
je     117e <cdiXmalloc+0x4e>
test   %rbx,%rbx
jne    117e <cdiXmalloc+0x4e>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe95(%rip),%r8
xor    %edi,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %eax,%r9d
call   1030 <cdiAbortC@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"malloc failed: %s\00"
@errno = global i32 0
define i8* @cdiXmalloc(i64 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i64, i64* %5
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %9
%12 = load i64, i64* %5
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i8*, i8** %9
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %4
br label %25
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @cdiAbortC(i32* null, i8* %19, i8* %20, i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %18, %17
%26 = load i8*, i8** %9
ret i8* %26
}

LLVM IR (-O2):
@.str = [18 x i8] c"malloc failed: %s\00"
@errno = global i32 0
define noalias i8* @cdiXmalloc(i64 %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i8* @malloc(i64 %0)
%6 = icmp eq i64 %0, 0
%7 = icmp ne i8* %5, null
%8 = or i1 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @cdiAbortC(i32* null, i8* %1, i8* %2, i32 %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %4, %9
ret i8* %5
}