// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/snake/snake.c
// Function: main
int main(void)
{
  int c, maxy, maxx;
  direction_t current_direction, original_direction;

  /* Initialize curses. */
  initscr();
  atexit(exit_handler);
  noecho();
  keypad(stdscr, TRUE);
  timeout(0); /* Non-blocking mode */

  getmaxyx(stdscr, maxy, maxx);
  srandom(time(NULL));

  /* Set initial variables. */
  current_direction = DIRECTION_RIGHT;
  queue_insert(DIRECTION_RIGHT, 0);
  queue_insert(DIRECTION_RIGHT, 0);
  queue_insert(DIRECTION_RIGHT, 0);
  score = 0;
  pos_y = maxy / 2;
  pos_x = maxx / 2;
  place_apple();

  update_screen();

  while (1) {

    /* Read character buffer until empty. */
    original_direction = current_direction;
    while ((c = getch()) != ERR) {
      switch (c) {
      case KEY_RESIZE:
        return 0; /* Not allowed! */
      case KEY_UP:
        if (original_direction != DIRECTION_DOWN)
          current_direction = DIRECTION_UP;
        break;
      case KEY_DOWN:
        if (original_direction != DIRECTION_UP)
          current_direction = DIRECTION_DOWN;
        break;
      case KEY_LEFT:
        if (original_direction != DIRECTION_RIGHT)
          current_direction = DIRECTION_LEFT;
        break;
      case KEY_RIGHT:
        if (original_direction != DIRECTION_LEFT)
          current_direction = DIRECTION_RIGHT;
        break;
      case 'q':
      case 'Q':
      case '\e':
        exit(0);
      }
    }

    /* Move player. */
    switch (current_direction) {
    case DIRECTION_UP:
      pos_y--;
      break;
    case DIRECTION_DOWN:
      pos_y++;
      break;
    case DIRECTION_LEFT:
      pos_x--;
      break;
    case DIRECTION_RIGHT:
      pos_x++;
      break;
    }

    /* Check for collisions. */
    c = mvinch(pos_y, pos_x);
    if (c == ' ') { /* Normal progression. */
      queue_insert(current_direction, 1);
    } else if (c == '@') { /* Expand. */
      queue_insert(current_direction, 0);
      score++;
      place_apple();
    } else { /* Died. */
      flash();
      exit(0);
    }

    /* Redraw screen. */
    update_screen();
    usleep(75000);
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
callq 0x10a0
leaq 0x2e5(%rip), %rdi       # 0x1590
callq 0x19b0
callq 0x1080
movq 0x2d24(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x10c0
movq 0x2d10(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10e0
xorl %eax, %eax
movq 0x2cfd(%rip), %rcx      # 0x3fe0
cmpq (%rcx), %rax
je 0x12fe
movq 0x2cf1(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movswl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1308
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x1c(%rbp)
jmp 0x1308
movl -0x1c(%rbp), %eax
movl %eax, -0xc(%rbp)
xorl %eax, %eax
movq 0x2cc9(%rip), %rcx      # 0x3fe0
cmpq (%rcx), %rax
je 0x1332
movq 0x2cbd(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movswl 0x6(%rax), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x133c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x20(%rbp)
jmp 0x133c
movl -0x20(%rbp), %eax
movl %eax, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x10f0
movl %eax, %edi
callq 0x1050
movl $0x3, -0x14(%rbp)
movl $0x3, %edi
xorl %esi, %esi
callq 0x1620
movl $0x3, %edi
xorl %esi, %esi
callq 0x1620
movl $0x3, %edi
xorl %esi, %esi
callq 0x1620
movl $0x0, 0x2d59(%rip)      # 0x40e0
movl -0xc(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x2d4c(%rip)      # 0x40e4
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x2d3f(%rip)      # 0x40e8
callq 0x1700
callq 0x1840
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movq 0x2c20(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x1070
movl %eax, -0x8(%rbp)
cmpl $-0x1, %eax
je 0x148d
movl -0x8(%rbp), %eax
movl %eax, -0x24(%rbp)
subl $0x1b, %eax
je 0x1481
jmp 0x13e5
movl -0x24(%rbp), %eax
subl $0x51, %eax
je 0x1481
jmp 0x13f3
movl -0x24(%rbp), %eax
subl $0x71, %eax
je 0x1481
jmp 0x1401
movl -0x24(%rbp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x1454
jmp 0x140d
movl -0x24(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x1445
jmp 0x1419
movl -0x24(%rbp), %eax
subl $0x104, %eax            # imm = 0x104
je 0x1463
jmp 0x1425
movl -0x24(%rbp), %eax
subl $0x105, %eax            # imm = 0x105
je 0x1472
jmp 0x1431
movl -0x24(%rbp), %eax
subl $0x19a, %eax            # imm = 0x19A
jne 0x1488
jmp 0x143d
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
cmpl $0x1, -0x18(%rbp)
je 0x1452
movl $0x0, -0x14(%rbp)
jmp 0x1488
cmpl $0x0, -0x18(%rbp)
je 0x1461
movl $0x1, -0x14(%rbp)
jmp 0x1488
cmpl $0x3, -0x18(%rbp)
je 0x1470
movl $0x2, -0x14(%rbp)
jmp 0x1488
cmpl $0x2, -0x18(%rbp)
je 0x147f
movl $0x3, -0x14(%rbp)
jmp 0x1488
xorl %edi, %edi
callq 0x1160
jmp 0x13b9
movl -0x14(%rbp), %eax
movq %rax, -0x30(%rbp)
subq $0x3, %rax
ja 0x14f0
movq -0x30(%rbp), %rax
leaq 0xb5f(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2c30(%rip), %eax      # 0x40e4
addl $-0x1, %eax
movl %eax, 0x2c27(%rip)      # 0x40e4
jmp 0x14f0
movl 0x2c1f(%rip), %eax      # 0x40e4
addl $0x1, %eax
movl %eax, 0x2c16(%rip)      # 0x40e4
jmp 0x14f0
movl 0x2c12(%rip), %eax      # 0x40e8
addl $-0x1, %eax
movl %eax, 0x2c09(%rip)      # 0x40e8
jmp 0x14f0
movl 0x2c01(%rip), %eax      # 0x40e8
addl $0x1, %eax
movl %eax, 0x2bf8(%rip)      # 0x40e8
movq 0x2ae9(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
movl 0x2be4(%rip), %esi      # 0x40e4
movl 0x2be2(%rip), %edx      # 0x40e8
callq 0x1130
cmpl $-0x1, %eax
jne 0x151a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x34(%rbp)
jmp 0x152c
movq 0x2abf(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x1110
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x8(%rbp)
cmpl $0x20, -0x8(%rbp)
jne 0x1547
movl -0x14(%rbp), %edi
movl $0x1, %esi
callq 0x1620
jmp 0x157b
cmpl $0x40, -0x8(%rbp)
jne 0x156d
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0x1620
movl 0x2b83(%rip), %eax      # 0x40e0
addl $0x1, %eax
movl %eax, 0x2b7a(%rip)      # 0x40e0
callq 0x1700
jmp 0x1579
callq 0x10d0
xorl %edi, %edi
callq 0x1160
jmp 0x157b
callq 0x1840
movl $0x124f8, %edi          # imm = 0x124F8
callq 0x1180
jmp 0x13b3
nop