// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %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 0x12e9
callq 0x10c0
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1100
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1100
movl $0x3, %edi
movl $0x3, %esi
xorl %edx, %edx
callq 0x1100
movl $0x4, %edi
movl $0x4, %esi
xorl %edx, %edx
callq 0x1100
movl $0x5, %edi
movl $0x5, %esi
xorl %edx, %edx
callq 0x1100
movl $0x6, %edi
movl $0x6, %esi
xorl %edx, %edx
callq 0x1100
callq 0x1080
movq 0x2ceb(%rip), %r14      # 0x3fe0
movq (%r14), %rdi
movl $0x1, %esi
callq 0x10d0
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x10e0
movl %eax, %edi
callq 0x1060
movabsq $0x2aaaaaaaaaaaaaab, %r13 # imm = 0x2AAAAAAAAAAAAAAB
leaq 0x2efc(%rip), %r15      # 0x4220
callq 0x10f0
movq %rax, %rcx
imulq %r13
movq %rdx, %rax
shrq $0x3f, %rax
addl %edx, %eax
addl %eax, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
incl %ecx
movl %ecx, (%r12,%r15)
addq $0x4, %r12
cmpq $0x10, %r12
jne 0x1324
movl $0x9, 0x2eb7(%rip)      # 0x4210
leaq 0xcb0(%rip), %r12       # 0x2010
movl $0x0, 0x2eaa(%rip)      # 0x4214
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x15fb
movq (%r14), %rdi
callq 0x1070
cmpl $0x70, %eax
jg 0x139b
cmpl $0x1f, %eax
jg 0x13e0
cmpl $0xa, %eax
je 0x13ff
cmpl $0x1b, %eax
je 0x1426
jmp 0x1485
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
ja 0x13ef
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movslq 0x2e5a(%rip), %rax      # 0x4210
shlq $0x5, %rax
addq %rbx, %rax
movslq 0x2e50(%rip), %rcx      # 0x4214
movl (%rax,%rcx,4), %edx
leal -0x1(%rdx), %esi
addl $-0x8, %edx
cmpl $-0x6, %edx
movl $0x6, %edx
cmovbl %edx, %esi
movl %esi, (%rax,%rcx,4)
jmp 0x1485
cmpl $0x20, %eax
je 0x13ff
cmpl $0x51, %eax
je 0x1426
jmp 0x1485
cmpl $0x71, %eax
je 0x1426
cmpl $0x157, %eax            # imm = 0x157
jne 0x1485
movslq 0x2e0a(%rip), %rax      # 0x4210
shlq $0x5, %rax
addq %rbx, %rax
xorl %ecx, %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0x1485
incq %rcx
cmpq $0x4, %rcx
jne 0x140f
movl $0x1, %r13d
jmp 0x1485
movl $0x1, %ebp
jmp 0x1485
movl 0x2de1(%rip), %eax      # 0x4214
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
jmp 0x1455
movl 0x2dcc(%rip), %eax      # 0x4214
cmpl $0x2, %eax
movl $0x2, %ecx
cmovgel %ecx, %eax
incl %eax
movl %eax, 0x2db9(%rip)      # 0x4214
jmp 0x1485
movslq 0x2dac(%rip), %rax      # 0x4210
shlq $0x5, %rax
addq %rbx, %rax
movslq 0x2da2(%rip), %rcx      # 0x4214
movl (%rax,%rcx,4), %edx
incl %edx
cmpl $0x7, %edx
movl $0x1, %esi
cmovael %esi, %edx
movl %edx, (%rax,%rcx,4)
movl %r13d, %eax
orl %ebp, %eax
je 0x136f
testl %ebp, %ebp
jne 0x1588
movslq 0x2d71(%rip), %rax      # 0x4210
movq %rax, %rcx
shlq $0x5, %rcx
leaq (%rbx,%rcx), %rdi
xorl %edx, %edx
xorl %esi, %esi
movl (%rdi,%rdx), %r8d
xorl %r9d, %r9d
cmpl (%rdx,%r15), %r8d
sete %r9b
addl %r9d, %esi
movl %r9d, 0x10(%rsp,%rdx)
movl %r9d, (%rsp,%rdx)
addq $0x4, %rdx
cmpq $0x10, %rdx
jne 0x14ae
xorl %r8d, %r8d
xorl %edx, %edx
cmpl $0x0, 0x10(%rsp,%r8,4)
jne 0x150a
xorl %r9d, %r9d
cmpl $0x0, (%rsp,%r9)
jne 0x14f4
movl (%rdi,%r8,4), %r10d
cmpl (%r9,%r15), %r10d
je 0x1500
addq $0x4, %r9
cmpq $0x10, %r9
jne 0x14e3
jmp 0x150a
movl $0x1, (%rsp,%r9)
incl %edx
incq %r8
cmpq $0x4, %r8
jne 0x14d8
testl %esi, %esi
je 0x1535
movl %esi, %edi
leaq (%rcx,%rbx), %r8
addq $0x10, %r8
xorl %esi, %esi
movl $0x1, (%r8,%rsi,4)
incq %rsi
cmpq %rsi, %rdi
jne 0x1523
jmp 0x1537
xorl %esi, %esi
testl %edx, %edx
jle 0x1554
addl %esi, %edx
leaq (%rcx,%rbx), %rdi
addq $0x10, %rdi
movl $0x2, (%rdi,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x1545
addq %rbx, %rcx
addq $0x10, %rcx
xorl %edx, %edx
movl (%rcx,%rdx,4), %esi
cmpl $0x1, %esi
jne 0x1572
leaq 0x1(%rdx), %rdi
cmpq $0x3, %rdx
movq %rdi, %rdx
jne 0x155d
cmpl $0x1, %esi
je 0x1588
leal -0x1(%rax), %ecx
movl %ecx, 0x2c90(%rip)      # 0x4210
testl %eax, %eax
jg 0x1360
movslq 0x2c81(%rip), %rax      # 0x4210
shlq $0x5, %rax
leaq (%rax,%rbx), %rcx
addq $0x10, %rcx
xorl %edx, %edx
movl (%rcx,%rdx,4), %eax
cmpl $0x1, %eax
jne 0x15b2
leaq 0x1(%rdx), %rsi
cmpq $0x3, %rdx
movq %rsi, %rdx
jne 0x159d
testl %ebp, %ebp
leaq 0xaa7(%rip), %rcx       # 0x2062
leaq 0xa97(%rip), %rdx       # 0x2059
cmoveq %rcx, %rdx
cmpl $0x1, %eax
leaq 0xa78(%rip), %rdi       # 0x2048
cmovneq %rdx, %rdi
callq 0x15fb
testl %ebp, %ebp
jne 0x15e5
movq (%r14), %rdi
callq 0x1070
callq 0x1130
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq