#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 */
scalar_t__ time(int /*<<< orphan*/ *);
int fps() {
  static int resultat = 0;
  static int frames = 0;
  static int last_time = 0;
  int current_time;
  ++frames;
  current_time = (int)time(NULL);
  if ((current_time - last_time) < 1.0) {
    return resultat;
  } else {
    resultat = frames;
    frames = 0;
    last_time = current_time;
    return resultat;
  }
}


x86 assembly (clang, -O0):
<fps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2f12(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f09(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <time@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    0x2ef8(%rip),%eax
cvtsi2sd %eax,%xmm1
movsd  0xeb8(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1160 <fps+0x50>
mov    0x2ed4(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <fps+0x78>
mov    0x2eca(%rip),%eax
mov    %eax,0x2ec0(%rip)
movl   $0x0,0x2eba(%rip)
mov    -0x8(%rbp),%eax
mov    %eax,0x2eb5(%rip)
mov    0x2ea7(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fps>:
push   %rax
addl   $0x1,0x2f18(%rip)
xor    %edi,%edi
call   1030 <time@plt>
mov    %rax,%rcx
cmp    %ecx,0x2f0c(%rip)
jge    1148 <fps+0x38>
mov    0x2f00(%rip),%eax
mov    %eax,0x2ef6(%rip)
movl   $0x0,0x2ef0(%rip)
mov    %ecx,0x2eee(%rip)
pop    %rcx
ret
mov    0x2ede(%rip),%eax
pop    %rcx
ret

LLVM IR (-O0):
@fps.resultat = internal global i32 0
@fps.frames = internal global i32 0
@fps.last_time = internal global i32 0
define i32 @fps() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @fps.frames
%4 = add nsw i32 %3, 1
store i32 %4, i32* @fps.frames
%5 = call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = load i32, i32* @fps.last_time
%9 = sub nsw i32 %7, %8
%10 = sitofp i32 %9 to double
%11 = fcmp olt double %10, 1.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i32, i32* @fps.resultat
store i32 %13, i32* %1
br label %18
14: ; preds = %0
%15 = load i32, i32* @fps.frames
store i32 %15, i32* @fps.resultat
store i32 0, i32* @fps.frames
%16 = load i32, i32* %2
store i32 %16, i32* @fps.last_time
%17 = load i32, i32* @fps.resultat
store i32 %17, i32* %1
br label %18
18: ; preds = %14, %12
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@fps.resultat = internal unnamed_addr global i32 0
@fps.frames = internal unnamed_addr global i32 0
@fps.last_time = internal unnamed_addr global i32 0
define i32 @fps() {
%1 = load i32, i32* @fps.frames
%2 = add nsw i32 %1, 1
store i32 %2, i32* @fps.frames
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = load i32, i32* @fps.last_time
%6 = icmp slt i32 %5, %4
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = load i32, i32* @fps.resultat
br label %11
9: ; preds = %0
%10 = load i32, i32* @fps.frames
store i32 %10, i32* @fps.resultat
store i32 0, i32* @fps.frames
store i32 %4, i32* @fps.last_time
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
ret i32 %12
}