// File: BrianEnigma[P]cryptoslam/src/cryptoslam.cpp
// Function: handleKey(char, _win_st*, _win_st*, _win_st*, Cryptogram*)
void handleKey(char key, 
               WINDOW *menu, 
               WINDOW *message, 
               WINDOW *alphabet, 
               Cryptogram *cr)
{
    char key1, key2;
    switch(key)
    {
        case 's':
        case 'S':
            wclear(menu);
            mvwprintw(menu, 0, 0, "Cyphertext letter to set? ");
            wrefresh(menu);
            key1 = getch();
            wclear(menu);
            mvwprintw(menu, 0, 0, "Set letter \"%c\" to which plaintext letter (spacebar to unset)? ", 
                      key1);
            wrefresh(menu);
            key2 = getch();
            cr->set(key1, key2);
            cr->calcPlaintext();
            break;
        case 'u':
        case 'U':
            wclear(menu);
            mvwprintw(menu, 0, 0, "Cyphertext letter to unset? ");
            wrefresh(menu);
            key1 = getch();
            cr->unset(key1);
            cr->calcPlaintext();
            break;
        case 'r':
        case 'R':
            for (char c = 'A'; c <= 'Z'; c++)
                cr->unset(c);
            cr->calcPlaintext();
            break;
        case 't':
        case 'T':
            toolsMenu(menu, message, alphabet, cr);
            break;
        case 'f':
        case 'F':
            fileMenu(menu, cr);
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movsbl -0x1(%rbp), %eax
addl $-0x46, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x2f, %eax
ja 0x5b37
movq -0x38(%rbp), %rax
leaq 0xae1(%rip), %rcx       # 0x64d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
callq 0x2240
movq -0x10(%rbp), %rdi
xorl %edx, %edx
leaq 0xcfb(%rip), %rcx       # 0x6709
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x10(%rbp), %rdi
callq 0x22d0
movq 0x35b9(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
callq 0x20e0
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2240
movq -0x10(%rbp), %rdi
movsbl -0x29(%rbp), %r8d
xorl %edx, %edx
leaq 0xcd7(%rip), %rcx       # 0x6724
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x10(%rbp), %rdi
callq 0x22d0
movq 0x357a(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
callq 0x20e0
movb %al, -0x2a(%rbp)
movq -0x28(%rbp), %rdi
movb -0x29(%rbp), %al
movsbl %al, %esi
movsbl -0x2a(%rbp), %edx
callq 0x2ca0
movq -0x28(%rbp), %rdi
callq 0x26b0
jmp 0x5b37
movq -0x10(%rbp), %rdi
callq 0x2240
movq -0x10(%rbp), %rdi
xorl %edx, %edx
leaq 0xcbc(%rip), %rcx       # 0x6764
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x10(%rbp), %rdi
callq 0x22d0
movq 0x351f(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
callq 0x20e0
movb %al, -0x29(%rbp)
movq -0x28(%rbp), %rdi
movsbl -0x29(%rbp), %esi
callq 0x2d80
movq -0x28(%rbp), %rdi
callq 0x26b0
jmp 0x5b37
movb $0x41, -0x2b(%rbp)
movsbl -0x2b(%rbp), %eax
cmpl $0x5a, %eax
jg 0x5b08
movq -0x28(%rbp), %rdi
movsbl -0x2b(%rbp), %esi
callq 0x2d80
movb -0x2b(%rbp), %al
addb $0x1, %al
movb %al, -0x2b(%rbp)
jmp 0x5ae8
movq -0x28(%rbp), %rdi
callq 0x26b0
jmp 0x5b37
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x5780
jmp 0x5b37
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x53a0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)