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

/* Variables and functions */
scalar_t__ time(int /*<<< orphan*/ *);
int performance(unsigned long counter, unsigned long divider) {
  int performance = -1;
  static time_t t_last = 0;
  if (counter == 0)
    t_last = 0;
  time_t t_now = time(NULL);
  if (t_last > 0) {
    static unsigned long counter_last = 0;
    if ((t_now - t_last) > 5) {
      performance = (counter - counter_last) / (t_now - t_last) / divider;
      t_last = t_now;
      counter_last = counter;
    }
  } else
    t_last = time(NULL);
  return performance;
}


x86 assembly (clang, -O0):
<performance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113d <performance+0x2d>
movq   $0x0,0x2ef3(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <time@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,0x2ede(%rip)
jle    11ae <performance+0x9e>
mov    -0x20(%rbp),%rax
sub    0x2ecd(%rip),%rax
cmp    $0x5,%rax
jle    11a9 <performance+0x99>
mov    -0x8(%rbp),%rax
sub    0x2ec0(%rip),%rax
mov    -0x20(%rbp),%rcx
sub    0x2ead(%rip),%rcx
xor    %edx,%edx
div    %rcx
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,0x2e92(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2e8f(%rip)
jmp    11be <performance+0xae>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <time@plt>
mov    %rax,0x2e72(%rip)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<performance>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    112a <performance+0x1a>
movq   $0x0,0x2f06(%rip)
xor    %edi,%edi
call   1030 <time@plt>
mov    %rax,%rcx
mov    0x2ef5(%rip),%rax
test   %rax,%rax
jle    116e <performance+0x5e>
mov    %rcx,%rsi
sub    %rax,%rsi
mov    $0xffffffff,%eax
cmp    $0x6,%rsi
jl     11ad <performance+0x9d>
mov    %rbx,%rax
sub    0x2edd(%rip),%rax
mov    %rax,%rdx
or     %rsi,%rdx
shr    $0x20,%rdx
je     1183 <performance+0x73>
xor    %edx,%edx
div    %rsi
jmp    1187 <performance+0x77>
xor    %edi,%edi
call   1030 <time@plt>
mov    %rax,0x2eb4(%rip)
mov    $0xffffffff,%eax
jmp    11ad <performance+0x9d>
xor    %edx,%edx
div    %esi
mov    %rax,%rdx
or     %r14,%rdx
shr    $0x20,%rdx
je     119a <performance+0x8a>
xor    %edx,%edx
div    %r14
jmp    119f <performance+0x8f>
xor    %edx,%edx
div    %r14d
mov    %rcx,0x2e8a(%rip)
mov    %rbx,0x2e8b(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@performance.t_last = internal global i64 0
@performance.counter_last = internal global i64 0
define i32 @performance(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
store i32 -1, i32* %5
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i64 0, i64* @performance.t_last
br label %10
10: ; preds = %9, %2
%11 = call i64 @time(i32* null)
store i64 %11, i64* %6
%12 = load i64, i64* @performance.t_last
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i64, i64* %6
%16 = load i64, i64* @performance.t_last
%17 = sub nsw i64 %15, %16
%18 = icmp sgt i64 %17, 5
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = load i64, i64* %3
%21 = load i64, i64* @performance.counter_last
%22 = sub i64 %20, %21
%23 = load i64, i64* %6
%24 = load i64, i64* @performance.t_last
%25 = sub nsw i64 %23, %24
%26 = udiv i64 %22, %25
%27 = load i64, i64* %4
%28 = udiv i64 %26, %27
%29 = trunc i64 %28 to i32
store i32 %29, i32* %5
%30 = load i64, i64* %6
store i64 %30, i64* @performance.t_last
%31 = load i64, i64* %3
store i64 %31, i64* @performance.counter_last
br label %32
32: ; preds = %19, %14
br label %35
33: ; preds = %10
%34 = call i64 @time(i32* null)
store i64 %34, i64* @performance.t_last
br label %35
35: ; preds = %33, %32
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@performance.t_last = internal unnamed_addr global i64 0
@performance.counter_last = internal unnamed_addr global i64 0
define i32 @performance(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %4, label %5
4: ; preds = %2
store i64 0, i64* @performance.t_last
br label %5
5: ; preds = %4, %2
%6 = tail call i64 @time(i32* null)
%7 = load i64, i64* @performance.t_last
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = sub nsw i64 %6, %7
%11 = icmp sgt i64 %10, 5
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i64, i64* @performance.counter_last
%14 = sub i64 %0, %13
%15 = udiv i64 %14, %10
%16 = udiv i64 %15, %1
%17 = trunc i64 %16 to i32
store i64 %6, i64* @performance.t_last
store i64 %0, i64* @performance.counter_last
br label %20
18: ; preds = %5
%19 = tail call i64 @time(i32* null)
store i64 %19, i64* @performance.t_last
br label %20
20: ; preds = %9, %12, %18
%21 = phi i32 [ %17, %12 ], [ -1, %9 ], [ -1, %18 ]
ret i32 %21
}