#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;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void *util_Realloc(void *ptr, size_t size) {
  void *p;
  errno = 0;
  p = realloc(ptr, size);
  if ((p == NULL) && (size != 0)) {
    fprintf(stderr, "\nrealloc failed: %s\n\n", strerror(errno));
    exit(EXIT_FAILURE);
    return ptr;
  } else
    return p;
}


x86 assembly (clang, -O0):
<util_Realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c0 <util_Realloc+0x80>
cmpq   $0x0,-0x10(%rbp)
je     11c0 <util_Realloc+0x80>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe53(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_Realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e8a(%rip),%r14
movq   $0x0,(%r14)
call   1040 <realloc@plt>
test   %rbx,%rbx
je     1164 <util_Realloc+0x24>
test   %rax,%rax
je     116c <util_Realloc+0x2c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e6d(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rdi
call   1060 <strerror@plt>
lea    0xe7c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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