#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, char *, int);
int /*<<< orphan*/ perror(char *);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *_realloc_and_check(void *ptr, size_t bytes, char *file, int lineno) {
  void *ret = realloc(ptr, bytes);
  if (!ret) {
    perror("malloc/realloc: ");
    fprintf(stderr, "Malloc/Realloc(%zu bytes) failed at %s:%d\n", bytes, file,
            lineno);
    abort();
  }
  return ret;
}


x86 assembly (clang, -O0):
<_realloc_and_check>:
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    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a7 <_realloc_and_check+0x67>
lea    0xe86(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_realloc_and_check>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%rbp
call   1050 <realloc@plt>
test   %rax,%rax
je     115c <_realloc_and_check+0x1c>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe9d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r14d,%r8d
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"malloc/realloc: \00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Malloc/Realloc(%zu bytes) failed at %s:%d\0A\00"
define i8* @_realloc_and_check(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** %5
%11 = load i64, i64* %6
%12 = call i8* @realloc(i8* %10, i64 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %4
%16 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = load i64, i64* %6
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %18, i8* %19, i32 %20)
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %4
%24 = load i8*, i8** %9
ret i8* %24
}

LLVM IR (-O2):
@.str = [17 x i8] c"malloc/realloc: \00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Malloc/Realloc(%zu bytes) failed at %s:%d\0A\00"
define noalias i8* @_realloc_and_check(i8* nocapture %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i8* @realloc(i8* %0, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %1, i8* %2, i32 %3)
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %4
ret i8* %5
}