// File: /workspace/github_c_makefile_star2_O0/kieselsteini[P]PiXL-old/pixl.c
// Function: px_run_main_loop
static void px_run_main_loop(lua_State *L) {
  int i;
  SDL_Event ev;
  Uint32 last_tick, current_tick, delta_ticks;

  // init callback
  if (lua_getglobal(L, "init") == LUA_TFUNCTION) lua_call(L, 0, 0);
  else lua_pop(L, 1);

  // loop
  last_tick = SDL_GetTicks(); delta_ticks = 0;
  while (running) {
    // fetch events
    while (SDL_PollEvent(&ev)) {
      switch (ev.type) {
      case SDL_QUIT: running = SDL_FALSE; break;
      case SDL_KEYDOWN: case SDL_KEYUP: px_handle_keys(&ev); break;
      case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: px_handle_mouse(&ev); break;
      case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: px_handle_controller(&ev); break;
      case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: px_open_controllers(L); break;
      case SDL_MOUSEMOTION: inputs[0].mouse.x = ev.motion.x; inputs[0].mouse.y = ev.motion.y; break;
      }
    }
    // update callback
    current_tick = SDL_GetTicks();
    delta_ticks += current_tick - last_tick;
    last_tick = current_tick;
    for (; delta_ticks >= PX_FPS_TICKS; delta_ticks -= PX_FPS_TICKS) {
      // do update call
      if (lua_getglobal(L, "update") == LUA_TFUNCTION) lua_call(L, 0, 0);
      else lua_pop(L, 1);
      // reset input
      for (i = 0; i < PX_NUM_CONTROLLERS; ++i) inputs[i].pressed = 0;
    }
    // render stuff
    px_render_screen(L);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x430d(%rip), %rsi      # 0x56a04
callq 0x9c90
cmpl $0x6, %eax
jne 0x52718
movq -0x8(%rbp), %rdi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r8d
movl %edx, %esi
movq %r8, %rcx
callq 0xbfb0
jmp 0x52726
movq -0x8(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6d90
callq 0x64f0
movl %eax, -0x4c(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x0, 0x112414(%rip)    # 0x164b50
je 0x528a1
jmp 0x52744
leaq -0x48(%rbp), %rdi
callq 0x6320
cmpl $0x0, %eax
je 0x527fc
movl -0x48(%rbp), %eax
movl %eax, -0x58(%rbp)
subl $0x100, %eax            # imm = 0x100
je 0x527ad
jmp 0x52765
movl -0x58(%rbp), %eax
addl $0xfffffd00, %eax       # imm = 0xFFFFFD00
subl $0x2, %eax
jb 0x527b9
jmp 0x52774
movl -0x58(%rbp), %eax
subl $0x400, %eax            # imm = 0x400
je 0x527e5
jmp 0x52780
movl -0x58(%rbp), %eax
addl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
subl $0x2, %eax
jb 0x527c4
jmp 0x5278f
movl -0x58(%rbp), %eax
addl $0xfffff9af, %eax       # imm = 0xFFFFF9AF
subl $0x2, %eax
jb 0x527cf
jmp 0x5279e
movl -0x58(%rbp), %eax
addl $0xfffff9ad, %eax       # imm = 0xFFFFF9AD
subl $0x2, %eax
jb 0x527da
jmp 0x527f7
movl $0x0, 0x112399(%rip)    # 0x164b50
jmp 0x527f7
leaq -0x48(%rbp), %rdi
callq 0x52db0
jmp 0x527f7
leaq -0x48(%rbp), %rdi
callq 0x52f50
jmp 0x527f7
leaq -0x48(%rbp), %rdi
callq 0x52fb0
jmp 0x527f7
movq -0x8(%rbp), %rdi
callq 0x52660
jmp 0x527f7
movl -0x34(%rbp), %eax
movl %eax, 0x112306(%rip)    # 0x164af4
movl -0x30(%rbp), %eax
movl %eax, 0x112301(%rip)    # 0x164af8
jmp 0x52744
callq 0x64f0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
subl -0x4c(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x21, -0x54(%rbp)
jb 0x52893
movq -0x8(%rbp), %rdi
leaq 0x5a85(%rip), %rsi      # 0x582ac
callq 0x9c90
cmpl $0x6, %eax
jne 0x52848
movq -0x8(%rbp), %rdi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r8d
movl %edx, %esi
movq %r8, %rcx
callq 0xbfb0
jmp 0x52856
movq -0x8(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6d90
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0x52886
movslq -0xc(%rbp), %rcx
leaq 0x112282(%rip), %rax    # 0x164af0
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movw $0x0, 0x2(%rax)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5285d
jmp 0x52888
movl -0x54(%rbp), %eax
subl $0x21, %eax
movl %eax, -0x54(%rbp)
jmp 0x52816
movq -0x8(%rbp), %rdi
callq 0x53060
jmp 0x52735
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)