// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/cgame/cgame.c
// Function: main
int main(void)
{
  int i, maxx, maxy, direction;
  char *done = NULL;

  initscr();
  if (has_colors()) {
    start_color();
    init_pair(PAIR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
    init_pair(PAIR_CYAN,   COLOR_CYAN,   COLOR_BLACK);
  }
  noecho();
  keypad(stdscr, TRUE);
  getmaxyx(stdscr, maxy, maxx);

  if (maxy != GAME_ROWS || maxx != GAME_COLS) {
    endwin();
    fprintf(stderr, "Terminal must be %dx%d!\n", GAME_ROWS, GAME_COLS);
    return 1;
  }

  init_game();

  while (done == NULL) {
    draw_screen();

    /* Get player input. */
    direction = DIRECTION_NONE;
    switch (getch()) {
    case KEY_LEFT:
      direction = DIRECTION_LEFT;
      break;

    case KEY_RIGHT:
      direction = DIRECTION_RIGHT;
      break;

    case KEY_UP:
      direction = DIRECTION_UP;
      break;

    case KEY_DOWN:
      direction = DIRECTION_DOWN;
      break;

    case KEY_RESIZE:
      done = "Window resize detected, aborted...";
      break;

    case 'q':
    case 'Q':
    case '\e':
      done = "Quitting...";
      break;

    default:
      break;
    }

    /* Move player, and check for collisions. */
    switch (move_object_check(&player, direction)) {
    case MOVE_OK:
      steps_taken++;
      break;

    case MOVE_BLOCKED:
      break;

    case MOVE_ON_MINE:
      done = "You were killed by a mine!";
      break;

    case MOVE_ON_MONEY:
      for (i = 0; i < AMOUNT_OF_MONEY; i++) {
        if (player.y == money[i].y && player.x == money[i].x) {
          money_collected++;
          money[i].taken = 1;
        }
      }
      break;

    case MOVE_ON_ENEMY:
      done = "You moved onto the enemy!";
      break;
    }

    draw_screen(); /* To update the positions of the objects, not visible. */

    /* Move enemy, and check for collision with player. */
    if (move_object_check(&enemy, direction_to_player()) == MOVE_BLOCKED) {
      enemy_idle_count++;
      if (enemy_idle_count > 3) {
        if (move_object_check(&enemy, random_direction()) == MOVE_OK)
          enemy_idle_count = 0;
      }
    }

    if (player.y == enemy.y && player.x == enemy.x) {
      done = "You were killed by the enemy!";
      break;
    }

    if (money_collected == AMOUNT_OF_MONEY)
      done = "Well done! all money collected!";
  }

  draw_screen();
  endwin();

  fprintf(stderr, "%s\n", done);
  fprintf(stderr, "You collected %d$ of %d$.\n",
    money_collected, AMOUNT_OF_MONEY);
  fprintf(stderr, "You walked %d step%s.\n", 
    steps_taken, (steps_taken == 1) ? "" : "s");

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movq $0x0, -0x20(%rbp)
callq 0x10a0
callq 0x1030
testb $0x1, %al
jne 0x1287
jmp 0x12ae
callq 0x10c0
movl $0x1, %edi
movl $0x3, %esi
xorl %edx, %edx
callq 0x1110
movl $0x2, %edi
movl $0x6, %esi
xorl %edx, %edx
callq 0x1110
callq 0x1090
movq 0x2d1e(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
movl $0x1, %esi
callq 0x10d0
xorl %eax, %eax
movq 0x2d08(%rip), %rcx      # 0x3fd8
cmpq (%rcx), %rax
je 0x12eb
movq 0x2cfc(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movswl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x12f5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x24(%rbp)
jmp 0x12f5
movl -0x24(%rbp), %eax
movl %eax, -0x10(%rbp)
xorl %eax, %eax
movq 0x2cd4(%rip), %rcx      # 0x3fd8
cmpq (%rcx), %rax
je 0x131f
movq 0x2cc8(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movswl 0x6(%rax), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1329
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x28(%rbp)
jmp 0x1329
movl -0x28(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpl $0x18, -0x10(%rbp)
jne 0x133b
cmpl $0x50, -0xc(%rbp)
je 0x136e
callq 0x1150
movq 0x2cb1(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xdb3(%rip), %rsi       # 0x2104
movl $0x18, %edx
movl $0x50, %ecx
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x4(%rbp)
jmp 0x1642
callq 0x1650
cmpq $0x0, -0x20(%rbp)
jne 0x15b9
callq 0x18c0
movl $0x0, -0x14(%rbp)
movq 0x2c47(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1080
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
subl $0x1b, %eax
je 0x142a
jmp 0x13a9
movl -0x2c(%rbp), %eax
subl $0x51, %eax
je 0x142a
jmp 0x13b3
movl -0x2c(%rbp), %eax
subl $0x71, %eax
je 0x142a
jmp 0x13bd
movl -0x2c(%rbp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x1414
jmp 0x13c9
movl -0x2c(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x140b
jmp 0x13d5
movl -0x2c(%rbp), %eax
subl $0x104, %eax            # imm = 0x104
je 0x13f9
jmp 0x13e1
movl -0x2c(%rbp), %eax
subl $0x105, %eax            # imm = 0x105
je 0x1402
jmp 0x13ed
movl -0x2c(%rbp), %eax
subl $0x19a, %eax            # imm = 0x19A
je 0x141d
jmp 0x1437
movl $0x1, -0x14(%rbp)
jmp 0x1439
movl $0x2, -0x14(%rbp)
jmp 0x1439
movl $0x3, -0x14(%rbp)
jmp 0x1439
movl $0x4, -0x14(%rbp)
jmp 0x1439
leaq 0xcf9(%rip), %rax       # 0x211d
movq %rax, -0x20(%rbp)
jmp 0x1439
leaq 0xd0f(%rip), %rax       # 0x2140
movq %rax, -0x20(%rbp)
jmp 0x1439
jmp 0x1439
movl -0x14(%rbp), %esi
leaq 0x2c8d(%rip), %rdi      # 0x40d0
callq 0x1a00
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x4, %eax
ja 0x151c
movq -0x38(%rbp), %rax
leaq 0xba2(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2c73(%rip), %eax      # 0x40e4
addl $0x1, %eax
movl %eax, 0x2c6a(%rip)      # 0x40e4
jmp 0x151c
jmp 0x151c
leaq 0xcc1(%rip), %rax       # 0x214c
movq %rax, -0x20(%rbp)
jmp 0x151c
movl $0x0, -0x8(%rbp)
cmpl $0x14, -0x8(%rbp)
jge 0x150f
movl 0x2c29(%rip), %eax      # 0x40d0
movslq -0x8(%rbp), %rdx
leaq 0x2c3e(%rip), %rcx      # 0x40f0
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x1502
movl 0x2c11(%rip), %eax      # 0x40d4
movslq -0x8(%rbp), %rdx
leaq 0x2c22(%rip), %rcx      # 0x40f0
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x1502
movl 0x2da0(%rip), %eax      # 0x4280
addl $0x1, %eax
movl %eax, 0x2d97(%rip)      # 0x4280
movslq -0x8(%rbp), %rcx
leaq 0x2bfc(%rip), %rax      # 0x40f0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x10(%rax)
jmp 0x1504
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x149b
jmp 0x151c
leaq 0xc4f(%rip), %rax       # 0x2167
movq %rax, -0x20(%rbp)
callq 0x18c0
callq 0x1c90
movl %eax, %esi
leaq 0x2d55(%rip), %rdi      # 0x4284
callq 0x1a00
cmpl $0x1, %eax
jne 0x1577
movl 0x2d59(%rip), %eax      # 0x4298
addl $0x1, %eax
movl %eax, 0x2d50(%rip)      # 0x4298
cmpl $0x3, 0x2d49(%rip)      # 0x4298
jle 0x1575
callq 0x1d50
movl %eax, %esi
leaq 0x2d25(%rip), %rdi      # 0x4284
callq 0x1a00
cmpl $0x0, %eax
jne 0x1573
movl $0x0, 0x2d25(%rip)      # 0x4298
jmp 0x1575
jmp 0x1577
movl 0x2b53(%rip), %eax      # 0x40d0
cmpl 0x2d01(%rip), %eax      # 0x4284
jne 0x15a0
movl 0x2b49(%rip), %eax      # 0x40d4
cmpl 0x2cf7(%rip), %eax      # 0x4288
jne 0x15a0
leaq 0xbe7(%rip), %rax       # 0x2181
movq %rax, -0x20(%rbp)
jmp 0x15b9
cmpl $0x14, 0x2cd9(%rip)     # 0x4280
jne 0x15b4
leaq 0xbef(%rip), %rax       # 0x219f
movq %rax, -0x20(%rbp)
jmp 0x1373
callq 0x18c0
callq 0x1150
movq 0x2a2e(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbe7(%rip), %rsi       # 0x21bf
movb $0x0, %al
callq 0x10e0
movq 0x2a12(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl 0x2c91(%rip), %edx      # 0x4280
leaq 0xbcd(%rip), %rsi       # 0x21c3
movl $0x14, %ecx
movb $0x0, %al
callq 0x10e0
movq 0x29ef(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl 0x2ad2(%rip), %edx      # 0x40e4
movl 0x2acc(%rip), %esi      # 0x40e4
leaq 0xbd6(%rip), %rcx       # 0x21f5
leaq 0xaf6(%rip), %rax       # 0x211c
cmpl $0x1, %esi
cmoveq %rax, %rcx
leaq 0xbaa(%rip), %rsi       # 0x21de
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)