// File: /workspace/github_cpp_makefile_star2_O3/Dalgona[P]mine/mine.cpp
// Function: begin_arcade()
void begin_arcade(void)
{
  menu arcadeMenu(scr, "[ MINESWEEPER ] Select difficulty");
  arcadeMenu.add({
    "Beginner (9x9, 10 mines)",
    "Intermediate (16x16, 45 mines)",
    "Expert (16x30, 99 mines)"
  });
  arcadeMenu.draw = arcade_leaderboard;
  int sel = arcadeMenu.start_menu();
  game *theGame;
  switch (sel)
  {
  case 0: theGame = new game(scr, 9, 9); break;
  case 1: theGame = new game(scr, 16, 16); break;
  case 2: theGame = new game(scr, 16, 30); break;
  }
  theGame->start();

  initscr();
  cbreak();
  noecho();

  auto result = theGame->get_result();
  auto &vec = scores[sel];
  if (result.win && result.time < vec[4].time)
  {
    score_t score { "          ", result.time };
    name_input(score);
    vec.push_back(score);
    std::stable_sort(vec.begin(), vec.end(), [](const score_t &a, const score_t &b)
      {
        return a.time < b.time;
      });
    FILE *data = fopen("scores.dat", "wb");
    int fd = fileno(data);
    flock(fd, LOCK_EX);
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 5; j++)
      {
        fwrite(scores[i][j].name, 11, 1, data);
        fwrite(&scores[i][j].time, 4, 1, data);
      }
    flock(fd, LOCK_UN);
    fclose(data);
  }
  delete theGame;

  clear();
  arcade_leaderboard();

  getch();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq 0x8858(%rip), %rbx      # 0xb248
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4816(%rip), %rsi      # 0x7216
leaq 0x4830(%rip), %rdx      # 0x7237
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x4734
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x5c9c
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x2a36
callq 0x21e0
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x47f2(%rip), %rsi      # 0x7238
leaq 0x4803(%rip), %rdx      # 0x7250
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4734
leaq 0x28(%rsp), %r15
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x47e2(%rip), %rsi      # 0x7251
leaq 0x47f9(%rip), %rdx      # 0x726f
movq %r15, %rdi
callq 0x4734
leaq 0x48(%rsp), %r15
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x47dc(%rip), %rsi      # 0x7270
leaq 0x47ed(%rip), %rdx      # 0x7288
movq %r15, %rdi
callq 0x4734
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x3, %edx
callq 0x5ce2
leaq 0x58(%rsp), %rbx
xorl %r14d, %r14d
movq 0x48(%rsp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x2ad5
callq 0x21e0
addq $-0x20, %r14
cmpq $-0x60, %r14
jne 0x2ac2
leaq 0xc8(%rsp), %r12
leaq 0x370(%rip), %rsi       # 0x2e5e
movq %r12, %rdi
callq 0x4638
leaq 0x88(%rsp), %rdi
callq 0x5d18
movl %eax, %ebp
testl %eax, %eax
je 0x2b63
cmpl $0x1, %ebp
je 0x2b3b
cmpl $0x2, %ebp
jne 0x2b89
movl $0x58, %edi
callq 0x2220
movq %rax, %r14
movq 0x8721(%rip), %rsi      # 0xb248
movq %rax, %rdi
movl $0x10, %edx
movl $0x1e, %ecx
callq 0x4d60
jmp 0x2b89
movl $0x58, %edi
callq 0x2220
movq %rax, %r14
movq 0x86f9(%rip), %rsi      # 0xb248
movq %rax, %rdi
movl $0x10, %edx
movl $0x10, %ecx
callq 0x4d60
jmp 0x2b89
movl $0x58, %edi
callq 0x2220
movq %rax, %r14
movq 0x86d1(%rip), %rsi      # 0xb248
movq %rax, %rdi
movl $0x9, %edx
movl $0x9, %ecx
callq 0x4d60
movq %r14, %rdi
callq 0x4f34
callq 0x2320
callq 0x20c0
callq 0x2290
movq %r14, %rdi
callq 0x59d4
testb $0x1, (%rax)
je 0x2d1e
movl 0x4(%rax), %eax
movslq %ebp, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x868e(%rip), %rbx      # 0xb250
leaq (%rbx,%rcx,8), %r15
movq (%r15), %rcx
cmpl 0x4c(%rcx), %eax
jge 0x2d1e
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
leaq 0x8(%rsp), %rdi
movq %rcx, (%rdi)
movl $0x202020, 0x7(%rdi)    # imm = 0x202020
movl %eax, 0xc(%rdi)
callq 0x3366
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x2c13
movups 0x8(%rsp), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%r15), %r12
addq $0x10, %r12
movq %r12, 0x8(%r15)
jmp 0x2c24
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x47ee
movq 0x8(%r15), %r12
movq (%r15), %r13
cmpq %r12, %r13
je 0x2c7b
movq %r12, %rax
subq %r13, %rax
sarq $0x4, %rax
leaq 0x1(%rax), %rcx
shrq $0x3f, %rcx
leaq (%rax,%rcx), %rdi
incq %rdi
sarq %rdi
callq 0x4929
movq %rax, %r15
testq %rax, %rax
je 0x2c68
movq %rdx, %rcx
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3a76
jmp 0x2c73
movq %r13, %rdi
movq %r12, %rsi
callq 0x39f9
movq %r15, %rdi
callq 0x21e0
leaq 0x4612(%rip), %rdi      # 0x7294
leaq 0x4616(%rip), %rsi      # 0x729f
callq 0x22c0
movq %rax, %r15
movq %rax, %rdi
callq 0x2260
movl %eax, 0x4(%rsp)
movl %eax, %edi
movl $0x2, %esi
callq 0x23f0
xorl %r12d, %r12d
leaq (%r12,%r12,2), %rax
leaq (%rbx,%rax,8), %r13
xorl %ebp, %ebp
movq (%r13), %rdi
addq %rbp, %rdi
movl $0xb, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2400
movq (%r13), %rax
leaq (%rax,%rbp), %rdi
addq $0xc, %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2400
addq $0x10, %rbp
cmpq $0x50, %rbp
jne 0x2cb6
incq %r12
cmpq $0x3, %r12
jne 0x2cac
movl 0x4(%rsp), %edi
movl $0x8, %esi
callq 0x23f0
movq %r15, %rdi
callq 0x2210
leaq 0xc8(%rsp), %r12
movq %r14, %rdi
callq 0x4f26
movq %r14, %rdi
callq 0x21e0
callq 0x23b0
callq 0x2e5e
movq 0x8299(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x20f0
movq 0xd8(%rsp), %rax
testq %rax, %rax
je 0x2d61
movq %r12, %rdi
movq %r12, %rsi
movl $0x3, %edx
callq *%rax
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
callq 0x46e0
movq -0x20(%rbx), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x2d87
callq 0x21e0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
jmp 0x2dab
jmp 0x2da5
jmp 0x2da5
movq %rax, %rbx
movq %r14, %rdi
callq 0x21e0
jmp 0x2e29
jmp 0x2e26
movq %rax, %rdi
callq 0x4729
jmp 0x2e26
jmp 0x2e26
movq %rax, %rbx
movq $-0x60, %r14
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x2dd9
callq 0x21e0
addq $-0x20, %r12
addq $0x20, %r14
jne 0x2dca
jmp 0x2e29
jmp 0x2de7
movq %rax, %rbx
addq $-0x10, %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x2dfc
callq 0x21e0
leaq -0x20(%r15), %rax
addq $-0x10, %r15
cmpq %r14, %r15
movq %rax, %r15
jne 0x2dee
jmp 0x2e29
jmp 0x2e26
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e36
callq 0x21e0
jmp 0x2e36
jmp 0x2e26
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x45f8
movq %rbx, %rdi
callq 0x23c0