// File: /workspace/github_c_makefile_star2_O2/kobolt[P]curses-collection/mastermind/mastermind.c
// Function: main
int main(void)
{
  int user_done, user_quit;

  memset(guess, 0, sizeof(guess_t) * GUESS_SLOTS);
  display_init();
  hidden_code_randomize();

  for (current_guess = GUESS_SLOTS - 1;
       current_guess >= 0;
       current_guess--) {

    /* Wait for user to make a valid guess. */
    current_slot = user_done = user_quit = 0;
    while ((! user_done) && (! user_quit)) {
      display_update(NULL);

      switch (getch()) {
      case KEY_LEFT:
        current_slot--;
        if (current_slot < 0)
          current_slot = 0;
        break;

      case KEY_RIGHT:
        current_slot++;
        if (current_slot >= CODE_SLOTS)
          current_slot = CODE_SLOTS - 1;
        break;

      case KEY_UP:
        guess[current_guess].code[current_slot]++;
        if (guess[current_guess].code[current_slot] > CODE_FOXTROT)
          guess[current_guess].code[current_slot] = CODE_ALPHA;
        break;

      case KEY_DOWN:
        guess[current_guess].code[current_slot]--;
        if (guess[current_guess].code[current_slot] == CODE_NONE ||
            guess[current_guess].code[current_slot] > CODE_FOXTROT)
          guess[current_guess].code[current_slot] = CODE_FOXTROT;
        break;

      case KEY_ENTER:
      case '\n':
      case ' ':
        if (guess_is_completed())
          user_done = 1;
        break;

      case 'q':
      case 'Q':
      case '\e':
        user_quit = 1;
        break;

      default:
        break;
      }
    }

    if (user_quit)
      break;

    evaluate_and_give_hints();

    if (guess_is_correct())
      break;
  }

  if (guess_is_correct()) {
    display_update("Congratulations!");
  } else {
    if (user_quit) {
      display_update("Aborted.");
    } else {
      display_update("Too late!");
    }
  }

  if (! user_quit)
    getch(); /* Press any key... */

  endwin();
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x2e6f(%rip), %rbx      # 0x40d0
movl $0x140, %edx            # imm = 0x140
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10b0
callq 0x1090
callq 0x1030
testb %al, %al
je 0x12cb
callq 0x10c0
pushq $0x1
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1100
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1100
pushq $0x3
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1100
pushq $0x4
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1100
pushq $0x5
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1100
pushq $0x6
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1100
callq 0x1080
movq 0x2d09(%rip), %r14      # 0x3fe0
movq (%r14), %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0x10d0
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x10e0
movl %eax, %edi
callq 0x1060
pushq $0x6
popq %r13
leaq 0x2f20(%rip), %r15      # 0x4220
cmpq $0x10, %r12
je 0x131c
callq 0x10f0
cqto
idivq %r13
incl %edx
movl %edx, (%r12,%r15)
addq $0x4, %r12
jmp 0x1300
pushq $0x9
popq %r12
leaq 0xce9(%rip), %r13       # 0x2010
movl %r12d, 0x2ee2(%rip)     # 0x4210
movb $0x1, %al
movq %rax, 0x8(%rsp)
testl %r12d, %r12d
js 0x152f
andl $0x0, 0x2ecf(%rip)      # 0x4214
xorl %ecx, %ecx
xorl %r12d, %r12d
orl %r12d, %ecx
jne 0x1454
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x158c
movq (%r14), %rdi
callq 0x1070
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
jbe 0x13ba
cmpl $0xa, %eax
je 0x1395
cmpl $0x1b, %eax
je 0x13f0
cmpl $0x20, %eax
je 0x1395
cmpl $0x51, %eax
je 0x13f0
cmpl $0x71, %eax
je 0x13f0
movl $0x0, %ecx
cmpl $0x157, %eax            # imm = 0x157
jne 0x134a
movslq 0x2e74(%rip), %rax      # 0x4210
shlq $0x5, %rax
addq %rbx, %rax
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x13fa
cmpl $0x0, (%rax,%rcx,4)
leaq 0x1(%rcx), %rcx
jne 0x13a5
jmp 0x144d
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movslq 0x2e45(%rip), %rax      # 0x4210
shlq $0x5, %rax
addq %rbx, %rax
movslq 0x2e3b(%rip), %rcx      # 0x4214
movl (%rax,%rcx,4), %edx
leal -0x1(%rdx), %esi
addl $-0x8, %edx
cmpl $-0x6, %edx
pushq $0x6
popq %rdx
cmovbl %edx, %esi
movl %esi, (%rax,%rcx,4)
jmp 0x144d
xorl %ecx, %ecx
movl %ebp, %r12d
jmp 0x134a
movl %ebp, %ecx
jmp 0x134a
movl 0x2e0d(%rip), %eax      # 0x4214
cmpl $0x2, %eax
cmovll %ebp, %eax
decl %eax
jmp 0x1422
movl 0x2dfd(%rip), %eax      # 0x4214
cmpl $0x2, %eax
pushq $0x2
popq %rcx
cmovgel %ecx, %eax
incl %eax
movl %eax, 0x2dec(%rip)      # 0x4214
jmp 0x144d
movslq 0x2ddf(%rip), %rax      # 0x4210
shlq $0x5, %rax
addq %rbx, %rax
movslq 0x2dd5(%rip), %rcx      # 0x4214
movl (%rax,%rcx,4), %edx
incl %edx
cmpl $0x7, %edx
cmovael %ebp, %edx
movl %edx, (%rax,%rcx,4)
xorl %ecx, %ecx
jmp 0x134a
xorl %ecx, %ecx
testl %r12d, %r12d
jne 0x1526
movslq 0x2daa(%rip), %r12      # 0x4210
movq %r12, %rsi
shlq $0x5, %rsi
leaq (%rbx,%rsi), %rax
xorl %edx, %edx
cmpq $0x10, %rdx
je 0x149a
movl (%rax,%rdx), %edi
xorl %r8d, %r8d
cmpl (%rdx,%r15), %edi
sete %r8b
addl %r8d, %ecx
movl %r8d, 0x20(%rsp,%rdx)
movl %r8d, 0x10(%rsp,%rdx)
addq $0x4, %rdx
jmp 0x1473
xorl %edi, %edi
xorl %edx, %edx
cmpq $0x4, %rdi
je 0x14de
cmpl $0x0, 0x20(%rsp,%rdi,4)
je 0x14b0
incq %rdi
jmp 0x149e
xorl %r8d, %r8d
cmpq $0x10, %r8
je 0x14ab
cmpl $0x0, 0x10(%rsp,%r8)
jne 0x14cb
movl (%rax,%rdi,4), %r9d
cmpl (%r8,%r15), %r9d
je 0x14d1
addq $0x4, %r8
jmp 0x14b3
movl $0x1, 0x10(%rsp,%r8)
incl %edx
jmp 0x14ab
movl %ecx, %ecx
addq %rbx, %rsi
addq $0x10, %rsi
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x14fa
movl $0x1, (%rsi,%rdi,4)
incq %rdi
jmp 0x14e9
leaq (%rax,%rcx,4), %rax
addq $0x10, %rax
testl %edx, %edx
jle 0x1514
decl %edx
movl $0x2, (%rax)
addq $0x4, %rax
jmp 0x1502
callq 0x1875
decl %r12d
testl %eax, %eax
je 0x1327
jmp 0x152f
movq $0x0, 0x8(%rsp)
callq 0x1875
testl %eax, %eax
je 0x154d
leaq 0xb09(%rip), %rdi       # 0x2048
callq 0x158c
cmpb $0x0, 0x8(%rsp)
jne 0x1560
jmp 0x1576
cmpb $0x0, 0x8(%rsp)
je 0x156a
leaq 0xb07(%rip), %rdi       # 0x2062
callq 0x158c
movq (%r14), %rdi
callq 0x1070
jmp 0x1576
leaq 0xae8(%rip), %rdi       # 0x2059
callq 0x158c
callq 0x1130
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq