#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*/ debug_addpointer(void *, size_t, char const *, int);
int /*<<< orphan*/ debug_print(char const *, int, char *, void *, size_t, int);
int /*<<< orphan*/ debug_removepointer(void *, char const *, int);
void *realloc(void *, size_t);
void *debug_realloc(void *ptr, size_t size, const char *file, int line) {
  void *ptr2;
  debug_print(file, line, "realloc", ptr, size, 0);
  debug_removepointer(ptr, file, line);
  ptr2 = realloc(ptr, size);
  debug_addpointer(ptr2, size, file, line);
  debug_print(file, line, "realloc", ptr2, size, 1);
  return ptr2;
}


x86 assembly (clang, -O0):
<debug_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe93(%rip),%rdx
xor    %r9d,%r9d
call   1060 <debug_print@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <debug_removepointer@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <debug_addpointer@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe40(%rip),%rdx
mov    $0x1,%r9d
call   1060 <debug_print@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_realloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xea5(%rip),%r15
mov    %rdx,%rdi
mov    %ecx,%esi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1060 <debug_print@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <debug_removepointer@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <realloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1040 <debug_addpointer@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
mov    $0x1,%r9d
call   1060 <debug_print@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"realloc\00"
define i8* @debug_realloc(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %7
%11 = load i32, i32* %8
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32 @debug_print(i8* %10, i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12, i64 %13, i32 0)
%15 = load i8*, i8** %5
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = call i32 @debug_removepointer(i8* %15, i8* %16, i32 %17)
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = call i8* @realloc(i8* %19, i64 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = load i64, i64* %6
%24 = load i8*, i8** %7
%25 = load i32, i32* %8
%26 = call i32 @debug_addpointer(i8* %22, i64 %23, i8* %24, i32 %25)
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = load i8*, i8** %9
%30 = load i64, i64* %6
%31 = call i32 @debug_print(i8* %27, i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %29, i64 %30, i32 1)
%32 = load i8*, i8** %9
ret i8* %32
}

LLVM IR (-O2):
@.str = [8 x i8] c"realloc\00"
define i8* @debug_realloc(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i32 @debug_print(i8* %2, i32 %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i32 0)
%6 = tail call i32 @debug_removepointer(i8* %0, i8* %2, i32 %3)
%7 = tail call i8* @realloc(i8* %0, i64 %1)
%8 = tail call i32 @debug_addpointer(i8* %7, i64 %1, i8* %2, i32 %3)
%9 = tail call i32 @debug_print(i8* %2, i32 %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7, i64 %1, i32 1)
ret i8* %7
}