#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
scalar_t__ CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, ...);
int time_blitter(void) {
  int const duration = 4;
  static clock_t end_time;
  static int count;
  if (!count) {
    clock_t time = clock();
    while (clock() == time) {
    }
    if (clock() - time > CLOCKS_PER_SEC) {
      printf("Insufficient time resolution\n");
      return 0;
    }
    end_time = clock() + CLOCKS_PER_SEC * duration;
  } else if (clock() >= end_time) {
    int rate = count / duration;
    printf("Performance: %d frames per second, which would use %d%% CPU at 60 "
           "FPS\n",
           rate, 60 * 100 / rate);
    return 0;
  }
  count++;
  return 1;
}


x86 assembly (clang, -O0):
<time_blitter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x4,-0x8(%rbp)
cmpl   $0x0,0x2f0a(%rip)
jne    11b6 <time_blitter+0x96>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
cmp    -0x10(%rbp),%rax
jne    115d <time_blitter+0x3d>
jmp    1147 <time_blitter+0x27>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x10(%rbp),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jle    1192 <time_blitter+0x72>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <time_blitter+0xfe>
mov    $0x0,%al
call   1030 <clock@plt>
mov    0x2e48(%rip),%rcx
mov    (%rcx),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,0x2e87(%rip)
jmp    1208 <time_blitter+0xe8>
mov    $0x0,%al
call   1030 <clock@plt>
cmp    0x2e74(%rip),%rax
jl     1203 <time_blitter+0xe3>
mov    0x2e70(%rip),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x1770,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edx
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <time_blitter+0xfe>
jmp    1208 <time_blitter+0xe8>
mov    0x2e32(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e29(%rip)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_blitter>:
push   %rbp
push   %rbx
push   %rax
mov    0x2f0f(%rip),%ebp
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     1180 <time_blitter+0x50>
cmp    0x2ef2(%rip),%rbx
jl     11c7 <time_blitter+0x97>
mov    0x2ef2(%rip),%eax
lea    0x3(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x2,%esi
xor    %ebp,%ebp
mov    $0x1770,%eax
xor    %edx,%edx
idiv   %esi
lea    0xe8d(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d3 <time_blitter+0xa3>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <clock@plt>
cmp    %rbx,%rax
je     1180 <time_blitter+0x50>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
mov    0x2e49(%rip),%rbx
cmp    (%rbx),%rax
jle    11b2 <time_blitter+0x82>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
jmp    11d3 <time_blitter+0xa3>
xor    %eax,%eax
call   1040 <clock@plt>
mov    (%rbx),%rcx
lea    (%rax,%rcx,4),%rax
mov    %rax,0x2e79(%rip)
addl   $0x1,0x2e7a(%rip)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@time_blitter.end_time = internal global i64 0
@time_blitter.count = internal global i32 0
@CLOCKS_PER_SEC = global i64 0
@.str = [30 x i8] c"Insufficient time resolution\0A\00"
@.str.1 = [71 x i8] c"Performance: %d frames per second, which would use %d%% CPU at 60 FPS\0A\00"
define i32 @time_blitter() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i32 4, i32* %2
%5 = load i32, i32* @time_blitter.count
%6 = icmp ne i32 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %0
%8 = call i64 (...) @clock()
store i64 %8, i64* %3
br label %9
9: ; preds = %13, %7
%10 = call i64 (...) @clock()
%11 = load i64, i64* %3
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
br label %9
14: ; preds = %9
%15 = call i64 (...) @clock()
%16 = load i64, i64* %3
%17 = sub nsw i64 %15, %16
%18 = load i64, i64* @CLOCKS_PER_SEC
%19 = icmp sgt i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %42
22: ; preds = %14
%23 = call i64 (...) @clock()
%24 = load i64, i64* @CLOCKS_PER_SEC
%25 = mul nsw i64 %24, 4
%26 = add nsw i64 %23, %25
store i64 %26, i64* @time_blitter.end_time
br label %39
27: ; preds = %0
%28 = call i64 (...) @clock()
%29 = load i64, i64* @time_blitter.end_time
%30 = icmp sge i64 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i32, i32* @time_blitter.count
%33 = sdiv i32 %32, 4
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = load i32, i32* %4
%36 = sdiv i32 6000, %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %36)
store i32 0, i32* %1
br label %42
38: ; preds = %27
br label %39
39: ; preds = %38, %22
%40 = load i32, i32* @time_blitter.count
%41 = add nsw i32 %40, 1
store i32 %41, i32* @time_blitter.count
store i32 1, i32* %1
br label %42
42: ; preds = %39, %31, %20
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@time_blitter.end_time = internal unnamed_addr global i64 0
@time_blitter.count = internal unnamed_addr global i32 0
@CLOCKS_PER_SEC = global i64 0
@.str.1 = [71 x i8] c"Performance: %d frames per second, which would use %d%% CPU at 60 FPS\0A\00"
@str = [29 x i8] c"Insufficient time resolution\00"
define i32 @time_blitter() {
%1 = load i32, i32* @time_blitter.count
%2 = icmp eq i32 %1, 0
%3 = tail call i64 (...) @clock()
br i1 %2, label %4, label %19
4: ; preds = %0, %4
%5 = tail call i64 (...) @clock()
%6 = icmp eq i64 %5, %3
br i1 %6, label %4, label %7
7: ; preds = %4
%8 = tail call i64 (...) @clock()
%9 = sub nsw i64 %8, %3
%10 = load i64, i64* @CLOCKS_PER_SEC
%11 = icmp sgt i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %30
14: ; preds = %7
%15 = tail call i64 (...) @clock()
%16 = load i64, i64* @CLOCKS_PER_SEC
%17 = shl nsw i64 %16, 2
%18 = add nsw i64 %17, %15
store i64 %18, i64* @time_blitter.end_time
br label %27
19: ; preds = %0
%20 = load i64, i64* @time_blitter.end_time
%21 = icmp slt i64 %3, %20
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = load i32, i32* @time_blitter.count
%24 = sdiv i32 %23, 4
%25 = sdiv i32 6000, %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
br label %30
27: ; preds = %14, %19
%28 = load i32, i32* @time_blitter.count
%29 = add nsw i32 %28, 1
store i32 %29, i32* @time_blitter.count
br label %30
30: ; preds = %12, %27, %22
%31 = phi i32 [ 0, %22 ], [ 1, %27 ], [ 0, %12 ]
ret i32 %31
}