// File: /workspace/github_c_makefile_star2_O3/neovim[P]libvterm/bin/unterm.c
// Function: main
int main(int argc, char *argv[])
{
  rows = 25;
  cols = 80;

  int opt;
  while((opt = getopt(argc, argv, "f:l:c:")) != -1) {
    switch(opt) {
      case 'f':
        if(streq(optarg, "plain"))
          format = FORMAT_PLAIN;
        else if(streq(optarg, "sgr"))
          format = FORMAT_SGR;
        else {
          fprintf(stderr, "Unrecognised format '%s'\n", optarg);
          exit(1);
        }
        break;

      case 'l':
        rows = atoi(optarg);
        if(!rows)
          rows = 25;
        break;

      case 'c':
        cols = atoi(optarg);
        if(!cols)
          cols = 80;
        break;
    }
  }

  const char *file = argv[optind++];
  int fd = open(file, O_RDONLY);
  if(fd == -1) {
    fprintf(stderr, "Cannot open %s - %s\n", file, strerror(errno));
    exit(1);
  }

  vt = vterm_new(rows, cols);
  vterm_set_utf8(vt, true);

  vts = vterm_obtain_screen(vt);
  vterm_screen_set_callbacks(vts, &cb_screen, NULL);

  vterm_screen_reset(vts, 1);

  int len;
  char buffer[1024];
  while((len = read(fd, buffer, sizeof(buffer))) > 0) {
    vterm_input_write(vt, buffer, len);
  }

  for(int row = 0; row < rows; row++) {
    dump_row(row);
  }

  close(fd);

  vterm_free(vt);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rsi, %rbx
movl %edi, %ebp
movl $0x19, 0x2a48(%rip)     # 0x4150
movl $0x50, 0x2a2e(%rip)     # 0x4140
leaq 0x8ff(%rip), %r14       # 0x2018
movq 0x28b8(%rip), %r12      # 0x3fd8
leaq 0x8f8(%rip), %r15       # 0x201f
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1140
cmpl $0x65, %eax
jle 0x1776
cmpl $0x6c, %eax
je 0x1796
cmpl $0x66, %eax
jne 0x1727
movq (%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x10d0
testl %eax, %eax
je 0x17bf
movq %r13, %rdi
leaq 0x8c5(%rip), %rsi       # 0x2025
callq 0x10d0
testl %eax, %eax
jne 0x18d2
movb $0x1, 0x29e0(%rip)      # 0x4154
jmp 0x1727
cmpl $0x63, %eax
jne 0x17b4
movq (%r12), %rdi
callq 0x1150
testl %eax, %eax
movl $0x50, %ecx
cmovel %ecx, %eax
movl %eax, 0x29ac(%rip)      # 0x4140
jmp 0x1727
movq (%r12), %rdi
callq 0x1150
testl %eax, %eax
movl $0x19, %ecx
cmovel %ecx, %eax
movl %eax, 0x29a1(%rip)      # 0x4150
jmp 0x1727
cmpl $-0x1, %eax
jne 0x1727
jmp 0x17cb
movb $0x0, 0x298e(%rip)      # 0x4154
jmp 0x1727
movq 0x27fe(%rip), %rax      # 0x3fd0
movslq (%rax), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rax)
movq (%rbx,%rcx,8), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x1120
cmpl $-0x1, %eax
je 0x18da
movl %eax, %ebx
movl 0x2955(%rip), %edi      # 0x4150
movl 0x293f(%rip), %esi      # 0x4140
callq 0x10a0
movq %rax, 0x292b(%rip)      # 0x4138
movq %rax, %rdi
movl $0x1, %esi
callq 0x1030
movq 0x2917(%rip), %rdi      # 0x4138
callq 0x1190
movq %rax, 0x291b(%rip)      # 0x4148
leaq 0x28ac(%rip), %rsi      # 0x40e0
movq %rax, %rdi
xorl %edx, %edx
callq 0x1100
movq 0x2903(%rip), %rdi      # 0x4148
movl $0x1, %esi
callq 0x1070
movq %rsp, %rsi
movl $0x400, %edx            # imm = 0x400
movl %ebx, %edi
callq 0x10c0
testl %eax, %eax
jle 0x188f
movq %rsp, %r14
movq 0x28cc(%rip), %rdi      # 0x4138
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r14, %rsi
movq %rax, %rdx
callq 0x1060
movl $0x400, %edx            # imm = 0x400
movl %ebx, %edi
movq %r14, %rsi
callq 0x10c0
testl %eax, %eax
jg 0x1865
cmpl $0x0, 0x28ba(%rip)      # 0x4150
jle 0x18ab
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x12fc
incl %ebp
cmpl 0x28a7(%rip), %ebp      # 0x4150
jl 0x189a
movl %ebx, %edi
callq 0x10b0
movq 0x287f(%rip), %rdi      # 0x4138
callq 0x1130
xorl %eax, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x11b0
movq %r14, %rdi
callq 0x11d4