#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 *ILLutil_allocrus(size_t);
int /*<<< orphan*/ QSlog(char *, int);
scalar_t__ realloc(void *, size_t);
void *ILLutil_reallocrus(void *ptr, size_t size) {
  void *newptr;
  if (!ptr) {
    return ILLutil_allocrus(size);
  } else {
    newptr = (void *)realloc(ptr, size);
    if (!newptr) {
      QSlog("Out of memory.  Tried to grow to %d bytes", (int)size);
    }
    return newptr;
  }
}


x86 assembly (clang, -O0):
<ILLutil_reallocrus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <ILLutil_reallocrus+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <ILLutil_allocrus@plt>
mov    %rax,-0x8(%rbp)
jmp    1193 <ILLutil_reallocrus+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <ILLutil_reallocrus+0x5b>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
call   1050 <QSlog@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILLutil_reallocrus>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
je     1165 <ILLutil_reallocrus+0x35>
mov    %rbx,%rsi
call   1040 <realloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    115a <ILLutil_reallocrus+0x2a>
lea    0xead(%rip),%rdi
mov    %ebx,%esi
call   1050 <QSlog@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <ILLutil_allocrus@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Out of memory. Tried to grow to %d bytes\00"
define i8* @ILLutil_reallocrus(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i64, i64* %5
%11 = call i8* @ILLutil_allocrus(i64 %10)
store i8* %11, i8** %3
br label %25
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = call i64 @realloc(i8* %13, i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %12
%20 = load i64, i64* %5
%21 = trunc i64 %20 to i32
%22 = call i32 @QSlog(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %12
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %25
25: ; preds = %23, %9
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [42 x i8] c"Out of memory. Tried to grow to %d bytes\00"
define i8* @ILLutil_reallocrus(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @ILLutil_allocrus(i64 %1)
br label %13
6: ; preds = %2
%7 = tail call i64 @realloc(i8* %0, i64 %1)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = trunc i64 %1 to i32
%12 = tail call i32 @QSlog(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %6, %10, %4
%14 = phi i8* [ %5, %4 ], [ %8, %10 ], [ %8, %6 ]
ret i8* %14
}