#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 */
void *SafeMalloc(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
void *realloc(void *, int);
int /*<<< orphan*/ stderr;
void *SafeRealloc(void *pOld, int nByte) {
  void *p;
  if (pOld == 0) {
    p = SafeMalloc(nByte);
  } else {
    p = realloc(pOld, nByte);
    if (p == 0) {
      fprintf(stderr,
              "Out of memory.  Can't enlarge an allocation to %d bytes\n",
              nByte);
      exit(1);
    }
  }
  return p;
}


x86 assembly (clang, -O0):
<SafeRealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116b <SafeRealloc+0x2b>
mov    -0xc(%rbp),%edi
call   1040 <SafeMalloc@plt>
mov    %rax,-0x18(%rbp)
jmp    11ad <SafeRealloc+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <SafeRealloc+0x68>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe67(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11ad <SafeRealloc+0x6d>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SafeRealloc>:
push   %rbx
mov    %esi,%ebx
test   %rdi,%rdi
je     1156 <SafeRealloc+0x16>
mov    %ebx,%esi
call   1050 <realloc@plt>
test   %rax,%rax
je     115e <SafeRealloc+0x1e>
pop    %rbx
ret
mov    %ebx,%edi
pop    %rbx
jmp    1040 <SafeMalloc@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"Out of memory. Can't enlarge an allocation to %d bytes\0A\00"
define i8* @SafeRealloc(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 i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i8* @SafeMalloc(i32 %9)
store i8* %10, i8** %5
br label %23
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = call i8* @realloc(i8* %12, i32 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i32, i32* %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %11
br label %23
23: ; preds = %22, %8
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"Out of memory. Can't enlarge an allocation to %d bytes\0A\00"
define i8* @SafeRealloc(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @SafeMalloc(i32 %1)
br label %13
6: ; preds = %2
%7 = tail call i8* @realloc(i8* %0, i32 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %1)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %4
%14 = phi i8* [ %5, %4 ], [ %7, %6 ]
ret i8* %14
}