#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int uint32_t;
struct TYPE_3__ {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_4__ {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct itimerval {
  TYPE_1__ it_interval;
  TYPE_2__ it_value;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ setitimer(int /*<<< orphan*/, struct itimerval *,
                             struct itimerval *);
uint32_t hertz(void) {
  struct itimerval tim;
  tim.it_interval.tv_sec = 0;
  tim.it_interval.tv_usec = 1;
  tim.it_value.tv_sec = 0;
  tim.it_value.tv_usec = 0;
  setitimer(ITIMER_REAL, &tim, 0);
  setitimer(ITIMER_REAL, 0, &tim);
  if (tim.it_interval.tv_usec < 2)
    return (0);
  return (1000000 / tim.it_interval.tv_usec);
}


x86 assembly (clang, -O0):
<hertz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <setitimer@plt>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
call   1030 <setitimer@plt>
cmpl   $0x2,-0x28(%rbp)
jge    1179 <hertz+0x69>
movl   $0x0,-0x4(%rbp)
jmp    1185 <hertz+0x75>
mov    $0xf4240,%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hertz>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
movl   $0x1,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x2ea8(%rip),%r15
mov    (%r15),%edi
xor    %ebx,%ebx
mov    %rsp,%r14
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <setitimer@plt>
mov    (%r15),%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <setitimer@plt>
mov    (%rsp),%ecx
cmp    $0x2,%ecx
jl     116a <hertz+0x5a>
mov    $0xf4240,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_3__, %struct.TYPE_4__ }
%struct.TYPE_3__ = type { i32, i64 }
%struct.TYPE_4__ = type { i64, i64 }
@ITIMER_REAL = global i32 0
define i32 @hertz() {
%1 = alloca i32
%2 = alloca %struct.itimerval
%3 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i32 0, i32 0
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i32 0, i32 0
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
store i32 1, i32* %6
%7 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i32 0, i32 1
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 1
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i32 0, i32 1
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %9, i32 0, i32 0
store i64 0, i64* %10
%11 = load i32, i32* @ITIMER_REAL
%12 = call i32 @setitimer(i32 %11, %struct.itimerval* %2, %struct.itimerval* null)
%13 = load i32, i32* @ITIMER_REAL
%14 = call i32 @setitimer(i32 %13, %struct.itimerval* null, %struct.itimerval* %2)
%15 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %0
store i32 0, i32* %1
br label %25
20: ; preds = %0
%21 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sdiv i32 1000000, %23
store i32 %24, i32* %1
br label %25
25: ; preds = %20, %19
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_3__, %struct.TYPE_4__ }
%struct.TYPE_3__ = type { i32, i64 }
%struct.TYPE_4__ = type { i64, i64 }
@ITIMER_REAL = global i32 0
define i32 @hertz() {
%1 = alloca %struct.itimerval
%2 = bitcast %struct.itimerval* %1 to i8*
%3 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %1, i64 0, i32 0, i32 1
store i64 0, i64* %3
%4 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %1, i64 0, i32 0, i32 0
store i32 1, i32* %4
%5 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %1, i64 0, i32 1, i32 0
%6 = bitcast i64* %5 to i8*
%7 = load i32, i32* @ITIMER_REAL
%8 = call i32 @setitimer(i32 %7, %struct.itimerval* %1, %struct.itimerval* null)
%9 = load i32, i32* @ITIMER_REAL
%10 = call i32 @setitimer(i32 %9, %struct.itimerval* null, %struct.itimerval* %1)
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = udiv i32 1000000, %11
br label %15
15: ; preds = %0, %13
%16 = phi i32 [ %14, %13 ], [ 0, %0 ]
ret i32 %16
}