#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[4];
  static int index;
  int i, total;
  int fps;
  static int previous;
  int t, frameTime;
  t = trap_Milliseconds();
  frameTime = t - previous;
  previous = t;
  previousTimes[index % 4] = frameTime;
  index++;
  if (index > 4) {
    total = 0;
    for (i = 0; i < 4; i++) {
      total += previousTimes[i];
    }
    if (!total) {
      total = 1;
    }
    fps = 1000 * 4 / total;
    s = va("%ifps", fps);
    w = CG_DrawStrlen(s) * 16;
    CG_DrawBigString(500 - 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    0x2f04(%rip),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,0x2ef8(%rip)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ee8(%rip),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x2c(%rbp),%edx
movslq %eax,%rcx
lea    0x2ec1(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x2ec8(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ebf(%rip)
cmpl   $0x4,0x2eb8(%rip)
jle    124d <CG_DrawFPS+0x10d>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-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    $0xfa0,%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    $0x1f4,%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    0x2f0a(%rip),%ecx
mov    %eax,0x2f04(%rip)
mov    0x2efa(%rip),%eax
lea    0x3(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
and    $0xfffffffc,%edx
mov    %eax,%esi
sub    %edx,%esi
movslq %esi,%rdx
lea    0x2ed1(%rip),%rsi
mov    %ecx,(%rsi,%rdx,4)
lea    0x1(%rax),%ecx
mov    %ecx,0x2ed5(%rip)
cmp    $0x4,%eax
jl     1202 <CG_DrawFPS+0xc2>
movdqa 0x2eb8(%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    $0xfa0,%eax
xor    %edx,%edx
idiv   %ecx
lea    0xe48(%rip),%rdi
mov    %eax,%esi
call   1050 <va@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <CG_DrawStrlen@plt>
shl    $0x4,%eax
mov    $0x1f4,%edi
sub    %eax,%edi
movss  0xe14(%rip),%xmm0
addss  0xc(%rsp),%xmm0
movss  0xe0a(%rip),%xmm1
mov    %rbx,%rsi
call   1030 <CG_DrawBigString@plt>
movss  0xc(%rsp),%xmm0
addss  0xdf8(%rip),%xmm0
addss  0xdf4(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@CG_DrawFPS.previousTimes = internal global [4 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, 4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i32], [4 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, 4
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, 4
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i32], [4 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 4000, %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 500, %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 [4 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, 4
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [4 x i32], [4 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, 3
br i1 %10, label %11, label %23
11: ; preds = %1
%12 = load <4 x i32>, <4 x i32>* bitcast ([4 x i32]* @CG_DrawFPS.previousTimes to <4 x i32>*)
%13 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %12)
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 1, i32 %13
%16 = sdiv i32 4000, %15
%17 = tail call i8* @va(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @CG_DrawStrlen(i8* %17)
%19 = mul i32 %18, -16
%20 = add i32 %19, 500
%21 = fadd float %0, 2.000000e+00
%22 = tail call i32 @CG_DrawBigString(i32 %20, float %21, i8* %17, float 1.000000e+00)
br label %23
23: ; preds = %11, %1
%24 = fadd float %0, 1.600000e+01
%25 = fadd float %24, 4.000000e+00
ret float %25
}