// File: /workspace/github_c_makefile_star2_O1/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, %r13
cmpl $0x2, %edi
jne 0x13f2
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), %rbp      # 0x4110
xorl %esi, %esi
testb $0x1, 0x1(%rax,%rcx,2)
jne 0x1340
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
jmp 0x134a
movl %esi, (%rdx)
incl %esi
movl %esi, 0x2dba(%rip)      # 0x4104
movb $0x20, (%rcx,%rbp)
incq %rcx
addq $0x4, %rdx
cmpq $0xff, %rcx
jne 0x1331
movq 0x8(%r13), %rbx
leaq 0xcf5(%rip), %rsi       # 0x205e
movq %rbx, %rdi
callq 0x1140
movq %rax, %r12
testq %rax, %rax
je 0x13fe
leaq 0xcd9(%rip), %rsi       # 0x205d
movl $0x6, %edi
callq 0x1130
movq %r12, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x13ce
xorl %ebx, %ebx
leaq 0x326c(%rip), %r15      # 0x4610
cmpl $0xd, %eax
je 0x13b9
movl %eax, %edi
callq 0x1050
movslq %ebx, %rbx
movb %al, (%rbx,%r15)
incl %ebx
movq %r12, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x13ce
cmpl $0x10001, %ebx          # imm = 0x10001
jl 0x13a4
movq %r12, %rdi
callq 0x1070
movl $0x1, %eax
testq %r12, %r12
jne 0x141b
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x11d0
xorl %eax, %eax
jmp 0x13e0
movq 0x2bf3(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc51(%rip), %rsi       # 0x2060
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
jmp 0x13d6
callq 0x18bb
movq 0x2ba9(%rip), %r15      # 0x3fd0
leaq 0xbd6(%rip), %rbx       # 0x2004
leaq 0x31db(%rip), %r12      # 0x4610
movq %r13, 0x8(%rsp)
callq 0x18e7
movq (%r15), %rdi
callq 0x1060
cmpl $0x151, %eax            # imm = 0x151
jg 0x15be
leal -0x102(%rax), %ecx
cmpl $0x10, %ecx
ja 0x1763
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movq (%r15), %rdi
callq 0x1030
xorl %edi, %edi
xorl %esi, %esi
leaq 0xbff(%rip), %rdx       # 0x207c
xorl %eax, %eax
callq 0x1120
movl $0x1, %edi
xorl %esi, %esi
leaq 0xc10(%rip), %rdx       # 0x20a2
xorl %eax, %eax
callq 0x1120
movl $0x2, %edi
xorl %esi, %esi
leaq 0xc22(%rip), %rdx       # 0x20c9
xorl %eax, %eax
callq 0x1120
movl $0x3, %edi
xorl %esi, %esi
leaq 0xc2e(%rip), %rdx       # 0x20ea
xorl %eax, %eax
callq 0x1120
movl $0x4, %edi
xorl %esi, %esi
leaq 0xc3c(%rip), %rdx       # 0x210d
movl $0xa, %ecx
xorl %eax, %eax
callq 0x1120
movl $0x5, %edi
xorl %esi, %esi
leaq 0xc43(%rip), %rdx       # 0x212e
movl $0xa, %ecx
xorl %eax, %eax
callq 0x1120
movl $0x6, %edi
xorl %esi, %esi
leaq 0xc4c(%rip), %rdx       # 0x2151
xorl %eax, %eax
callq 0x1120
movl $0x7, %edi
xorl %esi, %esi
leaq 0xc5c(%rip), %rdx       # 0x2176
xorl %eax, %eax
callq 0x1120
movl $0x8, %edi
xorl %esi, %esi
leaq 0xc6d(%rip), %rdx       # 0x219c
xorl %eax, %eax
callq 0x1120
movl $0x9, %edi
xorl %esi, %esi
leaq 0xc78(%rip), %rdx       # 0x21bc
xorl %eax, %eax
callq 0x1120
movl $0xa, %edi
xorl %esi, %esi
leaq 0xc8d(%rip), %rdx       # 0x21e6
xorl %eax, %eax
callq 0x1120
movl $0xb, %edi
xorl %esi, %esi
leaq 0xca0(%rip), %rdx       # 0x220e
xorl %eax, %eax
callq 0x1120
movl $0xc, %edi
xorl %esi, %esi
leaq 0xcb6(%rip), %rdx       # 0x2239
xorl %eax, %eax
callq 0x1120
movl $0xe, %edi
xorl %esi, %esi
leaq 0xcb3(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1120
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
jmp 0x143a
cmpl $0x152, %eax            # imm = 0x152
je 0x17e7
cmpl $0x153, %eax            # imm = 0x153
je 0x17f3
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x1778
callq 0x11c0
callq 0x18e7
callq 0x1040
movq (%r15), %rdi
movl $0x1, %esi
callq 0x10e0
movl $0x0, 0x2afb(%rip)      # 0x4100
movl 0x2af5(%rip), %eax      # 0x4100
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x2ae2(%rip)      # 0x4100
jmp 0x143a
movl $0xff, %edx
movq %rbp, %rdi
movl $0x20, %esi
callq 0x10c0
jmp 0x143a
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 0x1666
incl 0x10(%rsp,%rcx,4)
incq %rax
cmpq $0x10000, %rax          # imm = 0x10000
jne 0x164d
movq (%r15), %rdi
callq 0x1030
movq (%r15), %rax
testq %rax, %rax
je 0x1812
movswl 0x6(%rax), %r15d
addl $-0x9, %r15d
jmp 0x1818
movq 0x8(%r13), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x12f78(%rip), %rbx     # 0x14610
movq %rbx, %rdi
leaq 0xbcc(%rip), %rdx       # 0x226e
leaq 0xbcb(%rip), %r8        # 0x2274
xorl %eax, %eax
callq 0x1090
movq (%r15), %rdi
callq 0x1030
movq %rbx, %rdi
leaq 0xbb7(%rip), %rsi       # 0x2279
callq 0x1140
movq %rax, %rbx
leaq 0xbaa(%rip), %rdx       # 0x227b
testq %rax, %rax
je 0x170e
xorl %r15d, %r15d
movb (%r15,%r12), %al
testb %al, %al
je 0x1700
movzbl %al, %edi
callq 0x1aef
movzbl %al, %edi
movq %rbx, %rsi
callq 0x10f0
incq %r15
cmpq $0x10000, %r15          # imm = 0x10000
jne 0x16d9
leaq 0xb98(%rip), %rdx       # 0x229f
movq 0x28c2(%rip), %r15      # 0x3fd0
xorl %edi, %edi
xorl %esi, %esi
leaq 0x12ef7(%rip), %rcx     # 0x14610
xorl %eax, %eax
callq 0x1120
movq %rbx, %rdi
callq 0x1070
movl $0x1, %edi
xorl %esi, %esi
leaq 0xb15(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1120
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
leaq 0x8a6(%rip), %rbx       # 0x2004
jmp 0x143a
cmpl $0x20, %eax
jne 0x1778
movslq 0x2991(%rip), %rax      # 0x4100
movb $0x20, (%rax,%rbp)
jmp 0x143a
movq (%r14), %rcx
movslq %eax, %rdx
testb $0x4, 0x1(%rcx,%rdx,2)
je 0x143a
movl %eax, %edi
callq 0x1050
movslq 0x2969(%rip), %rcx      # 0x4100
movb %al, (%rcx,%rbp)
jmp 0x143a
movl 0x2963(%rip), %eax      # 0x4108
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x2950(%rip)      # 0x4108
jmp 0x143a
incl 0x2945(%rip)            # 0x4108
jmp 0x143a
movl 0x2932(%rip), %eax      # 0x4100
leal 0x1(%rax), %ecx
movl 0x292d(%rip), %edx      # 0x4104
cmpl %edx, %eax
cmovgel %edx, %ecx
movl %ecx, 0x291e(%rip)      # 0x4100
jmp 0x143a
addl $0xa, 0x291a(%rip)      # 0x4108
jmp 0x143a
movl 0x290f(%rip), %eax      # 0x4108
cmpl $0xb, %eax
movl $0xa, %ecx
cmovll %ecx, %eax
addl $-0xa, %eax
movl %eax, 0x28fb(%rip)      # 0x4108
jmp 0x143a
movl $0xfffffff5, %r15d      # imm = 0xFFFFFFF5
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %ebp, %ebp
movq (%r14), %rax
testb $0x1, 0x1(%rax,%rbx,2)
je 0x1859
movl 0x10(%rsp,%rbx,4), %r8d
movl %r13d, %edi
movl %ebp, %esi
leaq 0xa2d(%rip), %rdx       # 0x2267
movl %ebx, %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, %r13d
incq %rbx
cmpq $0xff, %rbx
jne 0x181f
incl %r13d
movl %r13d, %edi
xorl %esi, %esi
leaq 0x9d7(%rip), %rdx       # 0x224b
xorl %eax, %eax
callq 0x1120
movq 0x274e(%rip), %r15      # 0x3fd0
movq (%r15), %rdi
callq 0x10b0
callq 0x1040
movq (%r15), %rdi
callq 0x1060
callq 0x1040
movq 0x8(%rsp), %r13
leaq 0x2868(%rip), %rbp      # 0x4110
leaq 0x755(%rip), %rbx       # 0x2004
jmp 0x143a
xorl %edi, %edi
callq 0x1180