#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 */
struct timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
void step_sleep(int us) {
  struct timespec loopstart;
  struct timespec loopstop;
  for (int i = 0; i < (us / 10); i++) {
    clock_gettime(CLOCK_REALTIME, &loopstart);
    clock_gettime(CLOCK_REALTIME, &loopstop);
    while (((loopstop.tv_sec - loopstart.tv_sec) +
            ((loopstop.tv_nsec - loopstart.tv_nsec) / 1e9)) < 0.00001) {
      clock_gettime(CLOCK_REALTIME, &loopstop);
    }
  }
}


x86 assembly (clang, -O0):
<step_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11c4 <step_sleep+0xb4>
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe88(%rip),%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm0,%xmm1
movsd  0xe70(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b1 <step_sleep+0xa1>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
jmp    1164 <step_sleep+0x54>
jmp    11b6 <step_sleep+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1122 <step_sleep+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<step_sleep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0xa,%edi
jl     11f8 <step_sleep+0xe8>
movslq %edi,%rax
imul   $0x66666667,%rax,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x22,%r15
add    %eax,%r15d
xor    %r12d,%r12d
mov    0x2e99(%rip),%rbp
lea    0x8(%rsp),%r14
mov    %rsp,%rbx
jmp    116d <step_sleep+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    %r15d,%r12d
je     11f8 <step_sleep+0xe8>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    0xc(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  0xe58(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
divsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe48(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1160 <step_sleep+0x50>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
movsd  0xe27(%rip),%xmm2
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    0xc(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
jmp    11b0 <step_sleep+0xa0>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
define void @step_sleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
br label %6
6: ; preds = %36, %1
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 10
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %39
11: ; preds = %6
%12 = load i32, i32* @CLOCK_REALTIME
%13 = call i32 @clock_gettime(i32 %12, %struct.timespec* %3)
%14 = load i32, i32* @CLOCK_REALTIME
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %4)
br label %16
16: ; preds = %32, %11
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sub nsw i32 %18, %20
%22 = sitofp i32 %21 to double
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%26 = load i32, i32* %25
%27 = sub nsw i32 %24, %26
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 1.000000e+09
%30 = fadd double %22, %29
%31 = fcmp olt double %30, 1.000000e-05
br i1 %31, label %32, label %35
32: ; preds = %16
%33 = load i32, i32* @CLOCK_REALTIME
%34 = call i32 @clock_gettime(i32 %33, %struct.timespec* %4)
br label %16
35: ; preds = %16
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %6
39: ; preds = %6
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
define void @step_sleep(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = sdiv i32 %0, 10
%7 = icmp sgt i32 %0, 9
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
br label %14
13: ; preds = %45, %1
ret void
14: ; preds = %8, %45
%15 = phi i32 [ 0, %8 ], [ %46, %45 ]
%16 = load i32, i32* @CLOCK_REALTIME
%17 = call i32 @clock_gettime(i32 %16, %struct.timespec* %2)
%18 = load i32, i32* @CLOCK_REALTIME
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %3)
%20 = load i32, i32* %9
%21 = load i32, i32* %10
%22 = sub nsw i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = sub nsw i32 %24, %25
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 1.000000e+09
%29 = fadd double %28, %23
%30 = fcmp olt double %29, 1.000000e-05
br i1 %30, label %31, label %45
31: ; preds = %14, %31
%32 = load i32, i32* @CLOCK_REALTIME
%33 = call i32 @clock_gettime(i32 %32, %struct.timespec* %3)
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = sub nsw i32 %34, %35
%37 = sitofp i32 %36 to double
%38 = load i32, i32* %11
%39 = load i32, i32* %12
%40 = sub nsw i32 %38, %39
%41 = sitofp i32 %40 to double
%42 = fdiv double %41, 1.000000e+09
%43 = fadd double %42, %37
%44 = fcmp olt double %43, 1.000000e-05
br i1 %44, label %31, label %45
45: ; preds = %31, %14
%46 = add nuw nsw i32 %15, 1
%47 = icmp eq i32 %46, %6
br i1 %47, label %13, label %14
}