// File: /workspace/github_c_makefile_star2_O2/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, 0x2aec(%rip)     # 0x4150
movl $0x50, 0x2ad2(%rip)     # 0x4140
leaq 0x9a7(%rip), %r14       # 0x201c
movq 0x295c(%rip), %r12      # 0x3fd8
pushq $0x19
popq %r15
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1140
cmpl $0x63, %eax
je 0x16da
cmpl $0x66, %eax
je 0x16a3
cmpl $0x6c, %eax
je 0x16f3
cmpl $-0x1, %eax
jne 0x1680
jmp 0x1719
movq (%r12), %r13
movq %r13, %rdi
leaq 0x972(%rip), %rsi       # 0x2023
callq 0x10d0
testl %eax, %eax
je 0x170d
movq %r13, %rdi
leaq 0x965(%rip), %rsi       # 0x2029
callq 0x10d0
testl %eax, %eax
jne 0x1805
movb $0x1, 0x2a7c(%rip)      # 0x4154
jmp 0x1680
movq (%r12), %rdi
callq 0x1150
testl %eax, %eax
pushq $0x50
popq %rcx
cmovel %ecx, %eax
movl %eax, 0x2a4f(%rip)      # 0x4140
jmp 0x1680
movq (%r12), %rdi
callq 0x1150
testl %eax, %eax
cmovel %r15d, %eax
movl %eax, 0x2a48(%rip)      # 0x4150
jmp 0x1680
movb $0x0, 0x2a40(%rip)      # 0x4154
jmp 0x1680
movq 0x28b0(%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 0x1828
movl %eax, %ebx
movl 0x2a07(%rip), %edi      # 0x4150
movl 0x29f1(%rip), %esi      # 0x4140
callq 0x10a0
movq %rax, 0x29dd(%rip)      # 0x4138
pushq $0x1
popq %rbp
movq %rax, %rdi
movl %ebp, %esi
callq 0x1030
movq 0x29c9(%rip), %rdi      # 0x4138
callq 0x1190
movq %rax, 0x29cd(%rip)      # 0x4148
leaq 0x295e(%rip), %rsi      # 0x40e0
movq %rax, %rdi
xorl %edx, %edx
callq 0x1100
movq 0x29b5(%rip), %rdi      # 0x4148
movl %ebp, %esi
callq 0x1070
movq %rsp, %r14
movl $0x400, %edx            # imm = 0x400
movl %ebx, %edi
movq %r14, %rsi
callq 0x10c0
testl %eax, %eax
jle 0x17c9
movq 0x2981(%rip), %rdi      # 0x4138
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r14, %rsi
movq %rax, %rdx
callq 0x1060
jmp 0x179d
xorl %ebp, %ebp
cmpl 0x297f(%rip), %ebp      # 0x4150
jge 0x17de
movl %ebp, %edi
callq 0x129c
incl %ebp
jmp 0x17cb
movl %ebx, %edi
callq 0x10b0
movq 0x294c(%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 0x27ec(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x817(%rip), %rsi       # 0x202d
movq %r13, %rdx
xorl %eax, %eax
callq 0x10e0
pushq $0x1
popq %rdi
callq 0x1160
movq 0x27c9(%rip), %rax      # 0x3ff8
movq (%rax), %rbx
callq 0x1050
movl (%rax), %edi
callq 0x1180
leaq 0x802(%rip), %rsi       # 0x2047
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x10e0
jmp 0x1820