#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*/ die(char *, size_t, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
void *realloc(void *, size_t);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *xrealloc(void *ptr, size_t size, const char *name) {
  void *buf;
  buf = realloc(ptr, size);
  if (!buf) {
    die("Cannot realloc %ld bytes to hold %s: %s\n", size + 0UL, name,
        strerror(errno));
  }
  return buf;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1198 <xrealloc+0x68>
mov    -0x10(%rbp),%rax
add    $0x0,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
lea    0xe6d(%rip),%rdi
call   1040 <die@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1030 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <xrealloc+0x3a>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xea3(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <die@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Cannot realloc %ld bytes to hold %s: %s\0A\00"
@errno = global i32 0
define i8* @xrealloc(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = load i64, i64* %5
%10 = call i8* @realloc(i8* %8, i64 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %3
%14 = load i64, i64* %5
%15 = add i64 %14, 0
%16 = load i8*, i8** %6
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @die(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %15, i8* %16, i32 %18)
br label %20
20: ; preds = %13, %3
%21 = load i8*, i8** %7
ret i8* %21
}

LLVM IR (-O2):
@.str = [41 x i8] c"Cannot realloc %ld bytes to hold %s: %s\0A\00"
@errno = global i32 0
define noalias i8* @xrealloc(i8* nocapture %0, i64 %1, i8* %2) {
%4 = tail call i8* @realloc(i8* %0, i64 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @die(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %1, i8* %2, i32 %8)
br label %10
10: ; preds = %6, %3
ret i8* %4
}