#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*/ wgmem_error(char *, ...);
extern void *wg_realloc(void *ptr, size_t size) {
  void *result;
  if (!size) {
    wgmem_error("Error reallocing 0 bytes.\n");
  }
  result = realloc(ptr, size);
  if (!result) {
    wgmem_error("Error while reallocing %u bytes.\n", size);
  }
  return (result);
}


x86 assembly (clang, -O0):
<wg_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <wg_realloc+0x29>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <wgmem_error@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <wg_realloc+0x57>
mov    -0x10(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <wgmem_error@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wg_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
jne    113d <wg_realloc+0x1d>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1030 <wgmem_error@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1161 <wg_realloc+0x41>
lea    0xec4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <wgmem_error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Error reallocing 0 bytes.\0A\00"
@.str.1 = [34 x i8] c"Error while reallocing %u bytes.\0A\00"
define i8* @wg_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 i64, i64* %4
%7 = icmp ne i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = call i8* @realloc(i8* %11, i64 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i64, i64* %4
%18 = call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 %17)
br label %19
19: ; preds = %16, %10
%20 = load i8*, i8** %5
ret i8* %20
}

LLVM IR (-O2):
@.str = [27 x i8] c"Error reallocing 0 bytes.\0A\00"
@.str.1 = [34 x i8] c"Error while reallocing %u bytes.\0A\00"
define noalias i8* @wg_realloc(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = tail call i8* @realloc(i8* %0, i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 %1)
br label %11
11: ; preds = %9, %6
ret i8* %7
}