#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 double clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
double clock();
int sleeptest(unsigned long x) {
  clock_t c1 = clock(), c2;
  do {
    if ((c2 = clock()) == (clock_t)-1)
      return 0;
  } while (1000.0 * (c2 - c1) / CLOCKS_PER_SEC < x);
  return 1;
}


x86 assembly (clang, -O0):
<sleeptest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xec4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1158 <sleeptest+0x48>
jp     1158 <sleeptest+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11be <sleeptest+0xae>
jmp    115d <sleeptest+0x4d>
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe95(%rip),%xmm0
mulsd  %xmm0,%xmm1
mov    0x2e6a(%rip),%rax
movsd  (%rax),%xmm0
divsd  %xmm0,%xmm1
movaps 0xe83(%rip),%xmm2
movq   -0x10(%rbp),%xmm0
punpckldq %xmm2,%xmm0
movapd 0xe82(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1128 <sleeptest+0x18>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleeptest>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <clock@plt>
movq   %rbx,%xmm1
punpckldq 0xed1(%rip),%xmm1
movsd  %xmm0,0x8(%rsp)
subpd  0xed3(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
mov    0x2e92(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <clock@plt>
ucomisd 0xeb1(%rip),%xmm0
jne    1173 <sleeptest+0x63>
jnp    1196 <sleeptest+0x86>
subsd  0x8(%rsp),%xmm0
mulsd  0xea7(%rip),%xmm0
divsd  (%rbx),%xmm0
movapd 0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1160 <sleeptest+0x50>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @sleeptest(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca double
%5 = alloca double
store i64 %0, i64* %3
%6 = call double (...) @clock()
store double %6, double* %4
br label %7
7: ; preds = %12, %1
%8 = call double (...) @clock()
store double %8, double* %5
%9 = fcmp oeq double %8, -1.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 0, i32* %2
br label %23
11: ; preds = %7
br label %12
12: ; preds = %11
%13 = load double, double* %5
%14 = load double, double* %4
%15 = fsub double %13, %14
%16 = fmul double 1.000000e+03, %15
%17 = load double, double* @CLOCKS_PER_SEC
%18 = fdiv double %16, %17
%19 = load i64, i64* %3
%20 = uitofp i64 %19 to double
%21 = fcmp olt double %18, %20
br i1 %21, label %7, label %22
22: ; preds = %12
store i32 1, i32* %2
br label %23
23: ; preds = %22, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @sleeptest(i64 %0) {
%2 = tail call double (...) @clock()
%3 = uitofp i64 %0 to double
br label %4
4: ; preds = %7, %1
%5 = tail call double (...) @clock()
%6 = fcmp oeq double %5, -1.000000e+00
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = fsub double %5, %2
%9 = fmul double %8, 1.000000e+03
%10 = load double, double* @CLOCKS_PER_SEC
%11 = fdiv double %9, %10
%12 = fcmp olt double %11, %3
br i1 %12, label %4, label %13
13: ; preds = %7, %4
%14 = phi i32 [ 0, %4 ], [ 1, %7 ]
ret i32 %14
}