#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*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           void *, long long);
void *realloc(void *, long long);
int /*<<< orphan*/ stderr;
void *c_memory_realloc(void *ptr, long long nbytes, const char *file,
                       int line) {
  void *result;
  assert(nbytes > 0);
  result = realloc(ptr, nbytes);
  if (NULL == result) {
    fprintf(stderr, "%s:%d ERROR Failed to allocate ptr=%p nbytes=%llu.\n",
            file, line, ptr, nbytes);
  }
  return result;
}


x86 assembly (clang, -O0):
<c_memory_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)
cmpq   $0x0,-0x10(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    119a <c_memory_realloc+0x6a>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%r8
mov    -0x10(%rbp),%r9
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_memory_realloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %edi,%edi
test   %rsi,%rsi
setg   %dil
call   1030 <assert@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1186 <c_memory_realloc+0x56>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %r12,%r8
mov    %rbx,%r9
call   1040 <fprintf@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"%s:%d ERROR Failed to allocate ptr=%p nbytes=%llu.\0A\00"
define i8* @c_memory_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 i64, i64* %6
%11 = icmp sgt i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i8* @realloc(i8* %14, i64 %15)
store i8* %16, i8** %9
%17 = load i8*, i8** %9
%18 = icmp eq i8* null, %17
br i1 %18, label %19, label %26
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22, i8* %23, i64 %24)
br label %26
26: ; preds = %19, %4
%27 = load i8*, i8** %9
ret i8* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"%s:%d ERROR Failed to allocate ptr=%p nbytes=%llu.\0A\00"
define noalias i8* @c_memory_realloc(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = icmp sgt i64 %1, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i8* @realloc(i8* %0, i64 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3, i8* %0, i64 %1)
br label %13
13: ; preds = %10, %4
ret i8* %8
}