// File: /workspace/github_cpp_makefile_star2_O2/BrianEnigma[P]cryptoslam/src/cryptoslam.cpp
// Function: fileMenu(_win_st*, Cryptogram*)
void fileMenu(WINDOW *menu, Cryptogram *cr)
{
    char filename[255];
    char key;
    char *editor = NULL;
    char command[1024] = "";
    while (1)
    {
        wclear(menu);
        wcolor_set(menu, 1, NULL);
        wattron(menu, WA_REVERSE);
        mvwprintw(menu, 0, 0, "%s", FILEMENU);
        wattroff(menu, WA_REVERSE);
        wmove(menu, 0, strlen(FILEMENU));
        wrefresh(menu);

        noecho();
        key = getch();
        echo();
        switch(key)
        {
            case 'L':
            case 'l':
                wclear(menu);
                mvwprintw(menu, 0, 0, "File to open? ");
                wrefresh(menu);
                wgetnstr(menu, filename, 255);
                filename[254] = 0;
                cr->loadFile(filename);
                cr->calcPlaintext();
                return;
            case 'T':
            case 't':
                wclear(menu);
                mvwprintw(menu, 0, 0, "Text file to save? ");
                wrefresh(menu);
                wgetnstr(menu, filename, 255);
                filename[254] = 0;
                cr->saveFileText(filename);
                cr->calcPlaintext();
                return;
            case 'B':
            case 'b':
                wclear(menu);
                mvwprintw(menu, 0, 0, "Binary file to save? ");
                wrefresh(menu);
                wgetnstr(menu, filename, 255);
                filename[254] = 0;
                cr->saveFileBinary(filename);
                cr->calcPlaintext();
                return;
            case 'N':
            case 'n':
                wclear(menu);
                mvwprintw(menu, 0, 0, "File to create? ");
                wrefresh(menu);
                wgetnstr(menu, filename, 255);
                filename[254] = 0;
                editor = getenv("VISUAL");
                if (!editor)
                    editor = getenv("EDITOR");
                if (!editor)
                    return;
                strncpy(command, editor, 512);
                strcat(command, " ");
                strcat(command, filename);
                system(command);
                cr->loadFile(filename);
                cr->calcPlaintext();
                return;
            case 'S':
            case 's':
                wclear(menu);
                mvwprintw(menu, 0, 0, "File to save keys to? ");
                wrefresh(menu);
                wgetnstr(menu, filename, 255);
                filename[254] = 0;
                cr->saveKeys(filename);
                return;
            case 'K':
            case 'k':
                wclear(menu);
                mvwprintw(menu, 0, 0, "File to load keys from? ");
                wrefresh(menu);
                wgetnstr(menu, filename, 255);
                filename[254] = 0;
                cr->loadKeys(filename);
                return;
            case 'C':
            case 'c':
                return;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x518, %rsp            # imm = 0x518
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
leaq 0x310(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2130
leaq 0xc22(%rip), %r15       # 0x42e8
leaq 0xcf6(%rip), %r12       # 0x43c3
pushq $0x45
popq %r13
movq 0x3908(%rip), %rbp      # 0x6fe0
movq %r14, %rdi
callq 0x21c0
movq %r14, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x22a0
movq %r14, %rdi
movl $0x40000, %esi          # imm = 0x40000
xorl %edx, %edx
callq 0x2100
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
movl $0x40000, %esi          # imm = 0x40000
xorl %edx, %edx
callq 0x2270
movq %r14, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x21e0
movq %r14, %rdi
callq 0x2200
callq 0x2210
movq (%rbp), %rdi
callq 0x20c0
movl %eax, %ebx
callq 0x20a0
movsbl %bl, %eax
leal -0x4b(%rax), %ecx
cmpl $0x9, %ecx
jbe 0x376c
leal -0x6b(%rax), %ecx
cmpl $0x9, %ecx
ja 0x377c
leaq 0xbdd(%rip), %rdx       # 0x4340
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
leaq 0xba5(%rip), %rdx       # 0x4318
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpl $0x42, %eax
je 0x39b5
cmpl $0x43, %eax
je 0x3a0e
cmpl $0x62, %eax
je 0x39b5
cmpl $0x63, %eax
jne 0x36d8
jmp 0x3a0e
movq %r14, %rdi
callq 0x21c0
leaq 0xc8e(%rip), %rcx       # 0x4442
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
callq 0x2200
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0xff, %edx
callq 0x22d0
movb $0x0, 0xfe(%rbx)
leaq 0xc66(%rip), %rdi       # 0x4453
callq 0x2250
testq %rax, %rax
jne 0x380c
leaq 0xc5c(%rip), %rdi       # 0x445a
callq 0x2250
testq %rax, %rax
je 0x3a0e
leaq 0x110(%rsp), %rbx
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2110
movq %rbx, %rdi
callq 0x20e0
movw $0x20, 0x110(%rsp,%rax)
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2310
movq %rbx, %rdi
callq 0x2170
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x25d8
movq %rbx, %rdi
jmp 0x3a09
movq %r14, %rdi
callq 0x21c0
leaq 0xba3(%rip), %rcx       # 0x4418
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
callq 0x2200
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0xff, %edx
callq 0x22d0
movb $0x0, 0xfe(%rbx)
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x26bc
jmp 0x3a06
movq %r14, %rdi
callq 0x21c0
leaq 0xb3e(%rip), %rcx       # 0x4409
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
callq 0x2200
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0xff, %edx
callq 0x22d0
movb $0x0, 0xfe(%rbx)
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x25d8
jmp 0x3a06
movq %r14, %rdi
callq 0x21c0
leaq 0xb57(%rip), %rcx       # 0x4478
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
callq 0x2200
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0xff, %edx
callq 0x22d0
movb $0x0, 0xfe(%rbx)
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x27f0
jmp 0x3a0e
movq %r14, %rdi
callq 0x21c0
leaq 0xaed(%rip), %rcx       # 0x4461
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
callq 0x2200
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0xff, %edx
callq 0x22d0
movb $0x0, 0xfe(%rbx)
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x27a2
jmp 0x3a0e
movq %r14, %rdi
callq 0x21c0
leaq 0xa68(%rip), %rcx       # 0x442c
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2070
movq %r14, %rdi
callq 0x2200
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0xff, %edx
callq 0x22d0
movb $0x0, 0xfe(%rbx)
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2730
movq %r14, %rdi
callq 0x252c
addq $0x518, %rsp            # imm = 0x518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq