#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 */
unsigned long GpHClkGet();
int clockVal(void) {
  unsigned long hclk = GpHClkGet();
  unsigned long vclk = 0x98aeb8;
  int clkval = 0;
  while (hclk >= vclk) {
    clkval++;
    hclk -= vclk;
  }
  vclk >>= 2;
  if (hclk < vclk) {
    clkval--;
  }
  return clkval;
}


x86 assembly (clang, -O0):
<clockVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <GpHClkGet@plt>
mov    %rax,-0x8(%rbp)
movq   $0x98aeb8,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     115d <clockVal+0x4d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1132 <clockVal+0x22>
mov    -0x10(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1180 <clockVal+0x70>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clockVal>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <GpHClkGet@plt>
mov    %rax,%rcx
cmp    $0x98aeb8,%rax
jb     1151 <clockVal+0x41>
lea    -0x98aeb8(%rcx),%rax
movabs $0xd69d848491ee5ccd,%rdx
84 9d d6
mul    %rdx
shr    $0x17,%rdx
imul   $0xffffffffff675148,%rdx,%rax
lea    0x1(%rdx),%ebx
add    %rax,%rcx
add    $0xffffffffff675148,%rcx
cmp    $0x262bae,%rcx
sbb    $0x0,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @clockVal() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
%4 = call i64 (...) @GpHClkGet()
store i64 %4, i64* %1
store i64 10006200, i64* %2
store i32 0, i32* %3
br label %5
5: ; preds = %9, %0
%6 = load i64, i64* %1
%7 = load i64, i64* %2
%8 = icmp uge i64 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
%12 = load i64, i64* %2
%13 = load i64, i64* %1
%14 = sub i64 %13, %12
store i64 %14, i64* %1
br label %5
15: ; preds = %5
%16 = load i64, i64* %2
%17 = lshr i64 %16, 2
store i64 %17, i64* %2
%18 = load i64, i64* %1
%19 = load i64, i64* %2
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* %3
%23 = add nsw i32 %22, -1
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %15
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @clockVal() {
%1 = tail call i64 (...) @GpHClkGet()
%2 = icmp ugt i64 %1, 10006199
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = add i64 %1, -10006200
%5 = udiv i64 %4, 10006200
%6 = trunc i64 %5 to i32
%7 = mul i64 %5, -10006200
%8 = add i32 %6, 1
%9 = add i64 %7, %4
br label %10
10: ; preds = %3, %0
%11 = phi i64 [ %1, %0 ], [ %9, %3 ]
%12 = phi i32 [ 0, %0 ], [ %8, %3 ]
%13 = icmp ult i64 %11, 2501550
%14 = sext i1 %13 to i32
%15 = add nsw i32 %12, %14
ret i32 %15
}