#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*/ msgMessage(int, char *, size_t, char *);
void *realloc(void *, size_t);
void *CheckRealloc(void *ptr, size_t size) {
  register void *r;
  if (!(r = realloc(ptr, size)))
    msgMessage((0x1000 | 0x0800 | 0x0001), "Can't realloc %d byte%s", size,
               size == 1 ? "" : "s");
  return r;
}


x86 assembly (clang, -O0):
<CheckRealloc>:
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   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117a <CheckRealloc+0x5a>
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rsi
lea    0xebc(%rip),%rcx
lea    0xeb6(%rip),%rax
cmp    $0x1,%rsi
cmove  %rax,%rcx
mov    $0x1801,%edi
lea    0xe8b(%rip),%rsi
call   1040 <msgMessage@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckRealloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1030 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115e <CheckRealloc+0x3e>
cmp    $0x1,%r14
lea    0xed8(%rip),%rax
lea    0xed0(%rip),%rcx
cmove  %rax,%rcx
lea    0xeaf(%rip),%rsi
mov    $0x1801,%edi
mov    %r14,%rdx
call   1040 <msgMessage@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Can't realloc %d byte%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
define i8* @CheckRealloc(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 = icmp ne i8* %8, null
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = load i64, i64* %4
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 1
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%16 = call i32 @msgMessage(i32 6145, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %11, i8* %15)
br label %17
17: ; preds = %10, %2
%18 = load i8*, i8** %5
ret i8* %18
}

LLVM IR (-O2):
@.str = [24 x i8] c"Can't realloc %d byte%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
define noalias i8* @CheckRealloc(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 %9
5: ; preds = %2
%6 = icmp eq i64 %1, 1
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 @msgMessage(i32 6145, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %1, i8* %7)
br label %9
9: ; preds = %5, %2
ret i8* %3
}