#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*/ free(void *);
void *realloc(void *, size_t);
int /*<<< orphan*/ sleep(int);
void *w_realloc(void *ptr, size_t size) {
  void *p;
  if (!size) {
    free(ptr);
    return NULL;
  }
  do {
    p = realloc(ptr, size);
    if (p == NULL)
      sleep(1);
  } while (!p);
  return p;
}


x86 assembly (clang, -O0):
<w_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <w_realloc+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ab <w_realloc+0x7b>
jmp    1166 <w_realloc+0x36>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118c <w_realloc+0x5c>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1191 <w_realloc+0x61>
cmpq   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1166 <w_realloc+0x36>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<w_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rsi,%rsi
je     115c <w_realloc+0x2c>
mov    %rsi,%rbx
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
jne    1166 <w_realloc+0x36>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1140 <w_realloc+0x10>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @w_realloc(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 ne i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @free(i8* %10)
store i8* null, i8** %3
br label %28
12: ; preds = %2
br label %13
13: ; preds = %22, %12
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = call i8* @realloc(i8* %14, i64 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @sleep(i32 1)
br label %21
21: ; preds = %19, %13
br label %22
22: ; preds = %21
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
%25 = xor i1 %24, true
br i1 %25, label %13, label %26
26: ; preds = %22
%27 = load i8*, i8** %6
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %9
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @w_realloc(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i8* @realloc(i8* %0, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %13
7: ; preds = %2
%8 = tail call i32 @free(i8* %0)
br label %13
9: ; preds = %4, %9
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i8* @realloc(i8* %0, i64 %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %9, label %13
13: ; preds = %9, %4, %7
%14 = phi i8* [ null, %7 ], [ %5, %4 ], [ %11, %9 ]
ret i8* %14
}