#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ sleep_ms(int);
int /*<<< orphan*/ ts_less(struct timespec *, struct timespec *);
int ts_minus(struct timespec *, struct timespec *);
void busywait_until(struct timespec *tsp) {
  struct timespec ts;
  while (1) {
    clock_gettime(CLOCK_REALTIME, &ts);
    if (!ts_less(&ts, tsp))
      break;
    if (ts_minus(tsp, &ts) > 200)
      sleep_ms(100);
  }
}


x86 assembly (clang, -O0):
<busywait_until>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1060 <ts_less@plt>
cmp    $0x0,%eax
jne    1179 <busywait_until+0x39>
jmp    11a0 <busywait_until+0x60>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <ts_minus@plt>
cmp    $0xc8,%eax
jle    119b <busywait_until+0x5b>
mov    $0x64,%edi
call   1050 <sleep_ms@plt>
jmp    114c <busywait_until+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<busywait_until>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e8d(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <ts_less@plt>
test   %eax,%eax
je     11b8 <busywait_until+0x78>
lea    0x8(%rsp),%r14
jmp    119a <busywait_until+0x5a>
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <ts_less@plt>
test   %eax,%eax
je     11b8 <busywait_until+0x78>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <ts_minus@plt>
cmp    $0xc9,%eax
jl     1180 <busywait_until+0x40>
mov    $0x64,%edi
call   1050 <sleep_ms@plt>
jmp    1180 <busywait_until+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
define void @busywait_until(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %2
br label %4
4: ; preds = %1, %17
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %3)
%7 = load %struct.timespec*, %struct.timespec** %2
%8 = call i32 @ts_less(%struct.timespec* %3, %struct.timespec* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %4
br label %18
11: ; preds = %4
%12 = load %struct.timespec*, %struct.timespec** %2
%13 = call i32 @ts_minus(%struct.timespec* %12, %struct.timespec* %3)
%14 = icmp sgt i32 %13, 200
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @sleep_ms(i32 100)
br label %17
17: ; preds = %15, %11
br label %4
18: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
define void @busywait_until(%struct.timespec* %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = call i32 @ts_less(%struct.timespec* %2, %struct.timespec* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %1, %13
%9 = call i32 @ts_minus(%struct.timespec* %0, %struct.timespec* %2)
%10 = icmp sgt i32 %9, 200
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @sleep_ms(i32 100)
br label %13
13: ; preds = %11, %8
%14 = load i32, i32* @CLOCK_REALTIME
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %2)
%16 = call i32 @ts_less(%struct.timespec* %2, %struct.timespec* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %13, %1
ret void
}