#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *mrsh_realloc(void *ptr, size_t size) {
  void *ret = realloc(ptr, size);
  if (ret == NULL)
    do {
      do {
        fprintf(stderr, "mrsh: ");
        fprintf(stderr, "allocation error");
        fprintf(stderr, "\n");
      } while (0);
      exit(EXIT_FAILURE);
    } while (0);
  return ret;
}


x86 assembly (clang, -O0):
<mrsh_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <mrsh_realloc+0x83>
jmp    1161 <mrsh_realloc+0x31>
jmp    1166 <mrsh_realloc+0x36>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrsh_realloc>:
push   %rbx
call   1040 <realloc@plt>
test   %rax,%rax
je     113d <mrsh_realloc+0xd>
pop    %rbx
ret
mov    0x2e9c(%rip),%rbx
mov    (%rbx),%edi
lea    0xeb3(%rip),%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeac(%rip),%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeaf(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"mrsh: \00"
@.str.1 = [17 x i8] c"allocation error\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @mrsh_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = load i64, i64* %4
%8 = call i8* @realloc(i8* %6, i64 %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %24
11: ; preds = %2
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %13
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %2
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"mrsh: \00"
@.str.1 = [17 x i8] c"allocation error\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @mrsh_realloc(i8* nocapture %0, i64 %1) {
%3 = tail call i8* @realloc(i8* %0, i64 %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
ret i8* %3
}