// File: /workspace/github_cpp_makefile_star2_O1/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 0x8836(%rip), %rbx      # 0xb248
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x47f4(%rip), %rsi      # 0x7216
leaq 0x480e(%rip), %rdx      # 0x7237
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x4744
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x5cd4
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x2a58
callq 0x21e0
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x47d0(%rip), %rsi      # 0x7238
leaq 0x47e1(%rip), %rdx      # 0x7250
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4744
leaq 0x28(%rsp), %r14
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x47c0(%rip), %rsi      # 0x7251
leaq 0x47d7(%rip), %rdx      # 0x726f
movq %r14, %rdi
callq 0x4744
leaq 0x48(%rsp), %r14
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x47ba(%rip), %rsi      # 0x7270
leaq 0x47cb(%rip), %rdx      # 0x7288
movq %r14, %rdi
callq 0x4744
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x3, %edx
callq 0x5d1a
leaq 0x58(%rsp), %rbx
xorl %r14d, %r14d
movq 0x48(%rsp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x2af7
callq 0x21e0
addq $-0x20, %r14
cmpq $-0x60, %r14
jne 0x2ae4
leaq 0xc8(%rsp), %r12
leaq 0x390(%rip), %rsi       # 0x2ea0
movq %r12, %rdi
callq 0x4642
leaq 0x88(%rsp), %rdi
callq 0x5d50
movl %eax, %ebp
testl %eax, %eax
je 0x2b85
cmpl $0x1, %ebp
je 0x2b5d
cmpl $0x2, %ebp
jne 0x2bab
movl $0x58, %edi
callq 0x2220
movq %rax, %r14
movq 0x86ff(%rip), %rsi      # 0xb248
movq %rax, %rdi
movl $0x10, %edx
movl $0x1e, %ecx
callq 0x4d84
jmp 0x2bab
movl $0x58, %edi
callq 0x2220
movq %rax, %r14
movq 0x86d7(%rip), %rsi      # 0xb248
movq %rax, %rdi
movl $0x10, %edx
movl $0x10, %ecx
callq 0x4d84
jmp 0x2bab
movl $0x58, %edi
callq 0x2220
movq %rax, %r14
movq 0x86af(%rip), %rsi      # 0xb248
movq %rax, %rdi
movl $0x9, %edx
movl $0x9, %ecx
callq 0x4d84
movq %r14, %rdi
callq 0x4f68
callq 0x2320
callq 0x20c0
callq 0x2290
movq %r14, %rdi
callq 0x5a0c
testb $0x1, (%rax)
je 0x2d39
movl 0x4(%rax), %eax
movslq %ebp, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x866c(%rip), %rbx      # 0xb250
leaq (%rbx,%rcx,8), %r15
movq (%r15), %rcx
cmpl 0x4c(%rcx), %eax
jge 0x2d39
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
leaq 0x8(%rsp), %rdi
movq %rcx, (%rdi)
movl $0x202020, 0x7(%rdi)    # imm = 0x202020
movl %eax, 0xc(%rdi)
callq 0x339f
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x2c2e
movups 0x8(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r15)
jmp 0x2c3b
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x47f8
movq (%r15), %r13
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x2c96
movq %r15, %rax
subq %r13, %rax
sarq $0x4, %rax
leaq 0x1(%rax), %rcx
shrq $0x3f, %rcx
leaq (%rax,%rcx), %rdi
incq %rdi
sarq %rdi
callq 0x4933
movq %rax, %r12
testq %rax, %rax
je 0x2c83
movq %rdx, %rcx
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3ab0
jmp 0x2c8e
movq %r13, %rdi
movq %r15, %rsi
callq 0x3a33
movq %r12, %rdi
callq 0x21e0
leaq 0x45f7(%rip), %rdi      # 0x7294
leaq 0x45fb(%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 0x2cd1
incq %r12
cmpq $0x3, %r12
jne 0x2cc7
movl 0x4(%rsp), %edi
movl $0x8, %esi
callq 0x23f0
movq %r15, %rdi
callq 0x2210
leaq 0xc8(%rsp), %r12
movq %r14, %rdi
callq 0x4f5a
movq %r14, %rdi
callq 0x21e0
callq 0x23b0
callq 0x2ea0
movq 0x827e(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x20f0
movq 0xd8(%rsp), %rax
testq %rax, %rax
je 0x2d7c
movq %r12, %rdi
movq %r12, %rsi
movl $0x3, %edx
callq *%rax
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
callq 0x46f6
movq -0x20(%rbx), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x2da2
callq 0x21e0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r12, %rdi
jmp 0x2dc6
jmp 0x2dc0
jmp 0x2dc0
movq %rax, %rbx
movq %r14, %rdi
callq 0x21e0
jmp 0x2e6b
jmp 0x2e68
movq %rax, %rdi
callq 0x4739
jmp 0x2e68
jmp 0x2e68
movq %rax, %rbx
movq $-0x60, %r13
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x2e00
callq 0x21e0
addq $-0x20, %r12
addq $0x20, %r13
jne 0x2df1
movb $0x1, %al
jmp 0x2e1f
jmp 0x2e10
movq %rax, %rbx
xorl %eax, %eax
jmp 0x2e1f
movq %rax, %rbx
xorl %eax, %eax
movq %r15, %r14
cmpq %r14, %r15
sete %cl
orb %al, %cl
jne 0x2e6b
addq $-0x10, %r14
leaq 0x8(%rsp), %r15
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x2e40
callq 0x21e0
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %r15, %r14
movq %rax, %r14
jne 0x2e32
jmp 0x2e6b
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e78
callq 0x21e0
jmp 0x2e78
jmp 0x2e68
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4602
movq %rbx, %rdi
callq 0x23c0