#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 {
  long tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
void DelayMicrosecondsNoSleep(int delay_us) {
  long int start_time;
  long int time_difference;
  struct timespec gettime_now;
  clock_gettime(CLOCK_REALTIME, &gettime_now);
  start_time = gettime_now.tv_nsec;
  while (1) {
    clock_gettime(CLOCK_REALTIME, &gettime_now);
    time_difference = gettime_now.tv_nsec - start_time;
    if (time_difference < 0)
      time_difference += 1000000000;
    if (time_difference > (delay_us * 1000))
      break;
  }
}


x86 assembly (clang, -O0):
<DelayMicrosecondsNoSleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ebe(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    116c <DelayMicrosecondsNoSleep+0x5c>
mov    -0x18(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3e8,-0x4(%rbp),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jle    1188 <DelayMicrosecondsNoSleep+0x78>
jmp    118d <DelayMicrosecondsNoSleep+0x7d>
jmp    1135 <DelayMicrosecondsNoSleep+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DelayMicrosecondsNoSleep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    0x2eba(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%r12
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
mov    0x8(%rsp),%rbp
imul   $0x3e8,%r14d,%eax
movslq %eax,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edi
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
mov    0x8(%rsp),%rax
sub    %rbp,%rax
lea    0x3b9aca00(%rax),%rcx
test   %rax,%rax
cmovns %rax,%rcx
cmp    %rbx,%rcx
jle    1150 <DelayMicrosecondsNoSleep+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64 }
@CLOCK_REALTIME = global i32 0
define void @DelayMicrosecondsNoSleep(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.timespec
store i32 %0, i32* %2
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %5)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%9 = load i64, i64* %8
store i64 %9, i64* %3
br label %10
10: ; preds = %1, %29
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %5)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* %3
%16 = sub nsw i64 %14, %15
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %10
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 1000000000
store i64 %21, i64* %4
br label %22
22: ; preds = %19, %10
%23 = load i64, i64* %4
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, 1000
%26 = sext i32 %25 to i64
%27 = icmp sgt i64 %23, %26
br i1 %27, label %28, label %29
28: ; preds = %22
br label %30
29: ; preds = %22
br label %10
30: ; preds = %28
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64 }
@CLOCK_REALTIME = global i32 0
define void @DelayMicrosecondsNoSleep(i32 %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 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = mul nsw i32 %0, 1000
%9 = sext i32 %8 to i64
br label %10
10: ; preds = %10, %1
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %2)
%13 = load i64, i64* %6
%14 = sub nsw i64 %13, %7
%15 = icmp slt i64 %14, 0
%16 = add nsw i64 %14, 1000000000
%17 = select i1 %15, i64 %16, i64 %14
%18 = icmp sgt i64 %17, %9
br i1 %18, label %19, label %10
19: ; preds = %10
ret void
}