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


x86 assembly (clang, -O0):
<cdiXrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1173 <cdiXrealloc+0x43>
cmpq   $0x0,-0x30(%rbp)
je     1178 <cdiXrealloc+0x48>
jmp    11ba <cdiXrealloc+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4b(%rip),%r8
call   1030 <cdiAbortC@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdiXrealloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbp
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rbp,%rbp
je     117e <cdiXrealloc+0x4e>
test   %rbx,%rbx
jne    117e <cdiXrealloc+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 = [19 x i8] c"realloc failed: %s\00"
@errno = global i32 0
define i8* @cdiXrealloc(i8* %0, i64 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %11
%15 = load i64, i64* %7
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %5
%18 = load i8*, i8** %11
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17, %5
br label %28
21: ; preds = %17
%22 = load i8*, i8** %9
%23 = load i8*, i8** %8
%24 = load i32, i32* %10
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 @cdiAbortC(i32* null, i8* %22, i8* %23, i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %21, %20
%29 = load i8*, i8** %11
ret i8* %29
}

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