#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*/ exit(int);
void *realloc(void *, size_t);
int /*<<< orphan*/ sleep(int);
void *std_realloc(void *ptr, size_t newsize) {
  void *mem;
  char inter_multi = 1;
  while ((mem = realloc(ptr, newsize)) == NULL) {
    if (inter_multi > 10)
      exit(-1);
    sleep(1000 * inter_multi++);
  }
  return mem;
}


x86 assembly (clang, -O0):
<std_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x1,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1194 <std_realloc+0x64>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jle    1176 <std_realloc+0x46>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x19(%rbp),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,-0x19(%rbp)
movsbl %al,%eax
imul   $0x3e8,%eax,%edi
call   1050 <sleep@plt>
jmp    1144 <std_realloc+0x14>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<std_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x3e8,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x7d0,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0xbb8,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0xfa0,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x1388,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x1770,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x1b58,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x1f40,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x2328,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
jne    1260 <std_realloc+0x130>
mov    $0x2710,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     1268 <std_realloc+0x138>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define i8* @std_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
store i8 1, i8* %6
br label %7
7: ; preds = %18, %2
%8 = load i8*, i8** %3
%9 = load i64, i64* %4
%10 = call i8* @realloc(i8* %8, i64 %9)
store i8* %10, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 10
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %12
%19 = load i8, i8* %6
%20 = add i8 %19, 1
store i8 %20, i8* %6
%21 = sext i8 %19 to i32
%22 = mul nsw i32 1000, %21
%23 = call i32 @sleep(i32 %22)
br label %7
24: ; preds = %7
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
define noalias i8* @std_realloc(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 %47
5: ; preds = %2
%6 = tail call i32 @sleep(i32 1000)
%7 = tail call i8* @realloc(i8* %0, i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %47
9: ; preds = %43
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %5
%12 = tail call i32 @sleep(i32 2000)
%13 = tail call i8* @realloc(i8* %0, i64 %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %47
15: ; preds = %11
%16 = tail call i32 @sleep(i32 3000)
%17 = tail call i8* @realloc(i8* %0, i64 %1)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %47
19: ; preds = %15
%20 = tail call i32 @sleep(i32 4000)
%21 = tail call i8* @realloc(i8* %0, i64 %1)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %47
23: ; preds = %19
%24 = tail call i32 @sleep(i32 5000)
%25 = tail call i8* @realloc(i8* %0, i64 %1)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %47
27: ; preds = %23
%28 = tail call i32 @sleep(i32 6000)
%29 = tail call i8* @realloc(i8* %0, i64 %1)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = tail call i32 @sleep(i32 7000)
%33 = tail call i8* @realloc(i8* %0, i64 %1)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %47
35: ; preds = %31
%36 = tail call i32 @sleep(i32 8000)
%37 = tail call i8* @realloc(i8* %0, i64 %1)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = tail call i32 @sleep(i32 9000)
%41 = tail call i8* @realloc(i8* %0, i64 %1)
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = tail call i32 @sleep(i32 10000)
%45 = tail call i8* @realloc(i8* %0, i64 %1)
%46 = icmp eq i8* %45, null
br i1 %46, label %9, label %47
47: ; preds = %5, %11, %15, %19, %23, %27, %31, %35, %39, %43, %2
%48 = phi i8* [ %3, %2 ], [ %7, %5 ], [ %13, %11 ], [ %17, %15 ], [ %21, %19 ], [ %25, %23 ], [ %29, %27 ], [ %33, %31 ], [ %37, %35 ], [ %41, %39 ], [ %45, %43 ]
ret i8* %48
}