#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 */
typedef unsigned int useconds_t;

/* Variables and functions */
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(unsigned int);
int /*<<< orphan*/ usleep(unsigned int);
int main(void) {
  puts("5 x usleep(i++ * 500000)");
  for (unsigned i = 0; i < 5; i++) {
    useconds_t us = i * 500000u;
    usleep(us);
    puts("wake up");
  }
  puts("5 x sleep(i++)");
  for (unsigned i = 0; i < 5; i++) {
    sleep(i);
    puts("wake up");
  }
  puts("DONE");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jae    1188 <main+0x58>
imul   $0x7a120,-0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <usleep@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <main+0x22>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jae    11c7 <main+0x97>
mov    -0x10(%rbp),%edi
call   1040 <sleep@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119b <main+0x6b>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <usleep@plt>
lea    0xece(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0xf4240,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x16e360,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1e8480,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1040 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   1040 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x4,%edi
call   1040 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"5 x usleep(i++ * 500000)\00"
@.str.1 = [8 x i8] c"wake up\00"
@.str.2 = [15 x i8] c"5 x sleep(i++)\00"
@.str.3 = [5 x i8] c"DONE\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %2
%8 = icmp ult i32 %7, 5
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %2
%11 = mul i32 %10, 500000
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @usleep(i32 %12)
%14 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %9
%16 = load i32, i32* %2
%17 = add i32 %16, 1
store i32 %17, i32* %2
br label %6
18: ; preds = %6
%19 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %20
20: ; preds = %27, %18
%21 = load i32, i32* %4
%22 = icmp ult i32 %21, 5
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* %4
%25 = call i32 @sleep(i32 %24)
%26 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %23
%28 = load i32, i32* %4
%29 = add i32 %28, 1
store i32 %29, i32* %4
br label %20
30: ; preds = %20
%31 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"5 x usleep(i++ * 500000)\00"
@.str.1 = [8 x i8] c"wake up\00"
@.str.2 = [15 x i8] c"5 x sleep(i++)\00"
@.str.3 = [5 x i8] c"DONE\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @usleep(i32 0)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @usleep(i32 500000)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @usleep(i32 1000000)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @usleep(i32 1500000)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @usleep(i32 2000000)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @sleep(i32 0)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @sleep(i32 1)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @sleep(i32 2)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @sleep(i32 3)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @sleep(i32 4)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}