#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 */
int /*<<< orphan*/ GLUT_ELAPSED_TIME;
int glutGet(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double);
void print_performance(void) {
  static int first = 1;
  static int start, num_frames;
  int current;
  if (first) {
    start = glutGet(GLUT_ELAPSED_TIME);
    num_frames = 0;
    first = 0;
  }
  num_frames++;
  current = glutGet(GLUT_ELAPSED_TIME);
  if (current - start > 1000) {
    double elapsed = 1e-3 * (double)(current - start);
    double rate = (double)num_frames / elapsed;
    printf("%5.1f fps\n", rate);
    num_frames = 0;
    start = current;
  }
}


x86 assembly (clang, -O0):
<print_performance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2f01(%rip)
je     115d <print_performance+0x3d>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
call   1030 <glutGet@plt>
mov    %eax,0x2eef(%rip)
movl   $0x0,0x2ee9(%rip)
movl   $0x0,0x2ed3(%rip)
mov    0x2ed9(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ed0(%rip)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1030 <glutGet@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    0x2eb2(%rip),%eax
cmp    $0x3e8,%eax
jle    11e5 <print_performance+0xc5>
mov    -0x4(%rbp),%eax
sub    0x2e9e(%rip),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe5a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl 0x2e85(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,0x2e60(%rip)
mov    -0x4(%rbp),%eax
mov    %eax,0x2e53(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_performance>:
push   %rbx
cmpb   $0x1,0x2f0c(%rip)
jne    1135 <print_performance+0x15>
mov    0x2f0c(%rip),%eax
add    $0x1,%eax
jmp    1155 <print_performance+0x35>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
call   1030 <glutGet@plt>
mov    %eax,0x2eef(%rip)
movb   $0x1,0x2ee4(%rip)
mov    $0x1,%eax
mov    %eax,0x2ee1(%rip)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
call   1030 <glutGet@plt>
mov    %eax,%ebx
sub    0x2ec7(%rip),%eax
cmp    $0x3e9,%eax
jl     11ac <print_performance+0x8c>
cvtsi2sd %eax,%xmm1
mulsd  0xe7c(%rip),%xmm1
cvtsi2sdl 0x2eb0(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,0x2e96(%rip)
mov    %ebx,0x2e8c(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@print_performance.first = internal global i32 1
@print_performance.start = internal global i32 0
@print_performance.num_frames = internal global i32 0
@GLUT_ELAPSED_TIME = global i32 0
@.str = [11 x i8] c"%5.1f fps\0A\00"
define void @print_performance() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = load i32, i32* @print_performance.first
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @GLUT_ELAPSED_TIME
%8 = call i32 @glutGet(i32 %7)
store i32 %8, i32* @print_performance.start
store i32 0, i32* @print_performance.num_frames
store i32 0, i32* @print_performance.first
br label %9
9: ; preds = %6, %0
%10 = load i32, i32* @print_performance.num_frames
%11 = add nsw i32 %10, 1
store i32 %11, i32* @print_performance.num_frames
%12 = load i32, i32* @GLUT_ELAPSED_TIME
%13 = call i32 @glutGet(i32 %12)
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = load i32, i32* @print_performance.start
%16 = sub nsw i32 %14, %15
%17 = icmp sgt i32 %16, 1000
br i1 %17, label %18, label %31
18: ; preds = %9
%19 = load i32, i32* %1
%20 = load i32, i32* @print_performance.start
%21 = sub nsw i32 %19, %20
%22 = sitofp i32 %21 to double
%23 = fmul double 1.000000e-03, %22
store double %23, double* %2
%24 = load i32, i32* @print_performance.num_frames
%25 = sitofp i32 %24 to double
%26 = load double, double* %2
%27 = fdiv double %25, %26
store double %27, double* %3
%28 = load double, double* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %28)
store i32 0, i32* @print_performance.num_frames
%30 = load i32, i32* %1
store i32 %30, i32* @print_performance.start
br label %31
31: ; preds = %18, %9
ret void
}

LLVM IR (-O2):
@print_performance.first = internal unnamed_addr global i1 false
@print_performance.start = internal unnamed_addr global i32 0
@print_performance.num_frames = internal unnamed_addr global i32 0
@GLUT_ELAPSED_TIME = global i32 0
@.str = [11 x i8] c"%5.1f fps\0A\00"
define void @print_performance() {
%1 = load i1, i1* @print_performance.first
br i1 %1, label %2, label %5
2: ; preds = %0
%3 = load i32, i32* @print_performance.num_frames
%4 = add i32 %3, 1
br label %8
5: ; preds = %0
%6 = load i32, i32* @GLUT_ELAPSED_TIME
%7 = tail call i32 @glutGet(i32 %6)
store i32 %7, i32* @print_performance.start
store i1 true, i1* @print_performance.first
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ %4, %2 ], [ 1, %5 ]
store i32 %9, i32* @print_performance.num_frames
%10 = load i32, i32* @GLUT_ELAPSED_TIME
%11 = tail call i32 @glutGet(i32 %10)
%12 = load i32, i32* @print_performance.start
%13 = sub nsw i32 %11, %12
%14 = icmp sgt i32 %13, 1000
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = sitofp i32 %13 to double
%17 = fmul double %16, 1.000000e-03
%18 = load i32, i32* @print_performance.num_frames
%19 = sitofp i32 %18 to double
%20 = fdiv double %19, %17
%21 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %20)
store i32 0, i32* @print_performance.num_frames
store i32 %11, i32* @print_performance.start
br label %22
22: ; preds = %15, %8
ret void
}