#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ die_(char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
void *realloc(void *, size_t);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *xrealloc(void *ptr, size_t size) {
  assert(size > 0 && ptr);
  if (!(ptr = realloc(ptr, size)))
    die_("("
         "util.c"
         ":"
         "48"
         "): "
         "Cannot reallocate %zu bytes"
         ": %s\n",
         size, strerror(errno));
  return ptr;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jbe    116b <xrealloc+0x2b>
cmpq   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11bb <xrealloc+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe4a(%rip),%rdi
call   1050 <die_@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
setne  %al
test   %rdi,%rdi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1192 <xrealloc+0x52>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <die_@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [46 x i8] c"(util.c:48): Cannot reallocate %zu bytes: %s\0A\00"
@errno = global i32 0
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 i64, i64* %4
%6 = icmp ugt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br label %10
10: ; preds = %7, %2
%11 = phi i1 [ false, %2 ], [ %9, %7 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %3
%15 = load i64, i64* %4
%16 = call i8* @realloc(i8* %14, i64 %15)
store i8* %16, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %10
%19 = load i64, i64* %4
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @die_(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %19, i32 %21)
br label %23
23: ; preds = %18, %10
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [46 x i8] c"(util.c:48): Cannot reallocate %zu bytes: %s\0A\00"
@errno = global i32 0
define noalias i8* @xrealloc(i8* %0, i64 %1) {
%3 = icmp ne i64 %1, 0
%4 = icmp ne i8* %0, null
%5 = and i1 %4, %3
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i8* @realloc(i8* %0, i64 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @die_(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %1, i32 %12)
br label %14
14: ; preds = %10, %2
ret i8* %8
}