#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[40];
  static int index;
  int i, total;
  int fps;
  static int previous;
  int t, frameTime;
  t = trap_Milliseconds();
  frameTime = t - previous;
  previous = t;
  previousTimes[index % 40] = frameTime;
  index++;
  if (index > 40) {
    total = 0;
    for (i = 0; i < 40; i++) {
      total += previousTimes[i];
    }
    if (!total) {
      total = 1;
    }
    fps = 1000 * 40 / 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    0x2f94(%rip),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,0x2f88(%rip)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2f78(%rip),%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x2c(%rbp),%edx
movslq %eax,%rcx
lea    0x2ec1(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x2f58(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f4f(%rip)
cmpl   $0x28,0x2f48(%rip)
jle    124d <CG_DrawFPS+0x10d>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x28,-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    $0x9c40,%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    0x2f9a(%rip),%ecx
mov    %eax,0x2f94(%rip)
movslq 0x2f89(%rip),%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x24,%rdx
add    %esi,%edx
shl    $0x3,%edx
lea    (%rdx,%rdx,4),%edx
mov    %eax,%esi
sub    %edx,%esi
movslq %esi,%rdx
lea    0x2ec1(%rip),%rsi
mov    %ecx,(%rsi,%rdx,4)
lea    0x1(%rax),%ecx
mov    %ecx,0x2f55(%rip)
cmp    $0x28,%rax
jl     125f <CG_DrawFPS+0x11f>
movdqa 0x2eb3(%rip),%xmm0
paddd  0x2e9b(%rip),%xmm0
paddd  0x2eb3(%rip),%xmm0
paddd  0x2ebb(%rip),%xmm0
paddd  0x2ec3(%rip),%xmm0
paddd  0x2ecb(%rip),%xmm0
paddd  0x2ed3(%rip),%xmm0
paddd  0x2edb(%rip),%xmm0
paddd  0x2ee3(%rip),%xmm0
paddd  0x2eeb(%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    $0x9c40,%eax
xor    %edx,%edx
idiv   %ecx
lea    0xdeb(%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  0xdb7(%rip),%xmm0
addss  0xc(%rsp),%xmm0
movss  0xdad(%rip),%xmm1
mov    %rbx,%rsi
call   1030 <CG_DrawBigString@plt>
movss  0xc(%rsp),%xmm0
addss  0xd9b(%rip),%xmm0
addss  0xd97(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@CG_DrawFPS.previousTimes = internal global [40 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, 40
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [40 x i32], [40 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, 40
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, 40
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [40 x i32], [40 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 40000, %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 [40 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, 40
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [40 x i32], [40 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, 39
br i1 %10, label %11, label %41
11: ; preds = %1
%12 = load <4 x i32>, <4 x i32>* bitcast ([40 x i32]* @CG_DrawFPS.previousTimes to <4 x i32>*)
%13 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 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 ([40 x i32], [40 x i32]* @CG_DrawFPS.previousTimes, i64 0, i64 36) to <4 x i32>*)
%30 = add <4 x i32> %29, %28
%31 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %30)
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 1, i32 %31
%34 = sdiv i32 40000, %33
%35 = tail call i8* @va(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = tail call i32 @CG_DrawStrlen(i8* %35)
%37 = mul i32 %36, -16
%38 = add i32 %37, 635
%39 = fadd float %0, 2.000000e+00
%40 = tail call i32 @CG_DrawBigString(i32 %38, float %39, i8* %35, float 1.000000e+00)
br label %41
41: ; preds = %11, %1
%42 = fadd float %0, 1.600000e+01
%43 = fadd float %42, 4.000000e+00
ret float %43
}