#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 *);
char *malloc(unsigned int);
char *realloc(char *, unsigned int);
int /*<<< orphan*/ stderr;
char *xrealloc(char *ptr, int size) {
  char *ret;
  if ((ret = !ptr ? malloc((unsigned)size) : realloc(ptr, (unsigned)size)))
    return ret;
  fprintf(stderr, "Memory exhausted\n");
  exit(1);
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116b <xrealloc+0x2b>
mov    -0xc(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
jmp    117b <xrealloc+0x3b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1197 <xrealloc+0x57>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<xrealloc>:
push   %rax
test   %rdi,%rdi
je     1152 <xrealloc+0x12>
call   1050 <realloc@plt>
test   %rax,%rax
je     115e <xrealloc+0x1e>
pop    %rcx
ret
mov    %esi,%edi
call   1040 <malloc@plt>
test   %rax,%rax
jne    1150 <xrealloc+0x10>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Memory exhausted\0A\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 i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i8* @malloc(i32 %9)
br label %15
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = call i8* @realloc(i8* %12, i32 %13)
br label %15
15: ; preds = %11, %8
%16 = phi i8* [ %10, %8 ], [ %14, %11 ]
store i8* %16, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i8*, i8** %5
ret i8* %19
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
}

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