#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 *, size_t);
void *malloc(size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *xrealloc(void *old, size_t len) {
  if (old == 0)
    old = malloc(len ? len : 1);
  else
    old = realloc(old, len ? len : 1);
  if (old)
    return old;
  fprintf(stderr, "Out of memory reallocating %zu bytes!\n", len);
  exit(1);
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1193 <xrealloc+0x53>
cmpq   $0x0,-0x10(%rbp)
je     1173 <xrealloc+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1181 <xrealloc+0x41>
mov    $0x1,%eax
mov    %rax,-0x18(%rbp)
jmp    1181 <xrealloc+0x41>
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11d2 <xrealloc+0x92>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b3 <xrealloc+0x73>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11c1 <xrealloc+0x81>
mov    $0x1,%eax
mov    %rax,-0x28(%rbp)
jmp    11c1 <xrealloc+0x81>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e7 <xrealloc+0xa7>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe05(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<xrealloc>:
push   %rbx
mov    %rsi,%rbx
test   %rsi,%rsi
mov    $0x1,%esi
cmovne %rbx,%rsi
test   %rdi,%rdi
je     1161 <xrealloc+0x21>
call   1050 <realloc@plt>
test   %rax,%rax
je     116e <xrealloc+0x2e>
pop    %rbx
ret
mov    %rsi,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
jne    115f <xrealloc+0x1f>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Out of memory reallocating %zu bytes!\0A\00"
define i8* @xrealloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load i64, i64* %4
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i64, i64* %4
br label %13
12: ; preds = %7
br label %13
13: ; preds = %12, %10
%14 = phi i64 [ %11, %10 ], [ 1, %12 ]
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %3
br label %26
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i64, i64* %4
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i64, i64* %4
br label %23
22: ; preds = %16
br label %23
23: ; preds = %22, %20
%24 = phi i64 [ %21, %20 ], [ 1, %22 ]
%25 = call i8* @realloc(i8* %17, i64 %24)
store i8* %25, i8** %3
br label %26
26: ; preds = %23, %13
%27 = load i8*, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i8*, i8** %3
ret i8* %30
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i64, i64* %4
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %33)
%35 = call i32 @exit(i32 1)
unreachable
}

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