#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_FAILURE;
void *__caryll_allocate_clean(size_t, unsigned long);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long,
                           unsigned long);
int /*<<< orphan*/ free(void *);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *__caryll_reallocate(void *ptr, size_t n, unsigned long line) {
  if (!n) {
    free(ptr);
    return NULL;
  }
  if (!ptr) {
    return __caryll_allocate_clean(n, line);
  } else {
    void *p = realloc(ptr, n);
    if (!p) {
      fprintf(stderr, "[%ld]Out of memory(%ld bytes)\n", line,
              (unsigned long)n);
      exit(EXIT_FAILURE);
    }
    return p;
  }
}


x86 assembly (clang, -O0):
<__caryll_reallocate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1185 <__caryll_reallocate+0x35>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <__caryll_reallocate+0xa5>
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <__caryll_reallocate+0x56>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <__caryll_allocate_clean@plt>
mov    %rax,-0x8(%rbp)
jmp    11f5 <__caryll_reallocate+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ed <__caryll_reallocate+0x9d>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__caryll_reallocate>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     119a <__caryll_reallocate+0x4a>
mov    %rdx,%r14
mov    %rsi,%rbx
test   %rdi,%rdi
je     11a9 <__caryll_reallocate+0x59>
mov    %rbx,%rsi
call   1050 <realloc@plt>
test   %rax,%rax
jne    11a1 <__caryll_reallocate+0x51>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <__caryll_allocate_clean@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"[%ld]Out of memory(%ld bytes)\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @__caryll_reallocate(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 @free(i8* %12)
store i8* null, i8** %4
br label %36
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i64, i64* %6
%19 = load i64, i64* %7
%20 = call i8* @__caryll_allocate_clean(i64 %18, i64 %19)
store i8* %20, i8** %4
br label %36
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i8* @realloc(i8* %22, i64 %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %34, label %27
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i64, i64* %7
%30 = load i64, i64* %6
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %29, i64 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %21
%35 = load i8*, i8** %8
store i8* %35, i8** %4
br label %36
36: ; preds = %34, %17, %11
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"[%ld]Out of memory(%ld bytes)\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @__caryll_reallocate(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @free(i8* %0)
br label %19
7: ; preds = %3
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i8* @__caryll_allocate_clean(i64 %1, i64 %2)
br label %19
11: ; preds = %7
%12 = tail call i8* @realloc(i8* %0, i64 %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %2, i64 %1)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %11, %9, %5
%20 = phi i8* [ %10, %9 ], [ null, %5 ], [ %12, %11 ]
ret i8* %20
}