#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*/ fprintf(int /*<<< orphan*/, char *, void *, long, void *,
                           char const *, char const *, int);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *debug_realloc(void *ptr, size_t size, const char *file, int line,
                    const char *function) {
  void *next = realloc(ptr, size);
  fprintf(stderr, "realloc(0x%p, %ld) returned 0x%p (%s:%s:%d)\n", ptr,
          (long)size, next, file, function, line);
  return next;
}


x86 assembly (clang, -O0):
<debug_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0x1c(%rbp),%eax
lea    0xe8d(%rip),%rsi
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <fprintf@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_realloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
call   1040 <realloc@plt>
mov    %rax,%rbp
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %r12,%r9
push   %r15
push   %r14
call   1030 <fprintf@plt>
add    $0x10,%rsp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"realloc(0x%p, %ld) returned 0x%p (%s:%s:%d)\0A\00"
define i8* @debug_realloc(i8* %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %11
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %6
%17 = load i64, i64* %7
%18 = load i8*, i8** %11
%19 = load i8*, i8** %8
%20 = load i8*, i8** %10
%21 = load i32, i32* %9
%22 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %16, i64 %17, i8* %18, i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %11
ret i8* %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"realloc(0x%p, %ld) returned 0x%p (%s:%s:%d)\0A\00"
define i8* @debug_realloc(i8* %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = tail call i8* @realloc(i8* %0, i64 %1)
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i8* %6, i8* %2, i8* %4, i32 %3)
ret i8* %6
}