#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 */
struct floc {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fatal(struct floc *, int /*<<< orphan*/);
int /*<<< orphan*/ gettext(char *);
void *malloc(unsigned int);
void *realloc(void *, unsigned int);
void *xrealloc(void *ptr, unsigned int size) {
  void *result;
  if (!size)
    size = 1;
  result = ptr ? realloc(ptr, size) : malloc(size);
  if (result == 0)
    fatal(((struct floc *)0), gettext("virtual memory exhausted"));
  return result;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1160 <xrealloc+0x20>
movl   $0x1,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1180 <xrealloc+0x40>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    118c <xrealloc+0x4c>
mov    -0xc(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <xrealloc+0x76>
lea    0xe5a(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fatal@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %rbx
mov    %esi,%eax
test   %esi,%esi
mov    $0x1,%esi
cmovne %eax,%esi
test   %rdi,%rdi
je     1159 <xrealloc+0x19>
call   1050 <realloc@plt>
jmp    1160 <xrealloc+0x20>
mov    %esi,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117d <xrealloc+0x3d>
lea    0xe91(%rip),%rdi
call   1030 <gettext@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1060 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.floc = type { i32 }
@.str = [25 x i8] c"virtual memory exhausted\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 i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %2
store i32 1, i32* %4
br label %9
9: ; preds = %8, %2
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = call i8* @realloc(i8* %13, i32 %14)
br label %19
16: ; preds = %9
%17 = load i32, i32* %4
%18 = call i8* @malloc(i32 %17)
br label %19
19: ; preds = %16, %12
%20 = phi i8* [ %15, %12 ], [ %18, %16 ]
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @gettext(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @fatal(%struct.floc* null, i32 %24)
br label %26
26: ; preds = %23, %19
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
%struct.floc = type { i32 }
@.str = [25 x i8] c"virtual memory exhausted\00"
define i8* @xrealloc(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i32 1, i32 %1
%5 = icmp eq i8* %0, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i8* @realloc(i8* %0, i32 %4)
br label %10
8: ; preds = %2
%9 = tail call i8* @malloc(i32 %4)
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %7, %6 ], [ %9, %8 ]
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @gettext(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @fatal(%struct.floc* null, i32 %14)
br label %16
16: ; preds = %13, %10
ret i8* %11
}