// File: /workspace/github_c_makefile_star2_O2/kobolt[P]curses-collection/scca/scca.c
// Function: main
int main(int argc, char *argv[])
{
  int c;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    return 0;
  }

  cipher_init();
  if (text_read(argv[1]) != 0) {
    return 1;
  }
  screen_init();

  while (1) {
    screen_update();
    c = getch();

    switch (c) {
    case KEY_RESIZE:
      screen_resize();

    case KEY_LEFT:
      cipher_pos--;
      if (cipher_pos < 0)
        cipher_pos = 0;
      break;

    case KEY_RIGHT:
      cipher_pos++;
      if (cipher_pos > allowed_char_len)
        cipher_pos = allowed_char_len;
      break;

    case KEY_UP:
      text_offset--;
      if (text_offset < 0)
        text_offset = 0;
      break;

    case KEY_DOWN:
      text_offset++;
      /* NOTE: Nothing preventing infinite scrolling... */
      break;

    case KEY_PPAGE:
      text_offset -= PAGE_OFFSET_SKIP;
      if (text_offset < 0)
        text_offset = 0;
      break;
      
    case KEY_NPAGE:
      text_offset += PAGE_OFFSET_SKIP;
      /* NOTE: Nothing preventing infinite scrolling... */
      break;

    case KEY_F(1):
    case KEY_F(5):
      display_help();
      break;

    case KEY_F(2):
    case KEY_F(6):
      display_frequency();
      break;

    case KEY_F(3):
    case KEY_F(7):
      cipher_erase();
      break;

    case KEY_F(4):
    case KEY_F(8):
      text_save(argv[1]);
      break;

    case KEY_F(10):
      exit(0);

    case ' ':
      cipher[cipher_pos] = ' ';
      break;

    default:
      if (isalpha(c)) {
        cipher[cipher_pos] = toupper(c);
      }
      break;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rsi, %r12
cmpl $0x2, %edi
jne 0x132b
leaq 0xd91(%rip), %rsi       # 0x205d
pushq $0x6
popq %rdi
callq 0x1120
andl $0x0, 0x2e29(%rip)      # 0x4104
callq 0x11a0
movq %rax, %r14
movq (%rax), %rax
xorl %ecx, %ecx
leaq 0x2f21(%rip), %rdx      # 0x4210
pushq $-0x1
popq %rsi
leaq 0x2e17(%rip), %rbp      # 0x4110
xorl %edi, %edi
cmpq $0xff, %rcx
je 0x1345
testb $0x1, 0x1(%rax,%rcx,2)
jne 0x1310
movl %esi, %r8d
jmp 0x131b
movl %edi, %r8d
incl %edi
movl %edi, 0x2de9(%rip)      # 0x4104
movl %r8d, (%rdx)
movb $0x20, (%rcx,%rbp)
incq %rcx
addq $0x4, %rdx
jmp 0x12fb
movq 0x2cc6(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%r12), %rdx
leaq 0xd08(%rip), %rsi       # 0x2048
xorl %r13d, %r13d
jmp 0x1376
movq 0x8(%r12), %r15
leaq 0xd0d(%rip), %rsi       # 0x205e
movq %r15, %rdi
callq 0x1130
pushq $0x1
popq %r13
testq %rax, %rax
jne 0x1392
movq 0x2c8f(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xced(%rip), %rsi       # 0x2060
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
movl %r13d, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r12, 0x8(%rsp)
leaq 0xcbc(%rip), %rsi       # 0x205d
pushq $0x6
popq %rdi
callq 0x1120
xorl %r15d, %r15d
leaq 0x325d(%rip), %r12      # 0x4610
movq %rbx, %rdi
callq 0x10c0
cmpl $-0x1, %eax
je 0x13e1
cmpl $0x10000, %r15d         # imm = 0x10000
ja 0x13e1
cmpl $0xd, %eax
je 0x13b3
movl %eax, %edi
callq 0x1050
movl %r15d, %ecx
movb %al, (%rcx,%r12)
incl %r15d
jmp 0x13b3
movq %rbx, %rdi
callq 0x1070
callq 0x10a0
movq 0x2bf3(%rip), %rdi      # 0x3fe8
callq 0x1ac0
callq 0x1080
movq 0x2bca(%rip), %r15      # 0x3fd0
movq (%r15), %rdi
pushq $0x1
popq %r13
movl %r13d, %esi
callq 0x10d0
leaq 0xbe8(%rip), %rbx       # 0x2004
movq 0x8(%rsp), %r12
callq 0x188c
movq (%r15), %rdi
callq 0x1060
leal -0x102(%rax), %ecx
cmpl $0x10, %ecx
ja 0x1583
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movq (%r15), %rdi
callq 0x1030
xorl %edi, %edi
xorl %esi, %esi
leaq 0xc23(%rip), %rdx       # 0x207c
xorl %eax, %eax
callq 0x1110
movl %r13d, %edi
xorl %esi, %esi
leaq 0xc36(%rip), %rdx       # 0x20a2
xorl %eax, %eax
callq 0x1110
pushq $0x2
popq %rdi
xorl %esi, %esi
leaq 0xc4a(%rip), %rdx       # 0x20c9
xorl %eax, %eax
callq 0x1110
pushq $0x3
popq %rdi
xorl %esi, %esi
leaq 0xc58(%rip), %rdx       # 0x20ea
xorl %eax, %eax
callq 0x1110
pushq $0x4
popq %rdi
xorl %esi, %esi
leaq 0xc68(%rip), %rdx       # 0x210d
pushq $0xa
popq %rbx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1110
pushq $0x5
popq %rdi
xorl %esi, %esi
leaq 0xc71(%rip), %rdx       # 0x212e
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1110
pushq $0x6
popq %rdi
xorl %esi, %esi
leaq 0xc7f(%rip), %rdx       # 0x2151
xorl %eax, %eax
callq 0x1110
pushq $0x7
popq %rdi
xorl %esi, %esi
leaq 0xc91(%rip), %rdx       # 0x2176
xorl %eax, %eax
callq 0x1110
pushq $0x8
popq %rdi
xorl %esi, %esi
leaq 0xca4(%rip), %rdx       # 0x219c
xorl %eax, %eax
callq 0x1110
pushq $0x9
popq %rdi
xorl %esi, %esi
leaq 0xcb1(%rip), %rdx       # 0x21bc
xorl %eax, %eax
callq 0x1110
movl %ebx, %edi
leaq 0xae9(%rip), %rbx       # 0x2004
xorl %esi, %esi
leaq 0xcc2(%rip), %rdx       # 0x21e6
xorl %eax, %eax
callq 0x1110
pushq $0xb
popq %rdi
xorl %esi, %esi
leaq 0xcd7(%rip), %rdx       # 0x220e
xorl %eax, %eax
callq 0x1110
pushq $0xc
popq %rdi
xorl %esi, %esi
leaq 0xcef(%rip), %rdx       # 0x2239
xorl %eax, %eax
callq 0x1110
pushq $0xe
popq %rdi
xorl %esi, %esi
leaq 0xcee(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1110
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
jmp 0x1421
cmpl $0x20, %eax
je 0x184c
cmpl $0x152, %eax            # imm = 0x152
je 0x1879
cmpl $0x153, %eax            # imm = 0x153
je 0x185c
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x1766
callq 0x11b0
callq 0x188c
callq 0x1040
movq (%r15), %rdi
movl %r13d, %esi
callq 0x10d0
xorl %eax, %eax
jmp 0x1819
movq 0x8(%r12), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x13031(%rip), %rbx     # 0x14610
movq %rbx, %rdi
leaq 0xc85(%rip), %rdx       # 0x226e
leaq 0xc84(%rip), %r8        # 0x2274
xorl %eax, %eax
callq 0x1090
movq (%r15), %rdi
callq 0x1030
movq %rbx, %rdi
leaq 0xc70(%rip), %rsi       # 0x2279
callq 0x1130
movq %rax, %rbx
leaq 0xc63(%rip), %rdx       # 0x227b
testq %rax, %rax
je 0x179b
xorl %r15d, %r15d
cmpq $0x10000, %r15          # imm = 0x10000
je 0x178d
leaq 0x2fd8(%rip), %rax      # 0x4610
movb (%r15,%rax), %al
testb %al, %al
je 0x178d
movzbl %al, %edi
callq 0x1a84
movzbl %al, %edi
movq %rbx, %rsi
callq 0x10e0
incq %r15
jmp 0x1624
xorl %eax, %eax
leaq 0x2fab(%rip), %rdx      # 0x4610
cmpq $0xff, %rax
je 0x1677
andl $0x0, 0x10(%rsp,%rax,4)
incq %rax
jmp 0x1665
xorl %eax, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x1693
movzbl (%rax,%rdx), %ecx
testq %rcx, %rcx
je 0x1693
incl 0x10(%rsp,%rcx,4)
incq %rax
jmp 0x1679
movq (%r15), %rdi
callq 0x1030
movq (%r15), %rax
pushq $-0xb
popq %r12
testq %rax, %rax
je 0x16b0
movswl 0x6(%rax), %r12d
addl $-0x9, %r12d
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq $0xff, %rbx
je 0x1703
movq (%r14), %rax
testb $0x1, 0x1(%rax,%rbx,2)
je 0x16fe
movl 0x10(%rsp,%rbx,4), %r8d
movl %r13d, %edi
movl %r15d, %esi
leaq 0xb8a(%rip), %rdx       # 0x2267
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1110
addl $0xa, %r15d
xorl %eax, %eax
cmpl %r12d, %r15d
setg %al
movl $0x0, %ecx
cmovgl %ecx, %r15d
addl %eax, %r13d
incq %rbx
jmp 0x16b8
incl %r13d
movl %r13d, %edi
xorl %esi, %esi
leaq 0xb39(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1110
movq 0x28b0(%rip), %r15      # 0x3fd0
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
movq 0x8(%rsp), %r12
pushq $0x1
popq %r13
leaq 0x8ba(%rip), %rbx       # 0x2004
jmp 0x1421
xorl %eax, %eax
cmpq $0xff, %rax
je 0x1421
movb $0x20, (%rax,%rbp)
incq %rax
jmp 0x1751
movq (%r14), %rcx
movslq %eax, %rdx
testb $0x4, 0x1(%rcx,%rdx,2)
je 0x1421
movl %eax, %edi
callq 0x1050
movslq 0x297b(%rip), %rcx      # 0x4100
movb %al, (%rcx,%rbp)
jmp 0x1421
leaq 0xb0b(%rip), %rdx       # 0x229f
movq 0x2835(%rip), %r15      # 0x3fd0
xorl %edi, %edi
xorl %esi, %esi
leaq 0x12e6a(%rip), %rcx     # 0x14610
xorl %eax, %eax
callq 0x1110
movq %rbx, %rdi
callq 0x1070
movl %r13d, %edi
xorl %esi, %esi
leaq 0xa8a(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1110
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
leaq 0x81b(%rip), %rbx       # 0x2004
jmp 0x1421
incl 0x2914(%rip)            # 0x4108
jmp 0x1421
movl 0x2909(%rip), %eax      # 0x4108
cmpl $0x2, %eax
cmovll %r13d, %eax
decl %eax
movl %eax, 0x28fa(%rip)      # 0x4108
jmp 0x1421
movl 0x28e7(%rip), %eax      # 0x4100
cmpl $0x2, %eax
cmovll %r13d, %eax
decl %eax
movl %eax, 0x28d8(%rip)      # 0x4100
jmp 0x1421
movl 0x28cd(%rip), %eax      # 0x4100
leal 0x1(%rax), %ecx
movl 0x28c8(%rip), %edx      # 0x4104
cmpl %edx, %eax
cmovgel %edx, %ecx
movl %ecx, 0x28b9(%rip)      # 0x4100
jmp 0x1421
movslq 0x28ad(%rip), %rax      # 0x4100
movb $0x20, (%rax,%rbp)
jmp 0x1421
movl 0x28a6(%rip), %eax      # 0x4108
cmpl $0xb, %eax
pushq $0xa
popq %rcx
cmovll %ecx, %eax
addl $-0xa, %eax
movl %eax, 0x2894(%rip)      # 0x4108
jmp 0x1421
addl $0xa, 0x2888(%rip)      # 0x4108
jmp 0x1421
xorl %edi, %edi
callq 0x1170