#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
void *my_malloc(long);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *my_realloc(void *ptr, long bytes) {
  if (!ptr)
    return my_malloc(bytes);
  if (bytes < 1L || bytes != (size_t)bytes ||
      (ptr = realloc(ptr, (size_t)bytes)) == NULL) {
    fprintf(stderr, "Reallocation to %ld bytes failed. File too big.\n", bytes);
    exit(1);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<my_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <my_realloc+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <my_malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11cc <my_realloc+0x8c>
cmpq   $0x1,-0x18(%rbp)
jl     11a1 <my_realloc+0x61>
mov    -0x18(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11a1 <my_realloc+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c4 <my_realloc+0x84>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_realloc>:
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
je     115d <my_realloc+0x1d>
test   %rbx,%rbx
jle    1166 <my_realloc+0x26>
mov    %rbx,%rsi
call   1050 <realloc@plt>
test   %rax,%rax
je     1166 <my_realloc+0x26>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <my_malloc@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Reallocation to %ld bytes failed. File too big.\0A\00"
define i8* @my_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %5
%10 = call i8* @my_malloc(i64 %9)
store i8* %10, i8** %3
br label %30
11: ; preds = %2
%12 = load i64, i64* %5
%13 = icmp slt i64 %12, 1
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = load i64, i64* %5
%16 = load i64, i64* %5
%17 = icmp ne i64 %15, %16
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i64, i64* %5
%21 = call i8* @realloc(i8* %19, i64 %20)
store i8* %21, i8** %4
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %28
23: ; preds = %18, %14, %11
%24 = load i32, i32* @stderr
%25 = load i64, i64* %5
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i8*, i8** %4
store i8* %29, i8** %3
br label %30
30: ; preds = %28, %8
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Reallocation to %ld bytes failed. File too big.\0A\00"
define i8* @my_realloc(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @my_malloc(i64 %1)
br label %15
6: ; preds = %2
%7 = icmp slt i64 %1, 1
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i8* @realloc(i8* %0, i64 %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8, %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %1)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8, %4
%16 = phi i8* [ %5, %4 ], [ %9, %8 ]
ret i8* %16
}