// File: /workspace/github_c_makefile_star2_O0/skeeto[P]flappy/flappy.cc
// Function: main
int main(int argc, char **argv) {
  srand(std::time(NULL));

  /* Parse command line arguments. */
  int opt;
  const char *filename = "/tmp/flappy-scores.db", *host = "localhost";
  while ((opt = getopt(argc, argv, "d:h:p")) != -1) {
    switch (opt) {
      case 'd':
        filename = optarg;
        break;
      case 'h':
        host = optarg;
        break;
      case 'p':  // ignore
        break;
    }
  }

  Display display;
  HighScores scores{filename, display.height - 1};

  while (true) {
    Game game{&display};

    int score = game.run();
    if (score < 0) {
      return 0;  // game quit early
    }

    /* Game over */
    mvprintw(display.height + 1, 0, "Game over!");
    print_scores(display, scores);

    /* Enter new high score */
    if (scores.is_best(score)) {
      attron(A_BOLD);
      mvprintw(display.height + 2, 0, "You have a high score!");
      mvprintw(display.height + 3, 0, "Enter name: ");
      attroff(A_BOLD);
      char name[23] = {0};
      if (!display.read_name(display.height + 3, 12, name, sizeof(name))) {
        return 0;
      }
      if (std::strlen(name) == 0) {
        std::strcpy(name, "(anonymous)");
      }
      scores.insert_score(name, score);
      move(display.height + 3, 0);
      clrtoeol();
      print_scores(display, scores);
    }

    /* Handle quit/restart */
    mvprintw(display.height + 2, 0, "Press 'q' to quit, 'r' to retry.");
    int c;
    while ((c = display.block_getch()) != 'r') {
      if (is_exit(c) || c == ERR) {
        return 0;
      }
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x7290
movl %eax, %edi
callq 0x72c0
leaq 0x8c842(%rip), %rax     # 0x94032
movq %rax, -0x20(%rbp)
leaq 0x8c84d(%rip), %rax     # 0x94048
movq %rax, -0x28(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x8c845(%rip), %rdx     # 0x94052
callq 0x7080
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x7868
movl -0x14(%rbp), %eax
movl %eax, -0x128(%rbp)
subl $0x64, %eax
je 0x7844
jmp 0x782a
movl -0x128(%rbp), %eax
subl $0x68, %eax
je 0x7854
jmp 0x7837
movl -0x128(%rbp), %eax
subl $0x70, %eax
je 0x7864
jmp 0x7866
movq 0xaa77d(%rip), %rax     # 0xb1fc8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x7866
movq 0xaa76d(%rip), %rax     # 0xb1fc8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x7866
jmp 0x7866
jmp 0x77ff
leaq -0x30(%rbp), %rdi
movl $0x28, %esi
movl $0x14, %edx
callq 0x7cb0
movq -0x20(%rbp), %rsi
movl -0x30(%rbp), %edx
decl %edx
leaq -0x68(%rbp), %rdi
callq 0xac20
jmp 0x788f
jmp 0x7891
jmp 0x7893
leaq -0xf8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x7d30
jmp 0x78a5
leaq -0xf8(%rbp), %rdi
callq 0x7d80
movl %eax, -0x12c(%rbp)
jmp 0x78b9
movl -0x12c(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0xfc(%rbp)
jge 0x7923
movl $0x0, -0x4(%rbp)
movl $0x1, -0x100(%rbp)
jmp 0x7b18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x7b5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x7b53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x82a0
jmp 0x7b53
movl -0x30(%rbp), %edi
incl %edi
leaq 0x8c729(%rip), %rdx     # 0x94058
xorl %esi, %esi
movb %sil, %al
callq 0x73d0
jmp 0x793b
leaq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7650
jmp 0x794a
movl -0xfc(%rbp), %esi
leaq -0x68(%rbp), %rdi
callq 0xae20
movb %al, -0x12d(%rbp)
jmp 0x7961
movb -0x12d(%rbp), %al
testb $0x1, %al
jne 0x7970
jmp 0x7aa4
movq 0xaa669(%rip), %rax     # 0xb1fe0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x200000, %esi         # imm = 0x200000
callq 0x7180
jmp 0x798a
movl -0x30(%rbp), %edi
addl $0x2, %edi
leaq 0x8c6cc(%rip), %rdx     # 0x94063
xorl %esi, %esi
movb %sil, %al
callq 0x73d0
jmp 0x79a3
movl -0x30(%rbp), %edi
addl $0x3, %edi
leaq 0x8c6ca(%rip), %rdx     # 0x9407a
xorl %esi, %esi
movb %sil, %al
callq 0x73d0
jmp 0x79bc
movq 0xaa61d(%rip), %rax     # 0xb1fe0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x200000, %esi         # imm = 0x200000
callq 0x73c0
jmp 0x79d6
xorps %xmm0, %xmm0
movaps %xmm0, -0x120(%rbp)
movq $0x0, -0x111(%rbp)
movl -0x30(%rbp), %esi
addl $0x3, %esi
leaq -0x30(%rbp), %rdi
movl $0xc, %edx
leaq -0x120(%rbp), %rcx
movl $0x17, %r8d
callq 0x7ff0
movb %al, -0x12e(%rbp)
jmp 0x7a14
movb -0x12e(%rbp), %al
testb $0x1, %al
jne 0x7a36
jmp 0x7a20
movl $0x0, -0x4(%rbp)
movl $0x1, -0x100(%rbp)
jmp 0x7b18
leaq -0x120(%rbp), %rdi
callq 0x7150
cmpq $0x0, %rax
jne 0x7a5b
leaq -0x120(%rbp), %rdi
leaq 0x8c631(%rip), %rsi     # 0x94087
callq 0x72a0
movl -0xfc(%rbp), %edx
leaq -0x68(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0xae90
jmp 0x7a73
movl -0x30(%rbp), %edi
addl $0x3, %edi
xorl %esi, %esi
callq 0x71e0
jmp 0x7a82
movq 0xaa557(%rip), %rax     # 0xb1fe0
movq (%rax), %rdi
callq 0x7300
jmp 0x7a93
leaq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7650
jmp 0x7aa2
jmp 0x7aa4
movl -0x30(%rbp), %edi
addl $0x2, %edi
leaq 0x8c5e2(%rip), %rdx     # 0x94093
xorl %esi, %esi
movb %sil, %al
callq 0x73d0
jmp 0x7abd
jmp 0x7abf
leaq -0x30(%rbp), %rdi
callq 0x8240
movl %eax, -0x134(%rbp)
jmp 0x7ad0
movl -0x134(%rbp), %eax
movl %eax, -0x124(%rbp)
cmpl $0x72, %eax
je 0x7b0e
movl -0x124(%rbp), %edi
callq 0x7620
testb $0x1, %al
jne 0x7af9
cmpl $-0x1, -0x124(%rbp)
jne 0x7b0c
movl $0x0, -0x4(%rbp)
movl $0x1, -0x100(%rbp)
jmp 0x7b18
jmp 0x7abf
movl $0x0, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x82a0
movl -0x100(%rbp), %eax
testl %eax, %eax
jne 0x7b35
jmp 0x7b30
jmp 0x7891
leaq -0x68(%rbp), %rdi
callq 0xadf0
leaq -0x30(%rbp), %rdi
callq 0x82c0
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0xadf0
leaq -0x30(%rbp), %rdi
callq 0x82c0
movq -0x70(%rbp), %rdi
callq 0x7500
nop