#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*/ fprintf(int /*<<< orphan*/, char *, size_t);
scalar_t__ realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *xmalloc(size_t);
void *xrealloc(void *ptr, size_t s) {
  void *new;
  if (!ptr)
    return xmalloc(s);
  new = (void *)realloc(ptr, s);
  if (!new)
    fprintf(stderr, "mplib: Memory exhausted: Could not allocate %d bytes\n",
            s);
  return new;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <xrealloc+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <xmalloc@plt>
mov    %rax,-0x8(%rbp)
jmp    119a <xrealloc+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1192 <xrealloc+0x62>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
je     116f <xrealloc+0x3f>
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1164 <xrealloc+0x34>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <xmalloc@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"mplib: Memory exhausted: Could not allocate %d bytes\0A\00"
define i8* @xrealloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i64, i64* %5
%11 = call i8* @xmalloc(i64 %10)
store i8* %11, i8** %3
br label %25
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = call i64 @realloc(i8* %13, i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = load i64, i64* %5
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %21)
br label %23
23: ; preds = %19, %12
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %25
25: ; preds = %23, %9
%26 = load i8*, i8** %3
ret i8* %26
}

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