#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, size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *mpfq_realloc_check(void *p, size_t os, size_t s) {
  void *r = realloc(p, s);
  if (s && !r) {
    fprintf(stderr, "realloc(%zu, %zu) failed\n", os, s);
    abort();
  }
  return r;
}


x86 assembly (clang, -O0):
<mpfq_realloc_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118f <mpfq_realloc_check+0x5f>
cmpq   $0x0,-0x20(%rbp)
jne    118f <mpfq_realloc_check+0x5f>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpfq_realloc_check>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdx,%rsi
call   1050 <realloc@plt>
test   %rbx,%rbx
je     114c <mpfq_realloc_check+0x1c>
test   %rax,%rax
je     1154 <mpfq_realloc_check+0x24>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"realloc(%zu, %zu) failed\0A\00"
define i8* @mpfq_realloc_check(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = load i64, i64* %6
%10 = call i8* @realloc(i8* %8, i64 %9)
store i8* %10, i8** %7
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %18, i64 %19)
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %13, %3
%23 = load i8*, i8** %7
ret i8* %23
}

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