// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/invaders/loop.c
// Function: loop
void loop(void)
{
  long cycle;
  iface_action_t action;
  
  game_init();
  iface_init();

  iface_redraw_screen();
  for (cycle = 0;; cycle++) {

    action = iface_get_action();

    /* Perform player action. */
    switch (action) {
    case ACTION_EXIT:
      iface_set_end_msg("Player gave up!");
      return;

    case ACTION_RESIZE:
      if (iface_invalid_size()) {
        iface_set_end_msg("Invalid resize of terminal!");
        return;
      }
      break;

    case ACTION_SHOOT:
      game_fire_shot();
      break;

    case ACTION_MOVE_LEFT:
      game_state.player_pos--;
      if (game_state.player_pos < 2)
        game_state.player_pos = 2;
      break;

    case ACTION_MOVE_RIGHT:
      game_state.player_pos++;
      if (game_state.player_pos > (GAME_MAP_WIDTH - 3))
        game_state.player_pos = GAME_MAP_WIDTH - 3;
      break;

    case ACTION_NONE:
      break;
    }

    if (game_handle_invaders(cycle)) {
      iface_flash_screen();
      iface_set_end_msg("Player could not stop the invaders in time!");
      return;
    }

    if (game_handle_shot())
      iface_flash_screen();

    if (game_handle_bombs()) {
      iface_flash_screen();
      iface_set_end_msg("Player died from an invader's bomb!");
      return;
    }

    if (game_invaders_alive() == 0)
      break; /* Won. */

    iface_redraw_screen();

    usleep(50000);
  }

  iface_set_end_msg("Success! Invader attack has been stopped!");
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
callq 0x1fc0
callq 0x1430
callq 0x1770
movq $0x0, -0x8(%rbp)
callq 0x16a0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq %rax, -0x18(%rbp)
subq $0x5, %rax
ja 0x1385
movq -0x18(%rbp), %rax
leaq 0x1d31(%rip), %rcx      # 0x3004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1d39(%rip), %rdi      # 0x301c
callq 0x1670
jmp 0x140a
callq 0x15d0
cmpl $0x0, %eax
je 0x1308
leaq 0x1d2e(%rip), %rdi      # 0x302c
callq 0x1670
jmp 0x140a
jmp 0x1385
callq 0x2110
jmp 0x1385
leaq 0x3e28(%rip), %rax      # 0x5140
movw 0xa(%rax), %cx
addw $-0x1, %cx
leaq 0x3e19(%rip), %rax      # 0x5140
movw %cx, 0xa(%rax)
leaq 0x3e0e(%rip), %rax      # 0x5140
movswl 0xa(%rax), %eax
cmpl $0x2, %eax
jge 0x1348
leaq 0x3dfe(%rip), %rax      # 0x5140
movw $0x2, 0xa(%rax)
jmp 0x1385
leaq 0x3def(%rip), %rax      # 0x5140
movw 0xa(%rax), %cx
addw $0x1, %cx
leaq 0x3de0(%rip), %rax      # 0x5140
movw %cx, 0xa(%rax)
leaq 0x3dd5(%rip), %rax      # 0x5140
movswl 0xa(%rax), %eax
cmpl $0x4d, %eax
jle 0x1381
leaq 0x3dc5(%rip), %rax      # 0x5140
movw $0x4d, 0xa(%rax)
jmp 0x1385
jmp 0x1385
movq -0x8(%rbp), %rdi
callq 0x2140
cmpl $0x0, %eax
je 0x13a6
callq 0x1fb0
leaq 0x1ca9(%rip), %rdi      # 0x3048
callq 0x1670
jmp 0x140a
callq 0x2410
cmpl $0x0, %eax
je 0x13b5
callq 0x1fb0
callq 0x2670
cmpl $0x0, %eax
je 0x13d2
callq 0x1fb0
leaq 0x1ca9(%rip), %rdi      # 0x3074
callq 0x1670
jmp 0x140a
callq 0x20c0
cmpl $0x0, %eax
jne 0x13de
jmp 0x13fe
callq 0x1770
movl $0xc350, %edi           # imm = 0xC350
callq 0x1180
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x12af
leaq 0x1c93(%rip), %rdi      # 0x3098
callq 0x1670
addq $0x20, %rsp
popq %rbp
retq