#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*/ drawString(char *, double, int, double, double, double);
unsigned long getTime();
int /*<<< orphan*/ sprintf(char *, char *, float);
void drawFps() {
  static unsigned long timeOld;
  static int frameCounter;
  static float dfps;
  unsigned long time;
  char buffer[16];
  frameCounter++;
  time = getTime();
  if (time > timeOld + 500) {
    dfps = frameCounter * 1000.0 / (time - timeOld);
    frameCounter = 0;
    timeOld = time;
  }
  sprintf(buffer, "%.1lf fps", dfps);
  drawString(buffer, 3.0, 4 * 24.0, 1.0, 1.0, 1.0);
}


x86 assembly (clang, -O0):
<drawFps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2f0a(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f01(%rip)
mov    $0x0,%al
call   1030 <getTime@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2ee3(%rip),%rcx
add    $0x1f4,%rcx
cmp    %rcx,%rax
jbe    11db <drawFps+0xab>
cvtsi2sdl 0x2ed3(%rip),%xmm0
movsd  0xe83(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    0x2eb4(%rip),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xe85(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xe89(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x2e86(%rip)
movl   $0x0,0x2e78(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2e65(%rip)
lea    -0x20(%rbp),%rdi
movss  0x2e65(%rip),%xmm0
lea    0xe52(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x20(%rbp),%rdi
movsd  0xe09(%rip),%xmm0
mov    $0x60,%esi
movsd  0xe04(%rip),%xmm3
movaps %xmm3,%xmm1
movaps %xmm3,%xmm2
call   1040 <drawString@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawFps>:
push   %rbx
sub    $0x10,%rsp
addl   $0x1,0x2f0c(%rip)
xor    %eax,%eax
call   1030 <getTime@plt>
mov    0x2ef6(%rip),%rcx
lea    0x1f4(%rcx),%rdx
cmp    %rdx,%rax
jbe    11b0 <drawFps+0x80>
cvtsi2sdl 0x2eea(%rip),%xmm0
mulsd  0xe9a(%rip),%xmm0
mov    %rax,%rdx
sub    %rcx,%rdx
movq   %rdx,%xmm1
punpckldq 0xea7(%rip),%xmm1
subpd  0xeaf(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x2eaf(%rip)
movl   $0x0,0x2ea1(%rip)
mov    %rax,0x2e92(%rip)
jmp    11b8 <drawFps+0x88>
movss  0x2e94(%rip),%xmm0
lea    0xe81(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
movsd  0xe36(%rip),%xmm0
movsd  0xe36(%rip),%xmm1
mov    %rbx,%rdi
mov    $0x60,%esi
movaps %xmm1,%xmm2
movaps %xmm1,%xmm3
call   1040 <drawString@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@drawFps.timeOld = internal global i64 0
@drawFps.frameCounter = internal global i32 0
@drawFps.dfps = internal global float 0.000000e+00
@.str = [10 x i8] c"%.1lf fps\00"
define void @drawFps() {
%1 = alloca i64
%2 = alloca [16 x i8]
%3 = load i32, i32* @drawFps.frameCounter
%4 = add nsw i32 %3, 1
store i32 %4, i32* @drawFps.frameCounter
%5 = call i64 (...) @getTime()
store i64 %5, i64* %1
%6 = load i64, i64* %1
%7 = load i64, i64* @drawFps.timeOld
%8 = add i64 %7, 500
%9 = icmp ugt i64 %6, %8
br i1 %9, label %10, label %21
10: ; preds = %0
%11 = load i32, i32* @drawFps.frameCounter
%12 = sitofp i32 %11 to double
%13 = fmul double %12, 1.000000e+03
%14 = load i64, i64* %1
%15 = load i64, i64* @drawFps.timeOld
%16 = sub i64 %14, %15
%17 = uitofp i64 %16 to double
%18 = fdiv double %13, %17
%19 = fptrunc double %18 to float
store float %19, float* @drawFps.dfps
store i32 0, i32* @drawFps.frameCounter
%20 = load i64, i64* %1
store i64 %20, i64* @drawFps.timeOld
br label %21
21: ; preds = %10, %0
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%23 = load float, float* @drawFps.dfps
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %23)
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%26 = call i32 @drawString(i8* %25, double 3.000000e+00, i32 96, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00)
ret void
}

LLVM IR (-O2):
@drawFps.timeOld = internal unnamed_addr global i64 0
@drawFps.frameCounter = internal unnamed_addr global i32 0
@drawFps.dfps = internal unnamed_addr global float 0.000000e+00
@.str = [10 x i8] c"%.1lf fps\00"
define void @drawFps() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @drawFps.frameCounter
%4 = add nsw i32 %3, 1
store i32 %4, i32* @drawFps.frameCounter
%5 = tail call i64 (...) @getTime()
%6 = load i64, i64* @drawFps.timeOld
%7 = add i64 %6, 500
%8 = icmp ugt i64 %5, %7
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = load float, float* @drawFps.dfps
br label %19
11: ; preds = %0
%12 = load i32, i32* @drawFps.frameCounter
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 1.000000e+03
%15 = sub i64 %5, %6
%16 = uitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = fptrunc double %17 to float
store float %18, float* @drawFps.dfps
store i32 0, i32* @drawFps.frameCounter
store i64 %5, i64* @drawFps.timeOld
br label %19
19: ; preds = %9, %11
%20 = phi float [ %10, %9 ], [ %18, %11 ]
%21 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %20)
%22 = call i32 @drawString(i8* %2, double 3.000000e+00, i32 96, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00)
ret void
}