#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 */
void *realloc(void *, size_t);
int /*<<< orphan*/ report_error(char const *, int, char *, void *,
                                unsigned int);
int /*<<< orphan*/ rsh_exit(int);
void *rhash_realloc(void *mem, size_t size, const char *srcfile, int srcline) {
  void *res = realloc(mem, size);
  if (!res) {
    report_error(srcfile, srcline, "realloc(%p, %u) failed\n", mem,
                 (unsigned)size);
    rsh_exit(2);
  }
  return res;
}


x86 assembly (clang, -O0):
<rhash_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    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118b <rhash_realloc+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %eax,%r8d
lea    0xe84(%rip),%rdx
call   1030 <report_error@plt>
mov    $0x2,%edi
call   1050 <rsh_exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rhash_realloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbp
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1173 <rhash_realloc+0x43>
lea    0xea8(%rip),%rdx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %rbp,%rcx
mov    %r14d,%r8d
call   1030 <report_error@plt>
mov    $0x2,%edi
call   1050 <rsh_exit@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"realloc(%p, %u) failed\0A\00"
define i8* @rhash_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** %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 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = trunc i64 %19 to i32
%21 = call i32 @report_error(i8* %16, i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %20)
%22 = call i32 @rsh_exit(i32 2)
br label %23
23: ; preds = %15, %4
%24 = load i8*, i8** %9
ret i8* %24
}

LLVM IR (-O2):
@.str = [24 x i8] c"realloc(%p, %u) failed\0A\00"
define noalias i8* @rhash_realloc(i8* %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 %11
7: ; preds = %4
%8 = trunc i64 %1 to i32
%9 = tail call i32 @report_error(i8* %2, i32 %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
%10 = tail call i32 @rsh_exit(i32 2)
br label %11
11: ; preds = %7, %4
ret i8* %5
}