// File: /workspace/github_c_makefile_star2_O3/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, %r15
cmpl $0x2, %edi
jne 0x1398
leaq 0xd5d(%rip), %rsi       # 0x205d
movl $0x6, %edi
callq 0x1130
movl $0x0, 0x2df0(%rip)      # 0x4104
callq 0x11b0
movq %rax, %r14
movq (%rax), %rax
xorl %ecx, %ecx
leaq 0x2ee8(%rip), %rdx      # 0x4210
leaq 0x2de1(%rip), %r8       # 0x4110
xorl %esi, %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
testb $0x1, 0x1(%rax,%rcx,2)
je 0x1347
movl %esi, %edi
incl %esi
movl %esi, 0x2dbd(%rip)      # 0x4104
movl %edi, (%rdx)
movb $0x20, (%rcx,%r8)
incq %rcx
addq $0x4, %rdx
cmpq $0xff, %rcx
jne 0x1331
movq 0x8(%r15), %rbx
leaq 0xcf5(%rip), %rsi       # 0x205e
movq %rbx, %rdi
callq 0x1140
testq %rax, %rax
jne 0x13b4
movq 0x2c7b(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xcd9(%rip), %rsi       # 0x2060
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
movl $0x1, %eax
jmp 0x13a2
movq %r15, %rdi
callq 0x11d0
xorl %eax, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movq %r15, 0x8(%rsp)
leaq 0xc9a(%rip), %rsi       # 0x205d
movl $0x6, %edi
callq 0x1130
movq %r12, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x140d
xorl %ebx, %ebx
leaq 0x322d(%rip), %r15      # 0x4610
cmpl $0xd, %eax
je 0x13f8
movl %eax, %edi
callq 0x1050
movslq %ebx, %rbx
movb %al, (%rbx,%r15)
incl %ebx
movq %r12, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x140d
cmpl $0x10000, %ebx          # imm = 0x10000
jle 0x13e3
movq %r12, %rdi
callq 0x1070
callq 0x18b7
movq 0x2baf(%rip), %r15      # 0x3fd0
leaq 0xbdc(%rip), %rbx       # 0x2004
leaq 0x31e1(%rip), %r12      # 0x4610
movq 0x8(%rsp), %r13
leaq 0x2cd5(%rip), %rbp      # 0x4110
callq 0x18e3
movq (%r15), %rdi
callq 0x1060
cmpl $0x151, %eax            # imm = 0x151
jg 0x15bf
leal -0x102(%rax), %ecx
cmpl $0x10, %ecx
ja 0x1743
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movq (%r15), %rdi
callq 0x1030
xorl %edi, %edi
xorl %esi, %esi
leaq 0xbfe(%rip), %rdx       # 0x207c
xorl %eax, %eax
callq 0x1120
movl $0x1, %edi
xorl %esi, %esi
leaq 0xc0f(%rip), %rdx       # 0x20a2
xorl %eax, %eax
callq 0x1120
movl $0x2, %edi
xorl %esi, %esi
leaq 0xc21(%rip), %rdx       # 0x20c9
xorl %eax, %eax
callq 0x1120
movl $0x3, %edi
xorl %esi, %esi
leaq 0xc2d(%rip), %rdx       # 0x20ea
xorl %eax, %eax
callq 0x1120
movl $0x4, %edi
xorl %esi, %esi
leaq 0xc3b(%rip), %rdx       # 0x210d
movl $0xa, %ecx
xorl %eax, %eax
callq 0x1120
movl $0x5, %edi
xorl %esi, %esi
leaq 0xc42(%rip), %rdx       # 0x212e
movl $0xa, %ecx
xorl %eax, %eax
callq 0x1120
movl $0x6, %edi
xorl %esi, %esi
leaq 0xc4b(%rip), %rdx       # 0x2151
xorl %eax, %eax
callq 0x1120
movl $0x7, %edi
xorl %esi, %esi
leaq 0xc5b(%rip), %rdx       # 0x2176
xorl %eax, %eax
callq 0x1120
movl $0x8, %edi
xorl %esi, %esi
leaq 0xc6c(%rip), %rdx       # 0x219c
xorl %eax, %eax
callq 0x1120
movl $0x9, %edi
xorl %esi, %esi
leaq 0xc77(%rip), %rdx       # 0x21bc
xorl %eax, %eax
callq 0x1120
movl $0xa, %edi
xorl %esi, %esi
leaq 0xc8c(%rip), %rdx       # 0x21e6
xorl %eax, %eax
callq 0x1120
movl $0xb, %edi
xorl %esi, %esi
leaq 0xc9f(%rip), %rdx       # 0x220e
xorl %eax, %eax
callq 0x1120
movl $0xc, %edi
xorl %esi, %esi
leaq 0xcb5(%rip), %rdx       # 0x2239
xorl %eax, %eax
callq 0x1120
movl $0xe, %edi
xorl %esi, %esi
leaq 0xcb2(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1120
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
jmp 0x143b
cmpl $0x152, %eax            # imm = 0x152
je 0x17e5
cmpl $0x153, %eax            # imm = 0x153
je 0x17f1
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x1758
callq 0x11c0
callq 0x18e3
callq 0x1040
movq (%r15), %rdi
movl $0x1, %esi
callq 0x10e0
xorl %eax, %eax
jmp 0x17ae
movl $0xff, %edx
movq %rbp, %rdi
movl $0x20, %esi
callq 0x10c0
jmp 0x143b
movl $0x3fc, %edx            # imm = 0x3FC
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x10c0
xorl %eax, %eax
movzbl (%rax,%r12), %ecx
testq %rcx, %rcx
je 0x1646
incl 0x10(%rsp,%rcx,4)
incq %rax
cmpq $0x10000, %rax          # imm = 0x10000
jne 0x162d
movq (%r15), %rdi
callq 0x1030
movq (%r15), %rax
testq %rax, %rax
je 0x1810
movswl 0x6(%rax), %r15d
addl $-0x9, %r15d
jmp 0x1816
movq 0x8(%r13), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x12f98(%rip), %rbx     # 0x14610
movq %rbx, %rdi
leaq 0xbec(%rip), %rdx       # 0x226e
leaq 0xbeb(%rip), %r8        # 0x2274
xorl %eax, %eax
callq 0x1090
movq (%r15), %rdi
callq 0x1030
movq %rbx, %rdi
leaq 0xbd7(%rip), %rsi       # 0x2279
callq 0x1140
movq %rax, %rbx
leaq 0xbca(%rip), %rdx       # 0x227b
testq %rax, %rax
je 0x16ee
xorl %r15d, %r15d
movb (%r15,%r12), %al
testb %al, %al
je 0x16e0
movzbl %al, %edi
callq 0x1ae4
movzbl %al, %edi
movq %rbx, %rsi
callq 0x10f0
incq %r15
cmpq $0x10000, %r15          # imm = 0x10000
jne 0x16b9
leaq 0xbb8(%rip), %rdx       # 0x229f
movq 0x28e2(%rip), %r15      # 0x3fd0
xorl %edi, %edi
xorl %esi, %esi
leaq 0x12f17(%rip), %rcx     # 0x14610
xorl %eax, %eax
callq 0x1120
movq %rbx, %rdi
callq 0x1070
movl $0x1, %edi
xorl %esi, %esi
leaq 0xb35(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1120
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
leaq 0x8c6(%rip), %rbx       # 0x2004
jmp 0x143b
cmpl $0x20, %eax
jne 0x1758
movslq 0x29b1(%rip), %rax      # 0x4100
movb $0x20, (%rax,%rbp)
jmp 0x143b
movq (%r14), %rcx
movslq %eax, %rdx
testb $0x4, 0x1(%rcx,%rdx,2)
je 0x143b
movl %eax, %edi
callq 0x1050
movslq 0x2989(%rip), %rcx      # 0x4100
movb %al, (%rcx,%rbp)
jmp 0x143b
movl 0x2983(%rip), %eax      # 0x4108
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x2970(%rip)      # 0x4108
jmp 0x143b
incl 0x2965(%rip)            # 0x4108
jmp 0x143b
movl 0x2952(%rip), %eax      # 0x4100
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x293f(%rip)      # 0x4100
jmp 0x143b
movl 0x2934(%rip), %eax      # 0x4100
leal 0x1(%rax), %ecx
movl 0x292f(%rip), %edx      # 0x4104
cmpl %edx, %eax
cmovgel %edx, %ecx
movl %ecx, 0x2920(%rip)      # 0x4100
jmp 0x143b
addl $0xa, 0x291c(%rip)      # 0x4108
jmp 0x143b
movl 0x2911(%rip), %eax      # 0x4108
cmpl $0xb, %eax
movl $0xa, %ecx
cmovll %ecx, %eax
addl $-0xa, %eax
movl %eax, 0x28fd(%rip)      # 0x4108
jmp 0x143b
movl $0xfffffff5, %r15d      # imm = 0xFFFFFFF5
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r14), %rax
testb $0x1, 0x1(%rax,%r13,2)
je 0x1857
movl 0x10(%rsp,%r13,4), %r8d
movl %ebx, %edi
movl %ebp, %esi
leaq 0xa2f(%rip), %rdx       # 0x2267
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1120
addl $0xa, %ebp
xorl %eax, %eax
cmpl %r15d, %ebp
setg %al
movl $0x0, %ecx
cmovgl %ecx, %ebp
addl %eax, %ebx
incq %r13
cmpq $0xff, %r13
jne 0x181d
incl %ebx
movl %ebx, %edi
xorl %esi, %esi
leaq 0x9db(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1120
movq 0x2752(%rip), %r15      # 0x3fd0
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
movq 0x8(%rsp), %r13
leaq 0x286c(%rip), %rbp      # 0x4110
leaq 0x759(%rip), %rbx       # 0x2004
jmp 0x143b
xorl %edi, %edi
callq 0x1180