#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
void *realloc(void *, unsigned int);
int /*<<< orphan*/ stderr;
void *xrealloc(void *oldp, unsigned int size) {
  void *p;
  if (size == 0)
    ++size;
  p = realloc(oldp, size);
  if (!p) {
    fprintf(stderr, "xrealloc: realloc(%d) failed", size);
    perror(NULL);
    exit(1);
  }
  return (p);
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1162 <xrealloc+0x22>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <xrealloc+0x68>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe70(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %rbx
test   %esi,%esi
mov    $0x1,%ebx
cmovne %esi,%ebx
mov    %ebx,%esi
call   1040 <realloc@plt>
test   %rax,%rax
je     1159 <xrealloc+0x19>
pop    %rbx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"xrealloc: realloc(%d) failed\00"
define i8* @xrealloc(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i32 1, i32 %1
%5 = tail call i8* @realloc(i8* %0, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %4)
%10 = tail call i32 @perror(i32* null)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
ret i8* %5
}