#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 */
struct timeval {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int);
void tick(void) {
  static unsigned count = 0;
  static struct timeval past;
  struct timeval now;
  count++;
  gettimeofday(&now, NULL);
  if (past.tv_sec != now.tv_sec) {
    past = now;
    printf("%u\n", count);
    count = 0;
  }
}


x86 assembly (clang, -O0):
<tick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2f0a(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f01(%rip)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    0x2ef5(%rip),%rax
cmp    -0x8(%rbp),%rax
je     117c <tick+0x5c>
mov    -0x8(%rbp),%rax
mov    %rax,0x2ee0(%rip)
mov    0x2ed2(%rip),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,0x2ebc(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tick>:
push   %rax
addl   $0x1,0x2f10(%rip)
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%rax
cmp    %rax,0x2f03(%rip)
je     1162 <tick+0x42>
mov    %rax,0x2efa(%rip)
mov    0x2eec(%rip),%esi
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,0x2ed6(%rip)
pop    %rax
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@tick.count = internal global i32 0
@tick.past = internal global %struct.timeval zeroinitializer
@.str = [4 x i8] c"%u\0A\00"
define void @tick() {
%1 = alloca %struct.timeval
%2 = load i32, i32* @tick.count
%3 = add i32 %2, 1
store i32 %3, i32* @tick.count
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @tick.past, i32 0, i32 0)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%7 = load i64, i64* %6
%8 = icmp ne i64 %5, %7
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = bitcast %struct.timeval* %1 to i8*
%11 = load i32, i32* @tick.count
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* @tick.count
br label %13
13: ; preds = %9, %0
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@tick.count = internal unnamed_addr global i32 0
@tick.past.0 = internal unnamed_addr global i64 0
@.str = [4 x i8] c"%u\0A\00"
define void @tick() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = load i32, i32* @tick.count
%4 = add i32 %3, 1
store i32 %4, i32* @tick.count
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = load i64, i64* @tick.past.0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp eq i64 %6, %8
br i1 %9, label %13, label %10
10: ; preds = %0
store i64 %8, i64* @tick.past.0
%11 = load i32, i32* @tick.count
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* @tick.count
br label %13
13: ; preds = %10, %0
ret void
}