#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*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *, size_t,
                           int /*<<< orphan*/, int /*<<< orphan*/);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *xrealloc(void *oldptr, size_t size) {
  void *ret = realloc(oldptr, size);
  if (ret == NULL) {
    fprintf(stderr, "xrealloc(%p, %li): Cannot reallocate memory (#%i: %s).\n",
            oldptr, size, errno, strerror(errno));
    exit(errno);
  }
  return ret;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ce <xrealloc+0x8e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
mov    %eax,%r9d
lea    0xe45(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <realloc@plt>
test   %rax,%rax
je     1161 <xrealloc+0x21>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e78(%rip),%rax
mov    (%rax),%r15d
mov    0x2e66(%rip),%r12
mov    (%r12),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe7c(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
call   1030 <fprintf@plt>
mov    (%r12),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"xrealloc(%p, %li): Cannot reallocate memory (#%i: %s).\0A\00"
@errno = global i32 0
define i8* @xrealloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%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 i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = load i64, i64* %4
%15 = load i32, i32* @errno
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %13, i64 %14, i32 %15, i32 %17)
%19 = load i32, i32* @errno
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"xrealloc(%p, %li): Cannot reallocate memory (#%i: %s).\0A\00"
@errno = global i32 0
define noalias i8* @xrealloc(i8* %0, i64 %1) {
%3 = tail call i8* @realloc(i8* %0, i64 %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i32 %7, i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
ret i8* %3
}