// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x12f7
movq 0x3d25(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x1d20(%rip), %rsi      # 0x3004
movb $0x0, %al
callq 0x1100
movl $0x0, -0x4(%rbp)
jmp 0x158f
callq 0x15a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1650
cmpl $0x0, %eax
je 0x131a
movl $0x1, -0x4(%rbp)
jmp 0x158f
callq 0x1720
callq 0x1750
movq 0x3ca5(%rip), %rax      # 0x4fd0
movq (%rax), %rdi
callq 0x1060
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
subl $0x20, %eax
je 0x153f
jmp 0x1347
movl -0x18(%rbp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x14c8
jmp 0x1357
movl -0x18(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x14a1
jmp 0x1367
movl -0x18(%rbp), %eax
subl $0x104, %eax            # imm = 0x104
je 0x144c
jmp 0x1377
movl -0x18(%rbp), %eax
subl $0x105, %eax            # imm = 0x105
je 0x1473
jmp 0x1387
movl -0x18(%rbp), %eax
subl $0x109, %eax            # imm = 0x109
je 0x1514
jmp 0x1397
movl -0x18(%rbp), %eax
subl $0x10a, %eax            # imm = 0x10A
je 0x151b
jmp 0x13a7
movl -0x18(%rbp), %eax
subl $0x10b, %eax            # imm = 0x10B
je 0x1522
jmp 0x13b7
movl -0x18(%rbp), %eax
subl $0x10c, %eax            # imm = 0x10C
je 0x1529
jmp 0x13c7
movl -0x18(%rbp), %eax
subl $0x10d, %eax            # imm = 0x10D
je 0x1514
jmp 0x13d7
movl -0x18(%rbp), %eax
subl $0x10e, %eax            # imm = 0x10E
je 0x151b
jmp 0x13e7
movl -0x18(%rbp), %eax
subl $0x10f, %eax            # imm = 0x10F
je 0x1522
jmp 0x13f7
movl -0x18(%rbp), %eax
subl $0x110, %eax            # imm = 0x110
je 0x1529
jmp 0x1407
movl -0x18(%rbp), %eax
subl $0x112, %eax            # imm = 0x112
je 0x1538
jmp 0x1417
movl -0x18(%rbp), %eax
subl $0x152, %eax            # imm = 0x152
je 0x1503
jmp 0x1427
movl -0x18(%rbp), %eax
subl $0x153, %eax            # imm = 0x153
je 0x14dc
jmp 0x1437
movl -0x18(%rbp), %eax
subl $0x19a, %eax            # imm = 0x19A
jne 0x1553
jmp 0x1447
callq 0x1ae0
movl 0x3cae(%rip), %eax      # 0x5100
addl $-0x1, %eax
movl %eax, 0x3ca5(%rip)      # 0x5100
cmpl $0x0, 0x3c9e(%rip)      # 0x5100
jge 0x146e
movl $0x0, 0x3c92(%rip)      # 0x5100
jmp 0x158a
movl 0x3c87(%rip), %eax      # 0x5100
addl $0x1, %eax
movl %eax, 0x3c7e(%rip)      # 0x5100
movl 0x3c78(%rip), %eax      # 0x5100
cmpl 0x3c76(%rip), %eax      # 0x5104
jle 0x149c
movl 0x3c6e(%rip), %eax      # 0x5104
movl %eax, 0x3c64(%rip)      # 0x5100
jmp 0x158a
movl 0x3c61(%rip), %eax      # 0x5108
addl $-0x1, %eax
movl %eax, 0x3c58(%rip)      # 0x5108
cmpl $0x0, 0x3c51(%rip)      # 0x5108
jge 0x14c3
movl $0x0, 0x3c45(%rip)      # 0x5108
jmp 0x158a
movl 0x3c3a(%rip), %eax      # 0x5108
addl $0x1, %eax
movl %eax, 0x3c31(%rip)      # 0x5108
jmp 0x158a
movl 0x3c26(%rip), %eax      # 0x5108
subl $0xa, %eax
movl %eax, 0x3c1d(%rip)      # 0x5108
cmpl $0x0, 0x3c16(%rip)      # 0x5108
jge 0x14fe
movl $0x0, 0x3c0a(%rip)      # 0x5108
jmp 0x158a
movl 0x3bff(%rip), %eax      # 0x5108
addl $0xa, %eax
movl %eax, 0x3bf6(%rip)      # 0x5108
jmp 0x158a
callq 0x1b20
jmp 0x158a
callq 0x1c90
jmp 0x158a
callq 0x1ee0
jmp 0x158a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1f10
jmp 0x158a
xorl %edi, %edi
callq 0x1170
movslq 0x3bba(%rip), %rcx      # 0x5100
leaq 0x3bc3(%rip), %rax      # 0x5110
movb $0x20, (%rax,%rcx)
jmp 0x158a
callq 0x11a0
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x1588
movl -0x14(%rbp), %edi
callq 0x1050
movb %al, %dl
movslq 0x3b82(%rip), %rcx      # 0x5100
leaq 0x3b8b(%rip), %rax      # 0x5110
movb %dl, (%rax,%rcx)
jmp 0x158a
jmp 0x131f
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)