// File: BrianEnigma[P]cryptoslam/src/cryptoslam.cpp
// Function: toolsMenu(_win_st*, _win_st*, _win_st*, Cryptogram*)
void toolsMenu(WINDOW *menu, WINDOW *message, WINDOW *alphabet, Cryptogram *cr)
{
    char key;
    
    wclear(message);
    cr->paintStats(message);
    wrefresh(message);
    while (1)
    {
        wclear(menu);
        wcolor_set(menu, 1, NULL);
        wattron(menu, WA_REVERSE);
        mvwprintw(menu, 0, 0, "%s", TOOLSMENU);
        wattroff(menu, WA_REVERSE);
        wmove(menu, 0, strlen(TOOLSMENU));
        wrefresh(menu);

        noecho();
        key = getch();
        echo();
        switch(key)
        {
            case 'R':
            case 'r':
                cr->randomizeKeys();
                cr->calcPlaintext();
                return;
            case 'T':
            case 't':
                wclear(menu);
                wcolor_set(menu, 1, NULL);
                mvwprintw(menu, 0, 0, "Please wait, randomizing...");
                wmove(menu, 0, 27);
                wrefresh(menu);
                cr->randomizeMessage();
                cr->calcPlaintext();
                return;
            case 'G':
            case 'g':
                wclear(menu);
                wcolor_set(menu, 1, NULL);
                mvwprintw(menu, 0, 0, "Please wait, generating...");
                wmove(menu, 0, 27);
                wrefresh(menu);
                cr->newRandomMessage();
                cr->calcPlaintext();
                return;
            case '3':
                for (int i=0; i < 26; i++)
                    cr->set(i + 'A', ((i+13)%26) + 'A');
                cr->calcPlaintext();
                return;
            case 'C':
            case 'c':
                return;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2240
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3da0
movq -0x10(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, -0x34(%rbp)
movl %eax, %edx
movq %rdx, -0x40(%rbp)
movl $0x1, %esi
callq 0x2390
movq -0x40(%rbp), %rdx
movq -0x8(%rbp), %rdi
movl $0x40000, %esi          # imm = 0x40000
movl %esi, -0x44(%rbp)
callq 0x2130
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rdi
leaq 0xad0(%rip), %rcx       # 0x62cc
leaq 0xe96(%rip), %r8        # 0x6699
movb %dl, %al
movl %edx, %esi
callq 0x2090
movl -0x44(%rbp), %esi
movq -0x40(%rbp), %rdx
movq -0x8(%rbp), %rdi
callq 0x2350
movl -0x34(%rbp), %esi
movq -0x8(%rbp), %rdi
movl $0x38, %edx
callq 0x2260
movq -0x8(%rbp), %rdi
callq 0x22d0
callq 0x22e0
movq 0x379e(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
callq 0x20e0
movb %al, -0x21(%rbp)
callq 0x20c0
movsbl -0x21(%rbp), %eax
addl $-0x33, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x41, %eax
ja 0x59a1
movq -0x30(%rbp), %rax
leaq 0xb55(%rip), %rcx       # 0x63c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
callq 0x2db0
movq -0x20(%rbp), %rdi
callq 0x26b0
jmp 0x59a6
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2390
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0xe17(%rip), %rcx       # 0x66d2
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1b, %edx
callq 0x2260
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x20(%rbp), %rdi
callq 0x2e70
movq -0x20(%rbp), %rdi
callq 0x26b0
jmp 0x59a6
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2390
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0xdd2(%rip), %rcx       # 0x66ee
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1b, %edx
callq 0x2260
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x20(%rbp), %rdi
callq 0x2fe0
movq -0x20(%rbp), %rdi
callq 0x26b0
jmp 0x59a6
movl $0x0, -0x28(%rbp)
cmpl $0x1a, -0x28(%rbp)
jge 0x5994
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %eax
addl $0x41, %eax
movb %al, %cl
movl -0x28(%rbp), %eax
addl $0xd, %eax
movl $0x1a, %esi
cltd
idivl %esi
addl $0x41, %edx
movb %dl, %al
movsbl %cl, %esi
movsbl %al, %edx
callq 0x2ca0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x5959
movq -0x20(%rbp), %rdi
callq 0x26b0
jmp 0x59a6
jmp 0x59a6
jmp 0x57b7
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)