// File: Dalgona[P]mine/mine.cpp
// Function: arcade_leaderboard()
void arcade_leaderboard(void)
{
  FILE *data = fopen("scores.dat", "rb");
  int fd = fileno(data);
  flock(fd, LOCK_EX);
  for (int i = 0; i < 3; i++)
  {
    scores[i].resize(5);
    for (int j = 0; j < 5; j++)
    {
      fread(scores[i][j].name, 11, 1, data);
      fread(&scores[i][j].time, 4, 1, data);
    }
  }
  flock(fd, LOCK_UN);
  fclose(data);

  refresh();
  WINDOW *lbw = newwin(9, 78, 8, 1);

  wattron(lbw, A_BOLD);
  LBC(14, mvwprintw(lbw, 0, 27, " H A L L   O F   F A M E "););
  LBC(15, mvwprintw(lbw, 2, 8, "BEGINNER"););
  LBC(16, mvwprintw(lbw, 2, 33, "INTERMEDIATE"););
  LBC(17, mvwprintw(lbw, 2, 63, "EXPERT"););
  wattroff(lbw, A_BOLD);

  const char *nth[] { "1st", "2nd", "3rd", "4th", "5th" };
  int iPart, dPart;
  for (int i = 0; i < 3; i++)
  {
    int col = 27 * i;
    for (int j = 0; j < 5; j++)
    {
      score_t &sc = scores[i][j];
      if (sc.time > 999999) iPart = 9999, dPart = 99;
      else iPart = sc.time / 100, dPart = sc.time % 100;
      LBC(20 + j, mvwprintw(lbw, 4 + j, col, "%s", nth[j]););
      wprintw(lbw, "  %10s  %04d.%02d", sc.name, iPart, dPart);
    }
  }

  wrefresh(lbw);
  delwin(lbw);
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
leaq 0xedc7(%rip), %rdi      # 0x12325
leaq 0xedce(%rip), %rsi      # 0x12333
callq 0x2300
movq %rax, 0x1e0(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x2290
movl %eax, 0x1dc(%rsp)
movl 0x1dc(%rsp), %edi
movl $0x2, %esi
callq 0x2430
movl $0x0, 0x1d8(%rsp)
cmpl $0x3, 0x1d8(%rsp)
jge 0x3695
movslq 0x1d8(%rsp), %rax
leaq 0x16cb1(%rip), %rdi     # 0x1a270
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl $0x5, %esi
callq 0x8bf0
movl $0x0, 0x1d4(%rsp)
cmpl $0x5, 0x1d4(%rsp)
jge 0x367d
movslq 0x1d8(%rsp), %rax
leaq 0x16c78(%rip), %rdi     # 0x1a270
imulq $0x18, %rax, %rax
addq %rax, %rdi
movslq 0x1d4(%rsp), %rsi
callq 0x8b00
movq %rax, %rdi
movq 0x1e0(%rsp), %rcx
movl $0xb, %esi
movl $0x1, %edx
callq 0x2380
movslq 0x1d8(%rsp), %rax
leaq 0x16c3b(%rip), %rdi     # 0x1a270
imulq $0x18, %rax, %rax
addq %rax, %rdi
movslq 0x1d4(%rsp), %rsi
callq 0x8b00
movq %rax, %rdi
addq $0xc, %rdi
movq 0x1e0(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2380
movl 0x1d4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1d4(%rsp)
jmp 0x35db
jmp 0x367f
movl 0x1d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1d8(%rsp)
jmp 0x35a2
movl 0x1dc(%rsp), %edi
movl $0x8, %esi
movl %esi, 0x74(%rsp)
callq 0x2430
movq 0x1e0(%rsp), %rdi
callq 0x2240
callq 0x23e0
movl 0x74(%rsp), %edx
movl $0x9, %edi
movl $0x4e, %esi
movl $0x1, %ecx
callq 0x2260
movq %rax, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x200000, %esi         # imm = 0x200000
callq 0x2140
movq 0x16b6f(%rip), %rax     # 0x1a268
movq %rax, 0x78(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x1c8(%rsp), %rax
movq %rax, 0x1a0(%rsp)
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x88(%rsp)
leaq 0x1a0(%rsp), %rsi
callq 0x3f50
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rcx
movl $0xe, %edx
callq 0x11400
jmp 0x375c
leaq 0x1a8(%rsp), %rdi
callq 0x8c90
movq 0x16af8(%rip), %rax     # 0x1a268
movq %rax, 0x58(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x1c8(%rsp), %rax
movq %rax, 0x168(%rsp)
leaq 0x170(%rsp), %rdi
movq %rdi, 0x68(%rsp)
leaq 0x168(%rsp), %rsi
callq 0x3fe0
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rcx
movl $0xf, %edx
callq 0x11400
jmp 0x37c7
leaq 0x170(%rsp), %rdi
callq 0x8c90
movq 0x16a8d(%rip), %rax     # 0x1a268
movq %rax, 0x40(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x1c8(%rsp), %rax
movq %rax, 0x140(%rsp)
leaq 0x148(%rsp), %rdi
movq %rdi, 0x50(%rsp)
leaq 0x140(%rsp), %rsi
callq 0x4070
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rcx
movl $0x10, %edx
callq 0x11400
jmp 0x3832
leaq 0x148(%rsp), %rdi
callq 0x8c90
movq 0x16a22(%rip), %rax     # 0x1a268
movq %rax, 0x28(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x1c8(%rsp), %rax
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
movq %rdi, 0x38(%rsp)
leaq 0x118(%rsp), %rsi
callq 0x4100
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rcx
movl $0x11, %edx
callq 0x11400
jmp 0x389d
leaq 0x120(%rsp), %rdi
callq 0x8c90
movq 0x1c8(%rsp), %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %eax, %eax
movl %eax, %edx
callq 0x2320
leaq 0xf0(%rsp), %rdi
leaq 0x16331(%rip), %rsi     # 0x19c00
movl $0x28, %edx
callq 0x21d0
movl $0x0, 0xe4(%rsp)
cmpl $0x3, 0xe4(%rsp)
jge 0x3b67
imull $0x1b, 0xe4(%rsp), %eax
movl %eax, 0xe0(%rsp)
movl $0x0, 0xdc(%rsp)
cmpl $0x5, 0xdc(%rsp)
jge 0x3b4f
movslq 0xe4(%rsp), %rax
leaq 0x16947(%rip), %rdi     # 0x1a270
imulq $0x18, %rax, %rax
addq %rax, %rdi
movslq 0xdc(%rsp), %rsi
callq 0x8b00
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
cmpl $0xf423f, 0xc(%rax)     # imm = 0xF423F
jle 0x3a0d
movl $0x270f, 0xec(%rsp) # imm = 0x270F
movl $0x63, 0xe8(%rsp)
jmp 0x3a41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x8c90
jmp 0x3b89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x8c90
jmp 0x3b89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x8c90
jmp 0x3b89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x8c90
jmp 0x3b89
movq 0xd0(%rsp), %rax
movl 0xc(%rax), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, 0xec(%rsp)
movq 0xd0(%rsp), %rax
movl 0xc(%rax), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %edx, 0xe8(%rsp)
movq 0x16820(%rip), %rax     # 0x1a268
movq %rax, 0x8(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0xdc(%rsp), %eax
addl $0x14, %eax
movl %eax, 0x1c(%rsp)
leaq 0x1c8(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0xdc(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x90(%rsp), %rsi
callq 0x4190
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x1c(%rsp), %edx
movq 0x20(%rsp), %rcx
callq 0x11400
jmp 0x3adc
leaq 0xb0(%rsp), %rdi
callq 0x8c90
movq 0x1c8(%rsp), %rdi
movq 0xd0(%rsp), %rdx
movl 0xec(%rsp), %ecx
movl 0xe8(%rsp), %r8d
leaq 0xe83b(%rip), %rsi      # 0x1234a
movb $0x0, %al
callq 0x2050
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x390c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x8c90
jmp 0x3b89
jmp 0x3b51
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x38e4
movq 0x1c8(%rsp), %rdi
callq 0x22b0
movq 0x1c8(%rsp), %rdi
callq 0x2060
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq 0x198(%rsp), %rdi
callq 0x2400
nopw %cs:(%rax,%rax)