#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 */
typedef scalar_t__ uint64_t;
typedef int uint32_t;

/* Variables and functions */
scalar_t__ monotonic_nseconds();
scalar_t__ monotonic_useconds();
uint32_t monotonic_speed(void) {
  uint32_t i;
  uint64_t st, en;
  i = 0;
  st = monotonic_useconds();
  do {
    en = monotonic_nseconds();
  } while (en == st);
  st = monotonic_useconds() + 1000000;
  do {
    en = monotonic_useconds();
    i++;
  } while (en < st);
  return i / 100;
}


x86 assembly (clang, -O0):
<monotonic_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <monotonic_useconds@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <monotonic_nseconds@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     113a <monotonic_speed+0x1a>
mov    $0x0,%al
call   1040 <monotonic_useconds@plt>
add    $0xf4240,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <monotonic_useconds@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jl     1164 <monotonic_speed+0x44>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monotonic_speed>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <monotonic_useconds@plt>
mov    %rax,%rbx
nopl   (%rax)
xor    %eax,%eax
call   1030 <monotonic_nseconds@plt>
cmp    %rbx,%rax
je     1130 <monotonic_speed+0x10>
xor    %eax,%eax
call   1040 <monotonic_useconds@plt>
mov    %rax,%rbx
add    $0xf4240,%rbx
xor    %ebp,%ebp
nop
xor    %eax,%eax
call   1040 <monotonic_useconds@plt>
add    $0x1,%ebp
cmp    %rbx,%rax
jl     1150 <monotonic_speed+0x30>
mov    %ebp,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @monotonic_speed() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @monotonic_useconds()
store i64 %4, i64* %2
br label %5
5: ; preds = %7, %0
%6 = call i64 (...) @monotonic_nseconds()
store i64 %6, i64* %3
br label %7
7: ; preds = %5
%8 = load i64, i64* %3
%9 = load i64, i64* %2
%10 = icmp eq i64 %8, %9
br i1 %10, label %5, label %11
11: ; preds = %7
%12 = call i64 (...) @monotonic_useconds()
%13 = add nsw i64 %12, 1000000
store i64 %13, i64* %2
br label %14
14: ; preds = %18, %11
%15 = call i64 (...) @monotonic_useconds()
store i64 %15, i64* %3
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %18
18: ; preds = %14
%19 = load i64, i64* %3
%20 = load i64, i64* %2
%21 = icmp slt i64 %19, %20
br i1 %21, label %14, label %22
22: ; preds = %18
%23 = load i32, i32* %1
%24 = sdiv i32 %23, 100
ret i32 %24
}

LLVM IR (-O2):
define i32 @monotonic_speed() {
%1 = tail call i64 (...) @monotonic_useconds()
br label %2
2: ; preds = %2, %0
%3 = tail call i64 (...) @monotonic_nseconds()
%4 = icmp eq i64 %3, %1
br i1 %4, label %2, label %5
5: ; preds = %2
%6 = tail call i64 (...) @monotonic_useconds()
%7 = add nsw i64 %6, 1000000
br label %8
8: ; preds = %8, %5
%9 = phi i32 [ 0, %5 ], [ %11, %8 ]
%10 = tail call i64 (...) @monotonic_useconds()
%11 = add nuw nsw i32 %9, 1
%12 = icmp slt i64 %10, %7
br i1 %12, label %8, label %13
13: ; preds = %8
%14 = udiv i32 %11, 100
ret i32 %14
}