#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*/ fatal_error(char *, size_t, void *);
scalar_t__ realloc(void *, size_t);
int /*<<< orphan*/ warning(char *);
void *renew(void *data, size_t size) {
  void *new_data;
  if (size == 0) {
    warning("renew: requested zero bytes of memory, continuing...\n");
    return NULL;
  }
  new_data = (void *)realloc(data, size);
  if (new_data == NULL)
    fatal_error("renew: could not reallocate %d byte block (0x%x)\n", size,
                data);
  return new_data;
}


x86 assembly (clang, -O0):
<renew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1164 <renew+0x34>
lea    0xeae(%rip),%rdi
call   1030 <warning@plt>
movq   $0x0,-0x8(%rbp)
jmp    119c <renew+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <renew+0x64>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xea7(%rip),%rdi
call   1040 <fatal_error@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<renew>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1161 <renew+0x31>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1170 <renew+0x40>
lea    0xee2(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <fatal_error@plt>
jmp    1170 <renew+0x40>
lea    0xe98(%rip),%rdi
call   1030 <warning@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [54 x i8] c"renew: requested zero bytes of memory, continuing...\0A\00"
@.str.1 = [50 x i8] c"renew: could not reallocate %d byte block (0x%x)\0A\00"
define i8* @renew(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 i64, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @warning(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %24
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i64 @realloc(i8* %12, i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i64, i64* %5
%20 = load i8*, i8** %4
%21 = call i32 @fatal_error(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i64 %19, i8* %20)
br label %22
22: ; preds = %18, %11
%23 = load i8*, i8** %6
store i8* %23, i8** %3
br label %24
24: ; preds = %22, %9
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [54 x i8] c"renew: requested zero bytes of memory, continuing...\0A\00"
@.str.1 = [50 x i8] c"renew: could not reallocate %d byte block (0x%x)\0A\00"
define i8* @renew(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @warning(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %12
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 %12
10: ; preds = %6
%11 = tail call i32 @fatal_error(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i64 %1, i8* %0)
br label %12
12: ; preds = %6, %10, %4
%13 = phi i8* [ null, %4 ], [ %8, %10 ], [ %8, %6 ]
ret i8* %13
}