#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 */
float IRTC_RATE();
long _rtc();
void _glio_delay(int nano) {
  float hertz;
  long ticks, start;
  hertz = IRTC_RATE();
  ticks = hertz * (float)nano / 1000000000.0;
  start = _rtc();
  while (_rtc() < (start + ticks) && _rtc() >= start)
    continue;
  return;
}


x86 assembly (clang, -O0):
<_glio_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <IRTC_RATE@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x4(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeaf(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <_rtc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <_rtc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rdx
add    -0x10(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x19(%rbp)
jge    119a <_glio_delay+0x7a>
mov    $0x0,%al
call   1040 <_rtc@plt>
cmp    -0x18(%rbp),%rax
setge  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11aa <_glio_delay+0x8a>
jmp    11af <_glio_delay+0x8f>
jmp    1169 <_glio_delay+0x49>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_glio_delay>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <IRTC_RATE@plt>
cvtsi2ss %ebx,%xmm1
mulss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
divsd  0xebc(%rip),%xmm0
cvttsd2si %xmm0,%r14
xor    %eax,%eax
call   1040 <_rtc@plt>
mov    %rax,%rbx
add    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <_rtc@plt>
cmp    %r14,%rax
jge    1178 <_glio_delay+0x58>
xor    %eax,%eax
call   1040 <_rtc@plt>
cmp    %rbx,%rax
jge    1160 <_glio_delay+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @_glio_delay(i32 %0) {
%2 = alloca i32
%3 = alloca float
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
%6 = call float (...) @IRTC_RATE()
store float %6, float* %3
%7 = load float, float* %3
%8 = load i32, i32* %2
%9 = sitofp i32 %8 to float
%10 = fmul float %7, %9
%11 = fpext float %10 to double
%12 = fdiv double %11, 1.000000e+09
%13 = fptosi double %12 to i64
store i64 %13, i64* %4
%14 = call i64 (...) @_rtc()
store i64 %14, i64* %5
br label %15
15: ; preds = %27, %1
%16 = call i64 (...) @_rtc()
%17 = load i64, i64* %5
%18 = load i64, i64* %4
%19 = add nsw i64 %17, %18
%20 = icmp slt i64 %16, %19
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = call i64 (...) @_rtc()
%23 = load i64, i64* %5
%24 = icmp sge i64 %22, %23
br label %25
25: ; preds = %21, %15
%26 = phi i1 [ false, %15 ], [ %24, %21 ]
br i1 %26, label %27, label %28
27: ; preds = %25
br label %15
28: ; preds = %25
ret void
}

LLVM IR (-O2):
define void @_glio_delay(i32 %0) {
%2 = tail call float (...) @IRTC_RATE()
%3 = sitofp i32 %0 to float
%4 = fmul float %2, %3
%5 = fpext float %4 to double
%6 = fdiv double %5, 1.000000e+09
%7 = fptosi double %6 to i64
%8 = tail call i64 (...) @_rtc()
%9 = add nsw i64 %8, %7
br label %10
10: ; preds = %13, %1
%11 = tail call i64 (...) @_rtc()
%12 = icmp slt i64 %11, %9
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i64 (...) @_rtc()
%15 = icmp slt i64 %14, %8
br i1 %15, label %16, label %10
16: ; preds = %10, %13
ret void
}