#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 *, char const *, int,
                           unsigned long);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *_tc_realloc(const char *file, int line, void *p, size_t size) {
  p = realloc(p, size);
  if (p == NULL && size > 0) {
    fprintf(stderr, "[%s:%d] tc_realloc(): can't allocate %lu bytes\n", file,
            line, (unsigned long)size);
  }
  return p;
}


x86 assembly (clang, -O0):
<_tc_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117e <_tc_realloc+0x5e>
cmpq   $0x0,-0x20(%rbp)
jbe    117e <_tc_realloc+0x5e>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tc_realloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rdx,%rdi
mov    %rcx,%rsi
call   1040 <realloc@plt>
mov    %rax,%rbp
test   %rbx,%rbx
je     1166 <_tc_realloc+0x46>
test   %rbp,%rbp
jne    1166 <_tc_realloc+0x46>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"[%s:%d] tc_realloc(): can't allocate %lu bytes\0A\00"
define i8* @_tc_realloc(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = load i8*, i8** %7
%10 = load i64, i64* %8
%11 = call i8* @realloc(i8* %9, i64 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %4
%15 = load i64, i64* %8
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = load i64, i64* %8
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %20, i64 %21)
br label %23
23: ; preds = %17, %14, %4
%24 = load i8*, i8** %7
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"[%s:%d] tc_realloc(): can't allocate %lu bytes\0A\00"
define noalias i8* @_tc_realloc(i8* %0, i32 %1, i8* nocapture %2, i64 %3) {
%5 = tail call i8* @realloc(i8* %2, i64 %3)
%6 = icmp eq i8* %5, null
%7 = icmp ne i64 %3, 0
%8 = and i1 %7, %6
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i64 %3)
br label %12
12: ; preds = %9, %4
ret i8* %5
}