// File: /workspace/github_cpp_makefile_star2_O2/Dalgona[P]mine/mine.cpp
// Function: name_input(score_t&)
void name_input(score_t &score)
{
  int pos = 0;
  int ch;

  curs_set(0);
  WINDOW *nameWin;
  auto drawForm = [&]()
  {
    clear();
    refresh();
    nameWin = newwin(13, 39, scr->getRows() / 2 - 6, scr->getCols() / 2 - 19);
    wattron(nameWin, A_BOLD);
    NIC(18, mvwprintw(nameWin, 0, 5, "C O N G R A T U L A T I O N S"););
    NIC(19, mvwprintw(nameWin, 2, 4, "A   N E W   H I G H   S C O R E"););
    wattroff(nameWin, A_BOLD);
    NIC(11, mvwprintw(nameWin, 4, 0, "What is your name?");
           mvwprintw(nameWin, 8, 0, "Accepted Characters: A-Z, 0-9 and SPACE"););
    NIC(23, mvwprintw(nameWin, 12, 5, "BkSp: ERASE     Enter: DECIDE"););
  };
  drawForm();

  while (true)
  {
    for (int i = 0; i < pos; i++)
      NIC(31, mvwprintw(nameWin, 6, 4 * i, " %c ", score.name[i]););
    for (int i = pos; i < 10; i++)
      NIC(30, mvwprintw(nameWin, 6, 4 * i, " %c ", score.name[i]););
    wrefresh(nameWin);
    ch = getch();
    if ((ch >= 'A' && ch <= 'Z')
        || (ch >= '0' && ch <= '9')
        || ch == ' ')
    { if (pos < 10) score.name[pos++] = ch; }
    else if (ch >= 'a' && ch <= 'z')
    { if (pos < 10) score.name[pos++] = ch - 32; }
    else if (ch == 8 || ch == KEY_BACKSPACE)
    { if (pos != 0) score.name[--pos] = ' '; }
    else if (ch == KEY_RESIZE)
    { scr->updateMaxYX(); delwin(nameWin); drawForm(); }
    else if (ch == 10)
      break;
  }

  delwin(nameWin);
  curs_set(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x2190
leaq 0x8(%rsp), %rax
leaq 0x50(%rsp), %rdi
movq %rax, (%rdi)
callq 0x3338
leaq 0x30(%rsp), %r12
leaq 0x10(%rsp), %r14
xorl %eax, %eax
movl %eax, 0x4(%rsp)
cmpl %r15d, %eax
jge 0x31a4
movq 0x7111(%rip), %rbp      # 0xa248
movq 0x8(%rsp), %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
pushq $0x18
popq %rdi
callq 0x2210
leaq 0x8(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x4(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x30(%rsp)
leaq 0xeaa(%rip), %rax       # 0x401c
movq %rax, 0x48(%rsp)
leaq 0xed0(%rip), %rax       # 0x404e
movq %rax, 0x40(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
pushq $0x1f
popq %rdx
movq %r12, %rcx
callq 0x5e58
movq %r12, %rdi
callq 0x4200
movl 0x4(%rsp), %eax
incl %eax
jmp 0x3127
movl %r15d, %eax
movl %eax, 0x4(%rsp)
cmpl $0xa, %eax
jge 0x3224
movq 0x7091(%rip), %r13      # 0xa248
movq 0x8(%rsp), %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
pushq $0x18
popq %rdi
callq 0x2210
leaq 0x8(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x4(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x10(%rsp)
leaq 0xeba(%rip), %rax       # 0x40ac
movq %rax, 0x28(%rsp)
leaq 0xee0(%rip), %rax       # 0x40de
movq %rax, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
pushq $0x1e
popq %rdx
movq %r14, %rcx
callq 0x5e58
movq %r14, %rdi
callq 0x4200
movl 0x4(%rsp), %eax
incl %eax
jmp 0x31a7
movq 0x8(%rsp), %rdi
callq 0x2260
movq 0x6da3(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x20f0
leal -0x41(%rax), %edx
movslq %r15d, %rcx
cmpl $0x1a, %edx
jb 0x325d
leal -0x30(%rax), %edx
cmpl $0xa, %edx
setae %dl
cmpl $0x20, %eax
setne %sil
testb %dl, %sil
jne 0x3272
cmpl $0x9, %r15d
jg 0x3125
incl %r15d
movb %al, (%rbx,%rcx)
jmp 0x3125
leal -0x61(%rax), %edx
cmpl $0x19, %edx
ja 0x3292
cmpl $0x9, %r15d
jg 0x3125
addl $-0x20, %eax
incl %r15d
movb %al, (%rbx,%rcx)
jmp 0x3125
cmpl $0x8, %eax
je 0x32b0
cmpl $0x107, %eax            # imm = 0x107
je 0x32b0
cmpl $0x19a, %eax            # imm = 0x19A
je 0x32cf
cmpl $0xa, %eax
jne 0x3125
jmp 0x32f4
testl %r15d, %r15d
movl $0x0, %r15d
je 0x3125
movb $0x20, -0x1(%rbx,%rcx)
decq %rcx
movl %ecx, %r15d
jmp 0x3125
movq 0x6f72(%rip), %rdi      # 0xa248
callq 0x5c6c
movq 0x8(%rsp), %rdi
callq 0x2060
leaq 0x50(%rsp), %rdi
callq 0x3338
jmp 0x3125
movq 0x8(%rsp), %rdi
callq 0x2060
pushq $0x1
popq %rdi
callq 0x2190
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3317
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x332b
jmp 0x3323
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x4200
movq %rbx, %rdi
callq 0x23d0