#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 int time_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ printf(char *, int);
int sleep(int);
int time(int /*<<< orphan*/);
int usleep(int);
int main() {
  time_t start;
  time_t taken;
  start = time(0);
  printf("sleep(2) ret: %d\n", sleep(2));
  taken = time(0) - start;
  printf("after sleep(2) between 2 and 3: %d\n", taken >= 2 && taken <= 3);
  printf("errno: %d\n", errno);
  errno = 0;
  start = time(0);
  printf("usleep(3000000) ret: %d\n", usleep(3000000));
  taken = time(0) - start;
  printf("after usleep(3000000) between 3 and 4: %d\n",
         taken >= 3 && taken <= 4);
  printf("errno: %d\n", errno);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,-0x8(%rbp)
mov    $0x2,%edi
call   1050 <sleep@plt>
mov    %eax,%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <time@plt>
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jl     1197 <main+0x57>
cmpl   $0x3,-0xc(%rbp)
setle  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%esi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e19(%rip),%rax
movl   $0x0,(%rax)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,-0x8(%rbp)
mov    $0x2dc6c0,%edi
call   1060 <usleep@plt>
mov    %eax,%esi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <time@plt>
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0xc(%rbp)
mov    %al,-0xe(%rbp)
jl     1215 <main+0xd5>
cmpl   $0x4,-0xc(%rbp)
setle  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
and    $0x1,%al
movzbl %al,%esi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1050 <sleep@plt>
lea    0xea2(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <time@plt>
sub    %ebx,%eax
and    $0xfffffffe,%eax
xor    %esi,%esi
cmp    $0x2,%eax
sete   %sil
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e53(%rip),%rbx
mov    (%rbx),%esi
lea    0xea0(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x0,(%rbx)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
mov    $0x2dc6c0,%edi
call   1060 <usleep@plt>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <time@plt>
sub    %ebp,%eax
add    $0xfffffffd,%eax
xor    %esi,%esi
cmp    $0x2,%eax
setb   %sil
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"sleep(2) ret: %d\0A\00"
@.str.1 = [36 x i8] c"after sleep(2) between 2 and 3: %d\0A\00"
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"usleep(3000000) ret: %d\0A\00"
@.str.4 = [43 x i8] c"after usleep(3000000) between 3 and 4: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @time(i32 0)
store i32 %4, i32* %2
%5 = call i32 @sleep(i32 2)
%6 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @time(i32 0)
%8 = load i32, i32* %2
%9 = sub nsw i32 %7, %8
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 3
br label %15
15: ; preds = %12, %0
%16 = phi i1 [ false, %0 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @errno
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 0, i32* @errno
%21 = call i32 @time(i32 0)
store i32 %21, i32* %2
%22 = call i32 @usleep(i32 3000000)
%23 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @time(i32 0)
%25 = load i32, i32* %2
%26 = sub nsw i32 %24, %25
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp sge i32 %27, 3
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = load i32, i32* %3
%31 = icmp sle i32 %30, 4
br label %32
32: ; preds = %29, %15
%33 = phi i1 [ false, %15 ], [ %31, %29 ]
%34 = zext i1 %33 to i32
%35 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @errno
%37 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"sleep(2) ret: %d\0A\00"
@.str.1 = [36 x i8] c"after sleep(2) between 2 and 3: %d\0A\00"
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"usleep(3000000) ret: %d\0A\00"
@.str.4 = [43 x i8] c"after usleep(3000000) between 3 and 4: %d\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32 0)
%2 = tail call i32 @sleep(i32 2)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 @time(i32 0)
%5 = sub nsw i32 %4, %1
%6 = and i32 %5, -2
%7 = icmp eq i32 %6, 2
%8 = zext i1 %7 to i32
%9 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %10)
store i32 0, i32* @errno
%12 = tail call i32 @time(i32 0)
%13 = tail call i32 @usleep(i32 3000000)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i32 @time(i32 0)
%16 = sub i32 -3, %12
%17 = add i32 %16, %15
%18 = icmp ult i32 %17, 2
%19 = zext i1 %18 to i32
%20 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @errno
%22 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret i32 0
}