void my_unap(microsecs) unsigned long long microsecs;
{
  double timein, timeout;
  unsigned long usecs;
  usecs = (unsigned long)microsecs;
  usecs = (usecs / 1000) * 1000;
  timein = time_so_far1();
  usleep(usecs);
  while (1) {
    timeout = time_so_far1();
    if (timeout - timein > microsecs)
      break;
  }
}


x86 assembly (clang, -O0):
<my_unap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
imul   $0x3e8,%rax,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <time_so_far1@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <usleep@plt>
xor    %eax,%eax
call   1030 <time_so_far1@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movaps 0xe73(%rip),%xmm2
movq   -0x8(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe72(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11bc <my_unap+0x9c>
jmp    11c1 <my_unap+0xa1>
jmp    1168 <my_unap+0x48>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_unap>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%r14
xor    %eax,%eax
call   1030 <time_so_far1@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <usleep@plt>
movq   %rbx,%xmm0
punpckldq 0xe8f(%rip),%xmm0
subpd  0xe97(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <time_so_far1@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  0x8(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    1190 <my_unap+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @my_unap(i64 %0) {
%2 = alloca i64
%3 = alloca double
%4 = alloca double
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
store i64 %6, i64* %5
%7 = load i64, i64* %5
%8 = udiv i64 %7, 1000
%9 = mul i64 %8, 1000
store i64 %9, i64* %5
%10 = call i32 (...) @time_so_far1()
%11 = sitofp i32 %10 to double
store double %11, double* %3
%12 = load i64, i64* %5
%13 = call i32 (i64, ...) bitcast (i32 (...)* @usleep to i32 (i64, ...)*)(i64 %12)
br label %14
14: ; preds = %1, %24
%15 = call i32 (...) @time_so_far1()
%16 = sitofp i32 %15 to double
store double %16, double* %4
%17 = load double, double* %4
%18 = load double, double* %3
%19 = fsub double %17, %18
%20 = load i64, i64* %2
%21 = uitofp i64 %20 to double
%22 = fcmp ogt double %19, %21
br i1 %22, label %23, label %24
23: ; preds = %14
br label %25
24: ; preds = %14
br label %14
25: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @my_unap(i64 %0) {
%2 = urem i64 %0, 1000
%3 = sub i64 %0, %2
%4 = tail call i32 (...) @time_so_far1()
%5 = sitofp i32 %4 to double
%6 = tail call i32 (i64, ...) bitcast (i32 (...)* @usleep to i32 (i64, ...)*)(i64 %3)
%7 = uitofp i64 %0 to double
br label %8
8: ; preds = %8, %1
%9 = tail call i32 (...) @time_so_far1()
%10 = sitofp i32 %9 to double
%11 = fsub double %10, %5
%12 = fcmp ogt double %11, %7
br i1 %12, label %13, label %8
13: ; preds = %8
ret void
}