// File: /workspace/github_cpp_makefile_star2_O2/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 $0x108, %rsp            # imm = 0x108
movq 0x7910(%rip), %rbx      # 0xa248
leaq 0x38d7(%rip), %rsi      # 0x6216
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2110
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq %rbx, %rsi
callq 0x561c
leaq 0x88(%rsp), %rdi
callq 0x2130
leaq 0x38bb(%rip), %rsi      # 0x6238
leaq 0x28(%rsp), %rbx
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x2110
leaq 0x48(%rsp), %r15
leaq 0x38b6(%rip), %rsi      # 0x6251
leaq 0x3(%rsp), %rdx
movq %r15, %rdi
callq 0x2110
leaq 0x68(%rsp), %r15
leaq 0x38bc(%rip), %rsi      # 0x6270
leaq 0x2(%rsp), %rdx
movq %r15, %rdi
callq 0x2110
leaq 0xa8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
pushq $0x3
popq %rdx
callq 0x5652
pushq $0x40
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x28, %rdi
callq 0x2130
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x29d9
leaq 0xe8(%rsp), %rdi
leaq 0x308(%rip), %rsi       # 0x2d07
callq 0x415c
leaq 0xa8(%rsp), %rdi
callq 0x5688
movl %eax, %ebp
testl %eax, %eax
je 0x2a64
cmpl $0x1, %ebp
je 0x2a43
cmpl $0x2, %ebp
jne 0x2a83
pushq $0x58
popq %rdi
callq 0x2210
movq %rax, %rbx
movq 0x7815(%rip), %rsi      # 0xa248
pushq $0x10
popq %rdx
pushq $0x1e
popq %rcx
movq %rax, %rdi
callq 0x488c
jmp 0x2a83
pushq $0x58
popq %rdi
callq 0x2210
movq %rax, %rbx
movq 0x77f3(%rip), %rsi      # 0xa248
pushq $0x10
popq %rcx
movq %rax, %rdi
movl %ecx, %edx
callq 0x488c
jmp 0x2a83
pushq $0x58
popq %rdi
callq 0x2210
movq %rax, %rbx
movq 0x77d2(%rip), %rsi      # 0xa248
pushq $0x9
popq %rcx
movq %rax, %rdi
movl %ecx, %edx
callq 0x488c
movq %rbx, %rdi
callq 0x492e
callq 0x2330
callq 0x20c0
callq 0x2280
movq %rbx, %rdi
callq 0x5276
testb $0x1, (%rax)
je 0x2c14
movl 0x4(%rax), %eax
movslq %ebp, %rcx
imulq $0x18, %rcx, %r14
leaq 0x7794(%rip), %rcx      # 0xa250
addq %rcx, %r14
movq (%r14), %rcx
cmpl 0x4c(%rcx), %eax
jge 0x2c14
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
leaq 0x18(%rsp), %rdi
movq %rcx, (%rdi)
movl $0x202020, 0x7(%rdi)    # imm = 0x202020
movl %eax, 0xc(%rdi)
callq 0x30ee
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x41ae
movq (%r14), %r15
movq 0x8(%r14), %r14
cmpq %r14, %r15
je 0x2b5b
movq %r14, %rax
subq %r15, %rax
sarq $0x4, %rax
incq %rax
pushq $0x2
popq %rcx
cqto
idivq %rcx
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x43ec
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
je 0x2b46
movq 0x30(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x3680
jmp 0x2b51
movq %r15, %rdi
movq %r14, %rsi
callq 0x3603
movq 0x38(%rsp), %rdi
callq 0x21d0
movq %rbx, 0x8(%rsp)
leaq 0x372d(%rip), %rdi      # 0x6294
leaq 0x3731(%rip), %rsi      # 0x629f
callq 0x22b0
movq %rax, %r14
movq %rax, %rdi
callq 0x2250
pushq $0x2
popq %rsi
movl %eax, 0x4(%rsp)
movl %eax, %edi
callq 0x23f0
xorl %eax, %eax
pushq $0xb
popq %r15
pushq $0x1
popq %r12
pushq $0x4
popq %r13
cmpq $0x3, %rax
je 0x2bfb
movq %rax, 0x10(%rsp)
imulq $0x18, %rax, %rbp
leaq 0x76a0(%rip), %rax      # 0xa250
addq %rax, %rbp
pushq $0xc
popq %rbx
cmpq $0x5c, %rbx
je 0x2bf1
movq (%rbp), %rax
leaq (%rax,%rbx), %rdi
addq $-0xc, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2400
movq (%rbp), %rdi
addq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2400
addq $0x10, %rbx
jmp 0x2bb6
movq 0x10(%rsp), %rax
incq %rax
jmp 0x2b9a
pushq $0x8
popq %rsi
movl 0x4(%rsp), %edi
callq 0x23f0
movq %r14, %rdi
callq 0x2200
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4924
movq %rbx, %rdi
callq 0x21d0
callq 0x23c0
callq 0x2d07
movq 0x73a3(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x20f0
leaq 0xa8(%rsp), %rdi
callq 0x413c
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x38(%rsp), %rdi
jmp 0x2c70
jmp 0x2c6a
jmp 0x2c6a
movq %rax, %r14
movq %rbx, %rdi
callq 0x21d0
jmp 0x2cd2
jmp 0x2ccf
jmp 0x2ccf
jmp 0x2ccf
movq %rax, %r14
pushq $0x40
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x28, %rdi
callq 0x2130
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x2c83
jmp 0x2cd2
jmp 0x2c9e
movq %rax, %r14
addq $-0x20, %r15
movq %r15, %rdi
callq 0x2130
cmpq %rbx, %r15
jne 0x2ca1
jmp 0x2cd2
jmp 0x2ccf
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x2130
jmp 0x2cdf
movq %rax, %r14
jmp 0x2cdf
jmp 0x2ccf
movq %rax, %r14
leaq 0xa8(%rsp), %rdi
callq 0x413c
movq %r14, %rdi
callq 0x23d0