void waitSubTick(unsigned long subtick) {
  unsigned long start;
  unsigned long current;
  unsigned long i;
  if (SYS_getInterruptMaskLevel() >= 6) {
    i = subtick;
    while (i--) {
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
    }
    return;
  }
  start = getSubTick();
  do {
    current = getSubTick();
    if (current < start)
      current = start;
  } while ((current - start) < subtick);
}


x86 assembly (clang, -O0):
<waitSubTick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <SYS_getInterruptMaskLevel@plt>
cmp    $0x6,%eax
jl     116b <waitSubTick+0x4b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     1166 <waitSubTick+0x46>
nop
nop
nop
nop
jmp    1144 <waitSubTick+0x24>
jmp    11b2 <waitSubTick+0x92>
mov    $0x0,%al
call   1040 <getSubTick@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getSubTick@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    119b <waitSubTick+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11a0 <waitSubTick+0x80>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1178 <waitSubTick+0x58>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitSubTick>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <SYS_getInterruptMaskLevel@plt>
cmp    $0x6,%eax
jl     114c <waitSubTick+0x2c>
test   %r14,%r14
je     1176 <waitSubTick+0x56>
nopl   0x0(%rax,%rax,1)
nop
nop
nop
nop
add    $0xffffffffffffffff,%r14
jne    1140 <waitSubTick+0x20>
jmp    1176 <waitSubTick+0x56>
xor    %eax,%eax
call   1040 <getSubTick@plt>
movslq %eax,%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getSubTick@plt>
cmp    %ebx,%eax
cmovbe %ebx,%eax
cltq
sub    %rbx,%rax
cmp    %r14,%rax
jb     1160 <waitSubTick+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @waitSubTick(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
%6 = call i32 (...) @SYS_getInterruptMaskLevel()
%7 = icmp sge i32 %6, 6
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = load i64, i64* %2
store i64 %9, i64* %5
br label %10
10: ; preds = %14, %8
%11 = load i64, i64* %5
%12 = add i64 %11, -1
store i64 %12, i64* %5
%13 = icmp ne i64 %11, 0
br i1 %13, label %14, label %15
14: ; preds = %10
br label %10
15: ; preds = %10
br label %34
16: ; preds = %1
%17 = call i32 (...) @getSubTick()
%18 = sext i32 %17 to i64
store i64 %18, i64* %3
br label %19
19: ; preds = %28, %16
%20 = call i32 (...) @getSubTick()
%21 = sext i32 %20 to i64
store i64 %21, i64* %4
%22 = load i64, i64* %4
%23 = load i64, i64* %3
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i64, i64* %3
store i64 %26, i64* %4
br label %27
27: ; preds = %25, %19
br label %28
28: ; preds = %27
%29 = load i64, i64* %4
%30 = load i64, i64* %3
%31 = sub i64 %29, %30
%32 = load i64, i64* %2
%33 = icmp ult i64 %31, %32
br i1 %33, label %19, label %34
34: ; preds = %15, %28
ret void
}

LLVM IR (-O2):
define void @waitSubTick(i64 %0) {
%2 = tail call i32 (...) @SYS_getInterruptMaskLevel()
%3 = icmp sgt i32 %2, 5
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = icmp eq i64 %0, 0
br i1 %5, label %20, label %6
6: ; preds = %4, %6
%7 = phi i64 [ %8, %6 ], [ %0, %4 ]
%8 = add i64 %7, -1
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %6
10: ; preds = %1
%11 = tail call i32 (...) @getSubTick()
%12 = sext i32 %11 to i64
br label %13
13: ; preds = %13, %10
%14 = tail call i32 (...) @getSubTick()
%15 = icmp ugt i32 %14, %11
%16 = select i1 %15, i32 %14, i32 %11
%17 = sext i32 %16 to i64
%18 = sub nsw i64 %17, %12
%19 = icmp ult i64 %18, %0
br i1 %19, label %13, label %20
20: ; preds = %13, %6, %4
ret void
}