#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*/ getchar();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(unsigned int);
int /*<<< orphan*/ usleep(unsigned int);
int main(void) {
  puts("Please hit any key and then ENTER to continue");
  getchar();
  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    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jae    11ab <main+0x6b>
imul   $0x7a120,-0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <usleep@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1175 <main+0x35>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jae    11ea <main+0xaa>
mov    -0x10(%rbp),%edi
call   1050 <sleep@plt>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11be <main+0x7e>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <usleep@plt>
lea    0xed9(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0xf4240,%edi
call   1060 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x16e360,%edi
call   1060 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1e8480,%edi
call   1060 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x4,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Please hit any key and then ENTER to continue\00"
@.str.1 = [25 x i8] c"5 x usleep(i++ * 500000)\00"
@.str.2 = [8 x i8] c"wake up\00"
@.str.3 = [15 x i8] c"5 x sleep(i++)\00"
@.str.4 = [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 ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @getchar()
%7 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %2
%10 = icmp ult i32 %9, 5
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %2
%13 = mul i32 %12, 500000
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @usleep(i32 %14)
%16 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %11
%18 = load i32, i32* %2
%19 = add i32 %18, 1
store i32 %19, i32* %2
br label %8
20: ; preds = %8
%21 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %22
22: ; preds = %29, %20
%23 = load i32, i32* %4
%24 = icmp ult i32 %23, 5
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %4
%27 = call i32 @sleep(i32 %26)
%28 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %25
%30 = load i32, i32* %4
%31 = add i32 %30, 1
store i32 %31, i32* %4
br label %22
32: ; preds = %22
%33 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

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