#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 */
typedef int /*<<< orphan*/ u_long;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *, int /*<<< orphan*/);
void *realloc(void *, size_t);
void *xmalloc(size_t);
void *xrealloc(void *src, size_t new_size) {
  void *ret;
  if (src == NULL) {
    ret = xmalloc(new_size);
  } else {
    ret = realloc(src, new_size);
  }
  if (ret == NULL)
    err(2, "xrealloc can not reallocate %lu bytes", (u_long)new_size);
  return ret;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115d <xrealloc+0x2d>
mov    -0x10(%rbp),%rdi
call   1030 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
jmp    116e <xrealloc+0x3e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <xrealloc+0x60>
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe75(%rip),%rsi
call   1040 <err@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     1146 <xrealloc+0x16>
mov    %r14,%rsi
call   1050 <realloc@plt>
jmp    114e <xrealloc+0x1e>
mov    %r14,%rdi
call   1030 <xmalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <xrealloc+0x3a>
lea    0xea3(%rip),%rsi
mov    $0x2,%edi
mov    %r14d,%edx
call   1040 <err@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"xrealloc can not reallocate %lu bytes\00"
define i8* @xrealloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i64, i64* %4
%10 = call i8* @xmalloc(i64 %9)
store i8* %10, i8** %5
br label %15
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %5
br label %15
15: ; preds = %11, %8
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i64, i64* %4
%20 = trunc i64 %19 to i32
%21 = call i32 @err(i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@.str = [38 x i8] c"xrealloc can not reallocate %lu bytes\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 %8
6: ; preds = %2
%7 = tail call i8* @realloc(i8* %0, i64 %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 %11, label %14
11: ; preds = %8
%12 = trunc i64 %1 to i32
%13 = tail call i32 @err(i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %8
ret i8* %9
}