#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*/ gfx_handleWindowEvents(int *);
int /*<<< orphan*/ gfx_swapBuffers();
unsigned int time_ticks();
void gfx_loop(int target_frame_rate, void (*render_func)(unsigned int)) {
  int b_end = 0;
  unsigned int last_render_t = time_ticks();
  while (!b_end) {
    gfx_handleWindowEvents(&b_end);
    unsigned int current_time = time_ticks();
    if ((current_time - last_render_t) * target_frame_rate >= 1000) {
      render_func(current_time - last_render_t);
      gfx_swapBuffers();
      last_render_t = current_time;
    }
  }
}


x86 assembly (clang, -O0):
<gfx_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <time_ticks@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1166 <gfx_loop+0x36>
jmp    11ac <gfx_loop+0x7c>
lea    -0x14(%rbp),%rdi
call   1050 <gfx_handleWindowEvents@plt>
mov    $0x0,%al
call   1030 <time_ticks@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   -0x4(%rbp),%eax
cmp    $0x3e8,%eax
jb     11a7 <gfx_loop+0x77>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%edi
sub    -0x18(%rbp),%edi
call   *%rax
mov    $0x0,%al
call   1040 <gfx_swapBuffers@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <gfx_loop+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfx_loop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%r12d
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1030 <time_ticks@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%r15
jmp    1167 <gfx_loop+0x37>
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,0xc(%rsp)
jne    1197 <gfx_loop+0x67>
mov    %r15,%rdi
call   1050 <gfx_handleWindowEvents@plt>
xor    %eax,%eax
call   1030 <time_ticks@plt>
mov    %eax,%ebx
mov    %eax,%edi
sub    %ebp,%edi
mov    %edi,%eax
imul   %r12d,%eax
cmp    $0x3e8,%eax
jb     1160 <gfx_loop+0x30>
call   *%r14
xor    %eax,%eax
call   1040 <gfx_swapBuffers@plt>
mov    %ebx,%ebp
jmp    1160 <gfx_loop+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gfx_loop(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca void (i32)*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store void (i32)* %1, void (i32)** %4
store i32 0, i32* %5
%8 = call i32 (...) @time_ticks()
store i32 %8, i32* %6
br label %9
9: ; preds = %29, %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = call i32 @gfx_handleWindowEvents(i32* %5)
%15 = call i32 (...) @time_ticks()
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = sub i32 %16, %17
%19 = load i32, i32* %3
%20 = mul i32 %18, %19
%21 = icmp uge i32 %20, 1000
br i1 %21, label %22, label %29
22: ; preds = %13
%23 = load void (i32)*, void (i32)** %4
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = sub i32 %24, %25
%27 = call i32 (...) @gfx_swapBuffers()
%28 = load i32, i32* %7
store i32 %28, i32* %6
br label %29
29: ; preds = %22, %13
br label %9
30: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @gfx_loop(i32 %0, void (i32)* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 (...) @time_ticks()
br label %6
6: ; preds = %2, %15
%7 = phi i32 [ %16, %15 ], [ %5, %2 ]
%8 = call i32 @gfx_handleWindowEvents(i32* %3)
%9 = call i32 (...) @time_ticks()
%10 = sub i32 %9, %7
%11 = mul i32 %10, %0
%12 = icmp ugt i32 %11, 999
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = call i32 (...) @gfx_swapBuffers()
br label %15
15: ; preds = %13, %6
%16 = phi i32 [ %9, %13 ], [ %7, %6 ]
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %6, label %19
19: ; preds = %15
ret void
}