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


x86 assembly (clang, -O0):
<std_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x1,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118c <std_malloc+0x5c>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jle    116e <std_malloc+0x3e>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x11(%rbp),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,-0x11(%rbp)
movsbl %al,%eax
imul   $0x3e8,%eax,%edi
call   1050 <sleep@plt>
jmp    1140 <std_malloc+0x10>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<std_malloc>:
push   %rbx
mov    %rdi,%rbx
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x3e8,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x7d0,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0xbb8,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0xfa0,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x1388,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x1770,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x1b58,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x1f40,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x2328,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1238 <std_malloc+0x108>
mov    $0x2710,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
je     123a <std_malloc+0x10a>
pop    %rbx
ret
mov    $0xffffffff,%edi
call   1040 <exit@plt>

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

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