// File: 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
movq %rsp, %rbp
subq $0x540, %rsp            # imm = 0x540
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x120(%rbp)
leaq -0x520(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x2150
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, -0x52c(%rbp)
movl %eax, %edx
movq %rdx, -0x538(%rbp)
movl $0x1, %esi
callq 0x2390
movq -0x538(%rbp), %rdx
movq -0x8(%rbp), %rdi
movl $0x40000, %esi          # imm = 0x40000
movl %esi, -0x53c(%rbp)
callq 0x2130
movl -0x52c(%rbp), %edx
movq -0x8(%rbp), %rdi
leaq 0xea7(%rip), %rcx       # 0x62cc
leaq 0x119f(%rip), %r8       # 0x65cb
movb %dl, %al
movl %edx, %esi
callq 0x2090
movl -0x53c(%rbp), %esi
movq -0x538(%rbp), %rdx
movq -0x8(%rbp), %rdi
callq 0x2350
movl -0x52c(%rbp), %esi
movq -0x8(%rbp), %rdi
movl $0x45, %edx
callq 0x2260
movq -0x8(%rbp), %rdi
callq 0x22d0
callq 0x22e0
movq 0x3b6c(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
callq 0x20e0
movb %al, -0x111(%rbp)
callq 0x20c0
movsbl -0x111(%rbp), %eax
addl $-0x42, %eax
movl %eax, %ecx
movq %rcx, -0x528(%rbp)
subl $0x32, %eax
ja 0x5767
movq -0x528(%rbp), %rax
leaq 0xe4b(%rip), %rcx       # 0x62fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x1141(%rip), %rcx      # 0x6611
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x23c0
movb $0x0, -0x12(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2880
movq -0x10(%rbp), %rdi
callq 0x26b0
jmp 0x576c
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x10f1(%rip), %rcx      # 0x6620
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x23c0
movb $0x0, -0x12(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x29f0
movq -0x10(%rbp), %rdi
callq 0x26b0
jmp 0x576c
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x10a6(%rip), %rcx      # 0x6634
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x23c0
movb $0x0, -0x12(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2ab0
movq -0x10(%rbp), %rdi
callq 0x26b0
jmp 0x576c
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x105d(%rip), %rcx      # 0x664a
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x23c0
movb $0x0, -0x12(%rbp)
leaq 0x103c(%rip), %rdi      # 0x665b
callq 0x2320
movq %rax, -0x120(%rbp)
cmpq $0x0, -0x120(%rbp)
jne 0x5648
leaq 0x1026(%rip), %rdi      # 0x6662
callq 0x2320
movq %rax, -0x120(%rbp)
cmpq $0x0, -0x120(%rbp)
jne 0x5657
jmp 0x576c
leaq -0x520(%rbp), %rdi
movq -0x120(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x2140
leaq -0x520(%rbp), %rdi
leaq 0xbc7(%rip), %rsi       # 0x6244
callq 0x2420
leaq -0x520(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2420
leaq -0x520(%rbp), %rdi
callq 0x21e0
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2880
movq -0x10(%rbp), %rdi
callq 0x26b0
jmp 0x576c
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0xf94(%rip), %rcx       # 0x6669
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x23c0
movb $0x0, -0x12(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2b60
jmp 0x576c
movq -0x8(%rbp), %rdi
callq 0x2240
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0xf58(%rip), %rcx       # 0x6680
movl %edx, %esi
movb $0x0, %al
callq 0x2090
movq -0x8(%rbp), %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x23c0
movb $0x0, -0x12(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2bc0
jmp 0x576c
jmp 0x576c
jmp 0x53d1
addq $0x540, %rsp            # imm = 0x540
popq %rbp
retq
nopw %cs:(%rax,%rax)