// File: 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:
subq $0x238, %rsp            # imm = 0x238
movq 0x1755a(%rip), %rax     # 0x1a268
movq %rax, 0xb8(%rsp)
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x2410
movq 0xc0(%rsp), %rdx
leaq 0xf56d(%rip), %rsi      # 0x122a7
leaq 0x1b8(%rsp), %rdi
callq 0x2340
jmp 0x2d49
movq 0xb8(%rsp), %rsi
leaq 0x1d8(%rsp), %rdi
leaq 0x1b8(%rsp), %rdx
callq 0xf400
jmp 0x2d68
leaq 0x1b8(%rsp), %rdi
callq 0x2180
leaq 0x1b7(%rsp), %rdi
callq 0x22a0
movb $0x1, 0x124(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq %rax, 0x128(%rsp)
leaq 0x127(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x2410
movq 0xa8(%rsp), %rdi
movq 0xb0(%rsp), %rdx
leaq 0xf4fb(%rip), %rsi      # 0x122c9
callq 0x2340
jmp 0x2dd5
leaq 0x150(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %rax, 0x128(%rsp)
leaq 0x126(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x2410
movq 0x98(%rsp), %rdi
movq 0xa0(%rsp), %rdx
leaq 0xf4c9(%rip), %rsi      # 0x122e2
callq 0x2340
jmp 0x2e20
leaq 0x170(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %rax, 0x128(%rsp)
leaq 0x125(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x2410
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rdx
leaq 0xf49d(%rip), %rsi      # 0x12301
callq 0x2340
jmp 0x2e6b
movb $0x0, 0x124(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0x190(%rsp)
movq $0x3, 0x198(%rsp)
movq 0x190(%rsp), %rsi
movq 0x198(%rsp), %rdx
leaq 0x1d8(%rsp), %rdi
callq 0xf460
jmp 0x2eae
leaq 0x130(%rsp), %rax
movq %rax, 0x78(%rsp)
addq $0x60, %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rdi
addq $-0x20, %rdi
movq %rdi, 0x70(%rsp)
callq 0x2180
movq 0x78(%rsp), %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x80(%rsp)
jne 0x2ec7
leaq 0x125(%rsp), %rdi
callq 0x22a0
leaq 0x126(%rsp), %rdi
callq 0x22a0
leaq 0x127(%rsp), %rdi
callq 0x22a0
leaq 0x218(%rsp), %rdi
leaq 0x626(%rip), %rsi       # 0x3550
callq 0x8ab0
leaq 0x1d8(%rsp), %rdi
callq 0xf4f0
movl %eax, 0x6c(%rsp)
jmp 0x2f42
movl 0x6c(%rsp), %eax
movl %eax, 0x120(%rsp)
movl 0x120(%rsp), %eax
movl %eax, 0x68(%rsp)
testl %eax, %eax
je 0x30fb
jmp 0x2f62
movl 0x68(%rsp), %eax
subl $0x1, %eax
je 0x315b
jmp 0x2f71
movl 0x68(%rsp), %eax
subl $0x2, %eax
je 0x31bb
jmp 0x321b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
jmp 0x2fba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x2180
leaq 0x1b7(%rsp), %rdi
callq 0x22a0
jmp 0x350a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
jmp 0x307e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
jmp 0x3071
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
jmp 0x3064
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0x58(%rsp)
addq $0x60, %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
addq $-0x20, %rdi
movq %rdi, 0x50(%rsp)
callq 0x2180
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x60(%rsp)
jne 0x303b
jmp 0x3064
leaq 0x125(%rsp), %rdi
callq 0x22a0
leaq 0x126(%rsp), %rdi
callq 0x22a0
leaq 0x127(%rsp), %rdi
callq 0x22a0
testb $0x1, 0x124(%rsp)
jne 0x3097
jmp 0x30dd
movq 0x128(%rsp), %rax
leaq 0x130(%rsp), %rcx
cmpq %rax, %rcx
movq %rax, 0x48(%rsp)
je 0x30db
movq 0x48(%rsp), %rdi
addq $-0x20, %rdi
movq %rdi, 0x40(%rsp)
callq 0x2180
movq 0x40(%rsp), %rax
leaq 0x130(%rsp), %rcx
cmpq %rcx, %rax
movq %rax, 0x48(%rsp)
jne 0x30b1
jmp 0x30dd
jmp 0x34fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
jmp 0x34fd
movl $0x58, %edi
callq 0x2250
movq %rax, 0x38(%rsp)
jmp 0x310c
movq 0x38(%rsp), %rdi
movq 0x17150(%rip), %rsi     # 0x1a268
movl $0x9, %ecx
movl %ecx, %edx
callq 0xb9a0
jmp 0x3126
movq 0x38(%rsp), %rax
movq %rax, 0x118(%rsp)
jmp 0x321b
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
callq 0x2210
jmp 0x34fd
movl $0x58, %edi
callq 0x2250
movq %rax, 0x30(%rsp)
jmp 0x316c
movq 0x30(%rsp), %rdi
movq 0x170f0(%rip), %rsi     # 0x1a268
movl $0x10, %ecx
movl %ecx, %edx
callq 0xb9a0
jmp 0x3186
movq 0x30(%rsp), %rax
movq %rax, 0x118(%rsp)
jmp 0x321b
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
callq 0x2210
jmp 0x34fd
movl $0x58, %edi
callq 0x2250
movq %rax, 0x28(%rsp)
jmp 0x31cc
movq 0x28(%rsp), %rdi
movq 0x17090(%rip), %rsi     # 0x1a268
movl $0x10, %edx
movl $0x1e, %ecx
callq 0xb9a0
jmp 0x31e9
movq 0x28(%rsp), %rax
movq %rax, 0x118(%rsp)
jmp 0x321b
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
callq 0x2210
jmp 0x34fd
movq 0x118(%rsp), %rdi
callq 0xbb60
jmp 0x322a
callq 0x2370
jmp 0x3231
callq 0x20c0
jmp 0x3238
callq 0x22d0
jmp 0x323f
movq 0x118(%rsp), %rdi
callq 0xcfc0
movq %rax, 0x20(%rsp)
jmp 0x3253
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x110(%rsp)
movslq 0x120(%rsp), %rcx
leaq 0x16ffe(%rip), %rax     # 0x1a270
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x108(%rsp)
testb $0x1, 0x110(%rsp)
je 0x34a2
movl 0x114(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x108(%rsp), %rdi
movl $0x4, %esi
callq 0x8b00
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl 0xc(%rcx), %eax
jge 0x34a2
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0xf8(%rsp)
movl $0x202020, 0xff(%rsp) # imm = 0x202020
movl 0x114(%rsp), %eax
movl %eax, 0x104(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x3ba0
jmp 0x32f6
movq 0x108(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x8b20
jmp 0x330d
movq 0x108(%rsp), %rdi
callq 0x8b90
movq %rax, 0xf0(%rsp)
movq 0x108(%rsp), %rdi
callq 0x8bc0
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x3f10
jmp 0x334e
leaq 0xefd0(%rip), %rdi      # 0x12325
leaq 0xefd4(%rip), %rsi      # 0x12330
callq 0x2300
movq %rax, 0x10(%rsp)
jmp 0x3368
movq 0x10(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x2290
movl %eax, 0xd4(%rsp)
movl 0xd4(%rsp), %edi
movl $0x2, %esi
callq 0x2430
movl $0x0, 0xd0(%rsp)
cmpl $0x3, 0xd0(%rsp)
jge 0x3480
movl $0x0, 0xcc(%rsp)
cmpl $0x5, 0xcc(%rsp)
jge 0x3468
movslq 0xd0(%rsp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x16e91(%rip), %rax     # 0x1a270
leaq (%rax,%rcx,8), %rdi
movslq 0xcc(%rsp), %rsi
callq 0x8b00
movq %rax, %rdi
movq 0xd8(%rsp), %rcx
movl $0xb, %esi
movl $0x1, %edx
callq 0x2440
jmp 0x340c
movslq 0xd0(%rsp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x16e51(%rip), %rax     # 0x1a270
leaq (%rax,%rcx,8), %rdi
movslq 0xcc(%rsp), %rsi
callq 0x8b00
movq %rax, %rdi
addq $0xc, %rdi
movq 0xd8(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2440
jmp 0x3450
jmp 0x3452
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x33be
jmp 0x346a
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x33a5
movl 0xd4(%rsp), %edi
movl $0x8, %esi
callq 0x2430
movq 0xd8(%rsp), %rdi
callq 0x2240
jmp 0x34a0
jmp 0x34a2
movq 0x118(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x34c9
movq 0x8(%rsp), %rdi
callq 0xbb40
movq 0x8(%rsp), %rdi
callq 0x2210
callq 0x23f0
jmp 0x34d0
callq 0x3550
jmp 0x34d7
movq 0x16afa(%rip), %rax     # 0x19fd8
movq (%rax), %rdi
callq 0x20f0
jmp 0x34e8
leaq 0x1d8(%rsp), %rdi
callq 0x8a70
addq $0x238, %rsp            # imm = 0x238
retq
leaq 0x1d8(%rsp), %rdi
callq 0x8a70
movq 0x1a8(%rsp), %rdi
callq 0x2400
nopw (%rax,%rax)