#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_BITMAP_9_BY_15;
int /*<<< orphan*/ GLUT_ELAPSED_TIME;
int /*<<< orphan*/ glRasterPos2i(int, int);
int /*<<< orphan*/ glutBitmapString(int /*<<< orphan*/, char *);
int glutGet(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, double);
void drawFps(void) {
  static int timeOld;
  static int frameCounter;
  static double dfps;
  int time;
  char buffer[16];
  frameCounter++;
  time = glutGet(GLUT_ELAPSED_TIME);
  if (time > timeOld + 500) {
    dfps = frameCounter * 1000.0 / (time - timeOld);
    frameCounter = 0;
    timeOld = time;
  }
  glRasterPos2i(10, 20);
  sprintf(buffer, "%.1lf fps", dfps);
  glutBitmapString(GLUT_BITMAP_9_BY_15, buffer);
}


x86 assembly (clang, -O0):
<drawFps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2efe(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ef5(%rip)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1030 <glutGet@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ed7(%rip),%ecx
add    $0x1f4,%ecx
cmp    %ecx,%eax
jle    11bf <drawFps+0x7f>
cvtsi2sdl 0x2ec5(%rip),%xmm0
movsd  0xe71(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x4(%rbp),%eax
sub    0x2eac(%rip),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2ea4(%rip)
movl   $0x0,0x2e96(%rip)
mov    -0x4(%rbp),%eax
mov    %eax,0x2e89(%rip)
mov    $0xa,%edi
mov    $0x14,%esi
call   1050 <glRasterPos2i@plt>
lea    -0x20(%rbp),%rdi
movsd  0x2e76(%rip),%xmm0
lea    0xe27(%rip),%rsi
call   1040 <sprintf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <glutBitmapString@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawFps>:
push   %rbx
sub    $0x10,%rsp
addl   $0x1,0x2f00(%rip)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1030 <glutGet@plt>
mov    0x2ee8(%rip),%ecx
lea    0x1f4(%rcx),%edx
cmp    %edx,%eax
jle    119e <drawFps+0x5e>
cvtsi2sdl 0x2eda(%rip),%xmm0
mulsd  0xe86(%rip),%xmm0
mov    %eax,%edx
sub    %ecx,%edx
cvtsi2sd %edx,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2ec2(%rip)
movl   $0x0,0x2eb4(%rip)
mov    %eax,0x2eaa(%rip)
mov    $0xa,%edi
mov    $0x14,%esi
call   1050 <glRasterPos2i@plt>
movsd  0x2e9b(%rip),%xmm0
lea    0xe4c(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1060 <glutBitmapString@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@drawFps.timeOld = internal unnamed_addr global i32 0
@drawFps.frameCounter = internal unnamed_addr global i32 0
@drawFps.dfps = internal unnamed_addr global double 0.000000e+00
@GLUT_ELAPSED_TIME = global i32 0
@.str = [10 x i8] c"%.1lf fps\00"
@GLUT_BITMAP_9_BY_15 = global i32 0
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 = load i32, i32* @GLUT_ELAPSED_TIME
%6 = tail call i32 @glutGet(i32 %5)
%7 = load i32, i32* @drawFps.timeOld
%8 = add nsw i32 %7, 500
%9 = icmp sgt i32 %6, %8
br i1 %9, label %10, label %17
10: ; preds = %0
%11 = load i32, i32* @drawFps.frameCounter
%12 = sitofp i32 %11 to double
%13 = fmul double %12, 1.000000e+03
%14 = sub nsw i32 %6, %7
%15 = sitofp i32 %14 to double
%16 = fdiv double %13, %15
store double %16, double* @drawFps.dfps
store i32 0, i32* @drawFps.frameCounter
store i32 %6, i32* @drawFps.timeOld
br label %17
17: ; preds = %10, %0
%18 = tail call i32 @glRasterPos2i(i32 10, i32 20)
%19 = load double, double* @drawFps.dfps
%20 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %19)
%21 = load i32, i32* @GLUT_BITMAP_9_BY_15
%22 = call i32 @glutBitmapString(i32 %21, i8* %2)
ret void
}