#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 /*<<< orphan*/ tick_Delay10ms(int);
void busyWait(int t, void (*work)(void), int *f) {
  t >>= 6;
  if (t == 0)
    t = 1;
  while (t) {
    work();
    if (f)
      if (*f)
        return;
    tick_Delay10ms(1);
    --t;
  }
}


x86 assembly (clang, -O0):
<busyWait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    113d <busyWait+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    1142 <busyWait+0x32>
cmpl   $0x0,-0x4(%rbp)
je     1189 <busyWait+0x79>
call   *-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1171 <busyWait+0x61>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     116c <busyWait+0x5c>
jmp    1189 <busyWait+0x79>
jmp    1171 <busyWait+0x61>
mov    $0x1,%edi
call   1030 <tick_Delay10ms@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1142 <busyWait+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<busyWait>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%eax
sar    $0x6,%eax
cmp    $0x40,%edi
mov    $0x1,%ebp
cmovae %eax,%ebp
test   %ebp,%ebp
je     114c <busyWait+0x3c>
mov    %rdx,%rbx
mov    %rsi,%r14
jmp    113f <busyWait+0x2f>
mov    $0x1,%edi
call   1030 <tick_Delay10ms@plt>
add    $0xffffffff,%ebp
je     114c <busyWait+0x3c>
call   *%r14
test   %rbx,%rbx
je     1130 <busyWait+0x20>
cmpl   $0x0,(%rbx)
je     1130 <busyWait+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @busyWait(i32 %0, void ()* %1, i32* %2) {
%4 = alloca i32
%5 = alloca void ()*
%6 = alloca i32*
store i32 %0, i32* %4
store void ()* %1, void ()** %5
store i32* %2, i32** %6
%7 = load i32, i32* %4
%8 = ashr i32 %7, 6
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 1, i32* %4
br label %12
12: ; preds = %11, %3
br label %13
13: ; preds = %26, %12
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load void ()*, void ()** %5
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %30
25: ; preds = %20
br label %26
26: ; preds = %25, %16
%27 = call i32 @tick_Delay10ms(i32 1)
%28 = load i32, i32* %4
%29 = add nsw i32 %28, -1
store i32 %29, i32* %4
br label %13
30: ; preds = %24, %13
ret void
}

LLVM IR (-O2):
define void @busyWait(i32 %0, void ()* nocapture %1, i32* %2) {
%4 = ashr i32 %0, 6
%5 = icmp ult i32 %0, 64
%6 = select i1 %5, i32 1, i32 %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %3
%9 = icmp eq i32* %2, null
br label %10
10: ; preds = %8, %15
%11 = phi i32 [ %6, %8 ], [ %17, %15 ]
tail call void %1()
br i1 %9, label %15, label %12
12: ; preds = %10
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12, %10
%16 = tail call i32 @tick_Delay10ms(i32 1)
%17 = add nsw i32 %11, -1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %15, %12, %3
ret void
}