#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*/ CG_DrawBigString(int, float, char *, float);
int CG_DrawStrlen(char *);
int trap_Milliseconds();
char *va(char *, int);
float CG_DrawFPS(float y) {
  char *s;
  int w;
  static int previousTimes[100];
  static int index;
  int i, total;
  int fps;
  static int previous;
  int t, frameTime;
  t = trap_Milliseconds();
  frameTime = t - previous;
  previous = t;
  previousTimes[index % 100] = frameTime;
  index++;
  if (index > 100) {
    total = 0;
    for (i = 0; i < 100; i++) {
      total += previousTimes[i];
    }
    if (!total) {
      total = 1;
    }
    fps = 1000 * 100 / total;
    s = va("%ifps", fps);
    w = CG_DrawStrlen(s) * 16;
    CG_DrawBigString(635 - w, y + 2, s, 1.0F);
  }
  return y + 16 + 4;
}


x86 assembly (clang, -O0):
<CG_DrawFPS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <trap_Milliseconds@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    0x3084(%rip),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,0x3078(%rip)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x3068(%rip),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x2c(%rbp),%edx
movslq %eax,%rcx
lea    0x2ec1(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x3048(%rip),%eax
add    $0x1,%eax
mov    %eax,0x303f(%rip)
cmpl   $0x64,0x3038(%rip)
jle    124d <CG_DrawFPS+0x10d>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    11e8 <CG_DrawFPS+0xa8>
movslq -0x18(%rbp),%rcx
lea    0x2e7f(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bc <CG_DrawFPS+0x7c>
cmpl   $0x0,-0x1c(%rbp)
jne    11f9 <CG_DrawFPS+0xb9>
movl   $0x1,-0x1c(%rbp)
mov    $0x186a0,%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe01(%rip),%rdi
call   1050 <va@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <CG_DrawStrlen@plt>
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    $0x27b,%edi
sub    -0x14(%rbp),%edi
movss  0xdcd(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
mov    -0x10(%rbp),%rsi
movss  0xdb8(%rip),%xmm1
call   1030 <CG_DrawBigString@plt>
movss  0xdb7(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
movss  0xda6(%rip),%xmm1
addss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CG_DrawFPS>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1040 <trap_Milliseconds@plt>
mov    %eax,%ecx
sub    0x308a(%rip),%ecx
mov    %eax,0x3084(%rip)
movslq 0x3079(%rip),%rax
imul   $0x51eb851f,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x25,%rdx
add    %esi,%edx
imul   $0x64,%edx,%edx
mov    %eax,%esi
sub    %edx,%esi
movslq %esi,%rdx
lea    0x2ec4(%rip),%rsi
mov    %ecx,(%rsi,%rdx,4)
lea    0x1(%rax),%ecx
mov    %ecx,0x3048(%rip)
cmp    $0x64,%rax
jl     12d4 <CG_DrawFPS+0x194>
movdqa 0x2eb6(%rip),%xmm0
paddd  0x2e9e(%rip),%xmm0
paddd  0x2eb6(%rip),%xmm0
paddd  0x2ebe(%rip),%xmm0
paddd  0x2ec6(%rip),%xmm0
paddd  0x2ece(%rip),%xmm0
paddd  0x2ed6(%rip),%xmm0
paddd  0x2ede(%rip),%xmm0
paddd  0x2ee6(%rip),%xmm0
paddd  0x2eee(%rip),%xmm0
paddd  0x2ef6(%rip),%xmm0
paddd  0x2efe(%rip),%xmm0
paddd  0x2f06(%rip),%xmm0
paddd  0x2f0e(%rip),%xmm0
paddd  0x2f16(%rip),%xmm0
paddd  0x2f1e(%rip),%xmm0
paddd  0x2f26(%rip),%xmm0
paddd  0x2f2e(%rip),%xmm0
paddd  0x2f36(%rip),%xmm0
paddd  0x2f3e(%rip),%xmm0
paddd  0x2f46(%rip),%xmm0
paddd  0x2f4e(%rip),%xmm0
paddd  0x2f56(%rip),%xmm0
paddd  0x2f5e(%rip),%xmm0
paddd  0x2f66(%rip),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
test   %eax,%eax
mov    $0x1,%ecx
cmovne %eax,%ecx
mov    $0x186a0,%eax
xor    %edx,%edx
idiv   %ecx
lea    0xd76(%rip),%rdi
mov    %eax,%esi
call   1050 <va@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <CG_DrawStrlen@plt>
shl    $0x4,%eax
mov    $0x27b,%edi
sub    %eax,%edi
movss  0xd42(%rip),%xmm0
addss  0xc(%rsp),%xmm0
movss  0xd38(%rip),%xmm1
mov    %rbx,%rsi
call   1030 <CG_DrawBigString@plt>
movss  0xc(%rsp),%xmm0
addss  0xd26(%rip),%xmm0
addss  0xd22(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@CG_DrawFPS.previousTimes = internal global [100 x i32] zeroinitializer
@CG_DrawFPS.index = internal global i32 0
@CG_DrawFPS.previous = internal global i32 0
@.str = [6 x i8] c"%ifps\00"
define float @CG_DrawFPS(float %0) {
%2 = alloca float
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store float %0, float* %2
%10 = call i32 (...) @trap_Milliseconds()
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = load i32, i32* @CG_DrawFPS.previous
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %9
%14 = load i32, i32* %8
store i32 %14, i32* @CG_DrawFPS.previous
%15 = load i32, i32* %9
%16 = load i32, i32* @CG_DrawFPS.index
%17 = srem i32 %16, 100
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 %18
store i32 %15, i32* %19
%20 = load i32, i32* @CG_DrawFPS.index
%21 = add nsw i32 %20, 1
store i32 %21, i32* @CG_DrawFPS.index
%22 = load i32, i32* @CG_DrawFPS.index
%23 = icmp sgt i32 %22, 100
br i1 %23, label %24, label %56
24: ; preds = %1
store i32 0, i32* %6
store i32 0, i32* %5
br label %25
25: ; preds = %35, %24
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 100
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, %32
store i32 %34, i32* %6
br label %35
35: ; preds = %28
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %25
38: ; preds = %25
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %38
store i32 1, i32* %6
br label %42
42: ; preds = %41, %38
%43 = load i32, i32* %6
%44 = sdiv i32 100000, %43
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = call i8* @va(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %45)
store i8* %46, i8** %3
%47 = load i8*, i8** %3
%48 = call i32 @CG_DrawStrlen(i8* %47)
%49 = mul nsw i32 %48, 16
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = sub nsw i32 635, %50
%52 = load float, float* %2
%53 = fadd float %52, 2.000000e+00
%54 = load i8*, i8** %3
%55 = call i32 @CG_DrawBigString(i32 %51, float %53, i8* %54, float 1.000000e+00)
br label %56
56: ; preds = %42, %1
%57 = load float, float* %2
%58 = fadd float %57, 1.600000e+01
%59 = fadd float %58, 4.000000e+00
ret float %59
}

LLVM IR (-O2):
@CG_DrawFPS.previousTimes = internal unnamed_addr global [100 x i32] zeroinitializer
@CG_DrawFPS.index = internal unnamed_addr global i32 0
@CG_DrawFPS.previous = internal unnamed_addr global i32 0
@.str = [6 x i8] c"%ifps\00"
define float @CG_DrawFPS(float %0) {
%2 = tail call i32 (...) @trap_Milliseconds()
%3 = load i32, i32* @CG_DrawFPS.previous
%4 = sub nsw i32 %2, %3
store i32 %2, i32* @CG_DrawFPS.previous
%5 = load i32, i32* @CG_DrawFPS.index
%6 = srem i32 %5, 100
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 %7
store i32 %4, i32* %8
%9 = add nsw i32 %5, 1
store i32 %9, i32* @CG_DrawFPS.index
%10 = icmp sgt i32 %5, 99
br i1 %10, label %11, label %71
11: ; preds = %1
%12 = load <4 x i32>, <4 x i32>* bitcast ([100 x i32]* @CG_DrawFPS.previousTimes to <4 x i32>*)
%13 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 4) to <4 x i32>*)
%14 = add <4 x i32> %13, %12
%15 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 8) to <4 x i32>*)
%16 = add <4 x i32> %15, %14
%17 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 12) to <4 x i32>*)
%18 = add <4 x i32> %17, %16
%19 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 16) to <4 x i32>*)
%20 = add <4 x i32> %19, %18
%21 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 20) to <4 x i32>*)
%22 = add <4 x i32> %21, %20
%23 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 24) to <4 x i32>*)
%24 = add <4 x i32> %23, %22
%25 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 28) to <4 x i32>*)
%26 = add <4 x i32> %25, %24
%27 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 32) to <4 x i32>*)
%28 = add <4 x i32> %27, %26
%29 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 36) to <4 x i32>*)
%30 = add <4 x i32> %29, %28
%31 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 40) to <4 x i32>*)
%32 = add <4 x i32> %31, %30
%33 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 44) to <4 x i32>*)
%34 = add <4 x i32> %33, %32
%35 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 48) to <4 x i32>*)
%36 = add <4 x i32> %35, %34
%37 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 52) to <4 x i32>*)
%38 = add <4 x i32> %37, %36
%39 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 56) to <4 x i32>*)
%40 = add <4 x i32> %39, %38
%41 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 60) to <4 x i32>*)
%42 = add <4 x i32> %41, %40
%43 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 64) to <4 x i32>*)
%44 = add <4 x i32> %43, %42
%45 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 68) to <4 x i32>*)
%46 = add <4 x i32> %45, %44
%47 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 72) to <4 x i32>*)
%48 = add <4 x i32> %47, %46
%49 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 76) to <4 x i32>*)
%50 = add <4 x i32> %49, %48
%51 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 80) to <4 x i32>*)
%52 = add <4 x i32> %51, %50
%53 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 84) to <4 x i32>*)
%54 = add <4 x i32> %53, %52
%55 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 88) to <4 x i32>*)
%56 = add <4 x i32> %55, %54
%57 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 92) to <4 x i32>*)
%58 = add <4 x i32> %57, %56
%59 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 96) to <4 x i32>*)
%60 = add <4 x i32> %59, %58
%61 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %60)
%62 = icmp eq i32 %61, 0
%63 = select i1 %62, i32 1, i32 %61
%64 = sdiv i32 100000, %63
%65 = tail call i8* @va(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %64)
%66 = tail call i32 @CG_DrawStrlen(i8* %65)
%67 = mul i32 %66, -16
%68 = add i32 %67, 635
%69 = fadd float %0, 2.000000e+00
%70 = tail call i32 @CG_DrawBigString(i32 %68, float %69, i8* %65, float 1.000000e+00)
br label %71
71: ; preds = %11, %1
%72 = fadd float %0, 1.600000e+01
%73 = fadd float %72, 4.000000e+00
ret float %73
}