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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *);
int sleep(unsigned int);
unsigned int time(int /*<<< orphan*/ *);
int _sleep(char const *progname, unsigned int t) {
  time_t before;
  time_t after;
  int res;
  printf("%s: Testing sleep()\n", progname);
  before = time(NULL);
  res = sleep(t);
  after = time(NULL);
  if (res == 0)
    return (after - before == t) ? 0 : 64;
  return 0;
}


x86 assembly (clang, -O0):
<_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <sleep@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1199 <_sleep+0x69>
mov    -0x1c(%rbp),%edx
sub    -0x18(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x40,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <_sleep+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sleep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <sleep@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1040 <time@plt>
sub    %ebp,%eax
xor    %ecx,%ecx
cmp    %ebx,%eax
setne  %cl
shl    $0x6,%ecx
test   %r14d,%r14d
cmovne %r15d,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s: Testing sleep()\0A\00"
define i32 @_sleep(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 @time(i32* null)
store i32 %11, i32* %6
%12 = load i32, i32* %5
%13 = call i32 @sleep(i32 %12)
store i32 %13, i32* %8
%14 = call i32 @time(i32* null)
store i32 %14, i32* %7
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = sub i32 %18, %19
%21 = load i32, i32* %5
%22 = icmp eq i32 %20, %21
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 0, i32 64
store i32 %24, i32* %3
br label %26
25: ; preds = %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %17
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s: Testing sleep()\0A\00"
define i32 @_sleep(i8* %0, i32 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @sleep(i32 %1)
%6 = tail call i32 @time(i32* null)
%7 = icmp eq i32 %5, 0
%8 = sub i32 %6, %4
%9 = icmp eq i32 %8, %1
%10 = select i1 %9, i32 0, i32 64
%11 = select i1 %7, i32 %10, i32 0
ret i32 %11
}