#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*/ escape(void *);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, void *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main() {
  int i;
  srand(0);
  void *p = malloc(1);
  for (i = 0; i < 10000; ++i) {
    void *l = malloc(rand() % 1000);
    escape(l);
    usleep(100);
  }
  printf("malloc: %p\n", p);
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1050 <srand@plt>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    11e3 <main+0x73>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <escape@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x2b>
mov    -0x10(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <srand@plt>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x2710,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rdi
imul   $0x10624dd3,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdi
call   1070 <escape@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x20>
lea    0xe27(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"malloc: %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 @srand(i32 0)
%6 = call i8* @malloc(i32 1)
store i8* %6, i8** %3
store i32 0, i32* %2
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 10000
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 1000
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 @escape(i8* %14)
%16 = call i32 @usleep(i32 100)
br label %17
17: ; preds = %10
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %7
20: ; preds = %7
%21 = load i8*, i8** %3
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"malloc: %p\0A\00"
define i32 @main() {
%1 = tail call i32 @srand(i32 0)
%2 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %10, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 1000
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @escape(i8* %7)
%9 = tail call i32 @usleep(i32 100)
%10 = add nuw nsw i32 %4, 1
%11 = icmp eq i32 %10, 10000
br i1 %11, label %12, label %3
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%14 = tail call i32 @free(i8* %2)
ret i32 0
}