#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*/ fatal_error(int, char *, size_t);
void *mymalloc(size_t);
void *realloc(void *, size_t);
void myrealloc(void **o, size_t newsize) {
  if (*o == NULL)
    *o = mymalloc(newsize);
  else if (!(*o = realloc(*o, newsize))) {
    fatal_error(2, "Out of memory re-allocating %d bytes\n", newsize);
  }
}


x86 assembly (clang, -O0):
<myrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1166 <myrealloc+0x36>
mov    -0x10(%rbp),%rdi
call   1040 <mymalloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11a1 <myrealloc+0x71>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    -0x8(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    119c <myrealloc+0x6c>
mov    -0x10(%rbp),%rdx
mov    $0x2,%edi
lea    0xe69(%rip),%rsi
call   1030 <fatal_error@plt>
jmp    11a1 <myrealloc+0x71>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myrealloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     116d <myrealloc+0x3d>
mov    %r14,%rsi
call   1050 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    1178 <myrealloc+0x48>
lea    0xea7(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fatal_error@plt>
mov    %r14,%rdi
call   1040 <mymalloc@plt>
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Out of memory re-allocating %d bytes\0A\00"
define void @myrealloc(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
store i8** %0, i8*** %3
store i64 %1, i64* %4
%5 = load i8**, i8*** %3
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i64, i64* %4
%10 = call i8* @mymalloc(i64 %9)
%11 = load i8**, i8*** %3
store i8* %10, i8** %11
br label %23
12: ; preds = %2
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = load i64, i64* %4
%16 = call i8* @realloc(i8* %14, i64 %15)
%17 = load i8**, i8*** %3
store i8* %16, i8** %17
%18 = icmp ne i8* %16, null
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load i64, i64* %4
%21 = call i32 @fatal_error(i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %20)
br label %22
22: ; preds = %19, %12
br label %23
23: ; preds = %22, %8
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"Out of memory re-allocating %d bytes\0A\00"
define void @myrealloc(i8** nocapture %0, i64 %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i8* @mymalloc(i64 %1)
store i8* %6, i8** %0
br label %12
7: ; preds = %2
%8 = tail call i8* @realloc(i8* %3, i64 %1)
store i8* %8, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @fatal_error(i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %12
12: ; preds = %7, %10, %5
ret void
}