#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__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int check_clock(void) {
  static clock_t lastClock = 0;
  static double sDelay = 30.0 / 1000.0;
  int iret = 0;
  clock_t currClock;
  double duration;
  if (lastClock == 0)
    lastClock = clock();
  currClock = clock();
  duration = (double)(currClock - lastClock) / CLOCKS_PER_SEC;
  if (duration > sDelay) {
    iret = 1;
    lastClock = currClock;
  }
  return iret;
}


x86 assembly (clang, -O0):
<check_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
cmpq   $0x0,0x2f11(%rip)
jne    113b <check_clock+0x2b>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,0x2efd(%rip)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    0x2ee7(%rip),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e8b(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd 0x2eb5(%rip),%xmm0
jbe    118b <check_clock+0x7b>
movl   $0x1,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ead(%rip)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_clock>:
push   %rbx
cmpq   $0x0,0x2f17(%rip)
jne    1129 <check_clock+0x19>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,0x2f07(%rip)
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rcx
sub    0x2ef4(%rip),%rcx
cvtsi2sd %rcx,%xmm0
mov    0x2ea0(%rip),%rcx
divsd  (%rcx),%xmm0
ucomisd 0xeac(%rip),%xmm0
jbe    1162 <check_clock+0x52>
mov    %rax,0x2ed3(%rip)
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@check_clock.lastClock = internal global i64 0
@check_clock.sDelay = internal global double 3.000000e-02
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @check_clock() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca double
store i32 0, i32* %1
%4 = load i64, i64* @check_clock.lastClock
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i64 (...) @clock()
store i64 %7, i64* @check_clock.lastClock
br label %8
8: ; preds = %6, %0
%9 = call i64 (...) @clock()
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = load i64, i64* @check_clock.lastClock
%12 = sub nsw i64 %10, %11
%13 = sitofp i64 %12 to double
%14 = load double, double* @CLOCKS_PER_SEC
%15 = fdiv double %13, %14
store double %15, double* %3
%16 = load double, double* %3
%17 = load double, double* @check_clock.sDelay
%18 = fcmp ogt double %16, %17
br i1 %18, label %19, label %21
19: ; preds = %8
store i32 1, i32* %1
%20 = load i64, i64* %2
store i64 %20, i64* @check_clock.lastClock
br label %21
21: ; preds = %19, %8
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@check_clock.lastClock = internal unnamed_addr global i64 0
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @check_clock() {
%1 = load i64, i64* @check_clock.lastClock
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i64 (...) @clock()
store i64 %4, i64* @check_clock.lastClock
br label %5
5: ; preds = %3, %0
%6 = tail call i64 (...) @clock()
%7 = load i64, i64* @check_clock.lastClock
%8 = sub nsw i64 %6, %7
%9 = sitofp i64 %8 to double
%10 = load double, double* @CLOCKS_PER_SEC
%11 = fdiv double %9, %10
%12 = fcmp ogt double %11, 3.000000e-02
br i1 %12, label %13, label %14
13: ; preds = %5
store i64 %6, i64* @check_clock.lastClock
br label %14
14: ; preds = %13, %5
%15 = phi i32 [ 1, %13 ], [ 0, %5 ]
ret i32 %15
}