#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 */

/* Variables and functions */
int SYS_getInterruptMaskLevel();
unsigned long getTick();
int /*<<< orphan*/ waitSubTick(int);
void waitTick(unsigned long tick) {
  unsigned long start;
  unsigned long i;
  if (SYS_getInterruptMaskLevel() >= 6) {
    i = tick;
    while (i--)
      waitSubTick(256);
    return;
  }
  start = getTick();
  while ((getTick() - start) < tick)
    ;
}


x86 assembly (clang, -O0):
<waitTick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <SYS_getInterruptMaskLevel@plt>
cmp    $0x6,%eax
jl     1181 <waitTick+0x51>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     117c <waitTick+0x4c>
mov    $0x100,%edi
call   1040 <waitSubTick@plt>
jmp    1154 <waitTick+0x24>
jmp    11a6 <waitTick+0x76>
mov    $0x0,%al
call   1050 <getTick@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getTick@plt>
sub    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11a6 <waitTick+0x76>
jmp    118c <waitTick+0x5c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitTick>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <SYS_getInterruptMaskLevel@plt>
cmp    $0x6,%eax
jl     1162 <waitTick+0x32>
test   %rbx,%rbx
je     117f <waitTick+0x4f>
nopl   0x0(%rax,%rax,1)
mov    $0x100,%edi
call   1040 <waitSubTick@plt>
add    $0xffffffffffffffff,%rbx
jne    1150 <waitTick+0x20>
jmp    117f <waitTick+0x4f>
xor    %eax,%eax
call   1050 <getTick@plt>
mov    %rax,%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getTick@plt>
sub    %r14,%rax
cmp    %rbx,%rax
jb     1170 <waitTick+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @waitTick(i64 %0) {
%2 = tail call i32 (...) @SYS_getInterruptMaskLevel()
%3 = icmp sgt i32 %2, 5
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = icmp eq i64 %0, 0
br i1 %5, label %17, label %6
6: ; preds = %4, %6
%7 = phi i64 [ %8, %6 ], [ %0, %4 ]
%8 = add i64 %7, -1
%9 = tail call i32 @waitSubTick(i32 256)
%10 = icmp eq i64 %8, 0
br i1 %10, label %17, label %6
11: ; preds = %1
%12 = tail call i64 (...) @getTick()
br label %13
13: ; preds = %13, %11
%14 = tail call i64 (...) @getTick()
%15 = sub i64 %14, %12
%16 = icmp ult i64 %15, %0
br i1 %16, label %13, label %17
17: ; preds = %13, %6, %4
ret void
}