// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %edi, %edi
callq 0x7260
movl %eax, %edi
callq 0x7290
leaq 0x64921(%rip), %r15     # 0x6c042
leaq 0x64930(%rip), %r14     # 0x6c058
movq 0x818a1(%rip), %r12     # 0x88fd0
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x7080
cmpl $-0x1, %eax
je 0x774c
cmpl $0x64, %eax
jne 0x772f
movq (%r12), %r15
jmp 0x772f
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movl $0x28, %esi
movl $0x14, %edx
callq 0x7a38
movl (%r14), %edx
decl %edx
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x8af0
leaq 0x88(%rsp), %rbx
movsd 0x64883(%rip), %xmm1    # 0x6c008
movabsq $-0x4016666666666666, %rbp # imm = 0xBFE999999999999A
leaq 0x68(%rsp), %r12
leaq 0x648c3(%rip), %r13     # 0x6c05e
movq %r14, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
movq %rbp, 0x78(%rsp)
movq %r14, 0x80(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8032
movq %r12, %rdi
callq 0x7a8c
movl %eax, %r15d
testl %eax, %eax
js 0x7972
movl 0x8(%rsp), %edi
incl %edi
xorl %esi, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x7390
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x760b
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
callq 0x8bf8
testb %al, %al
je 0x791b
movq 0x817c7(%rip), %rax     # 0x88fe0
movq (%rax), %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x7160
movl 0x8(%rsp), %edi
addl $0x2, %edi
xorl %esi, %esi
leaq 0x64831(%rip), %rdx     # 0x6c069
xorl %eax, %eax
callq 0x7390
movl 0x8(%rsp), %edi
addl $0x3, %edi
xorl %esi, %esi
leaq 0x64831(%rip), %rdx     # 0x6c080
xorl %eax, %eax
callq 0x7390
movq 0x81783(%rip), %rax     # 0x88fe0
movq (%rax), %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x7380
movq %r12, %rbx
movq %rbp, %r12
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x1f(%rsp)
movl 0x8(%rsp), %esi
addl $0x3, %esi
movl $0x17, %r8d
movq %r14, %rdi
movl $0xc, %edx
leaq 0x10(%rsp), %rcx
callq 0x7cae
movl %eax, %ebp
testb %al, %al
je 0x796a
cmpb $0x0, 0x10(%rsp)
jne 0x78cc
movabsq $0x6f6d796e6f6e6128, %rax # imm = 0x6F6D796E6F6E6128
movq %rax, 0x10(%rsp)
movl $0x297375, 0x18(%rsp)   # imm = 0x297375
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl %r15d, %edx
callq 0x8c3a
movl 0x8(%rsp), %edi
addl $0x3, %edi
xorl %esi, %esi
callq 0x71a0
movq 0x816ed(%rip), %rax     # 0x88fe0
movq (%rax), %rdi
callq 0x72e0
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x760b
testb %bpl, %bpl
movq %r12, %rbp
movq %rbx, %r12
leaq 0x88(%rsp), %rbx
je 0x7972
movl 0x8(%rsp), %edi
addl $0x2, %edi
xorl %esi, %esi
leaq 0x6476e(%rip), %rdx     # 0x6c099
xorl %eax, %eax
callq 0x7390
movq %r14, %rdi
callq 0x7e92
cmpl $0x70, %eax
jg 0x794b
cmpl $-0x1, %eax
je 0x7972
cmpl $0x3, %eax
jne 0x7932
jmp 0x7972
cmpl $0x71, %eax
je 0x7972
cmpl $0x72, %eax
jne 0x7932
movq %rbx, %rdi
callq 0x8492
movsd 0x646a3(%rip), %xmm1    # 0x6c008
jmp 0x779b
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x8492
leaq 0x30(%rsp), %rdi
callq 0x8bde
leaq 0x8(%rsp), %rdi
callq 0x7ece
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x79ca
movq %rax, %r14
jmp 0x79c0
jmp 0x79b0
jmp 0x79b0
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x8492
leaq 0x30(%rsp), %rdi
callq 0x8bde
leaq 0x8(%rsp), %rdi
callq 0x7ece
movq %r14, %rdi
callq 0x74b0