// File: /workspace/github_c_makefile_star2_O1/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, 0x2a28(%rip)     # 0x4150
movl $0x50, 0x2a0e(%rip)     # 0x4140
leaq 0x8e3(%rip), %r14       # 0x201c
movq 0x2898(%rip), %r12      # 0x3fd8
leaq 0x8dc(%rip), %r15       # 0x2023
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1140
cmpl $0x65, %eax
jle 0x1796
cmpl $0x6c, %eax
je 0x17b6
cmpl $0x66, %eax
jne 0x1747
movq (%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x10d0
testl %eax, %eax
je 0x17df
movq %r13, %rdi
leaq 0x8a9(%rip), %rsi       # 0x2029
callq 0x10d0
testl %eax, %eax
jne 0x18f2
movb $0x1, 0x29c0(%rip)      # 0x4154
jmp 0x1747
cmpl $0x63, %eax
jne 0x17d4
movq (%r12), %rdi
callq 0x1150
testl %eax, %eax
movl $0x50, %ecx
cmovel %ecx, %eax
movl %eax, 0x298c(%rip)      # 0x4140
jmp 0x1747
movq (%r12), %rdi
callq 0x1150
testl %eax, %eax
movl $0x19, %ecx
cmovel %ecx, %eax
movl %eax, 0x2981(%rip)      # 0x4150
jmp 0x1747
cmpl $-0x1, %eax
jne 0x1747
jmp 0x17eb
movb $0x0, 0x296e(%rip)      # 0x4154
jmp 0x1747
movq 0x27de(%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 0x18fa
movl %eax, %ebx
movl 0x2935(%rip), %edi      # 0x4150
movl 0x291f(%rip), %esi      # 0x4140
callq 0x10a0
movq %rax, 0x290b(%rip)      # 0x4138
movq %rax, %rdi
movl $0x1, %esi
callq 0x1030
movq 0x28f7(%rip), %rdi      # 0x4138
callq 0x1190
movq %rax, 0x28fb(%rip)      # 0x4148
leaq 0x288c(%rip), %rsi      # 0x40e0
movq %rax, %rdi
xorl %edx, %edx
callq 0x1100
movq 0x28e3(%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 0x18af
movq %rsp, %r14
movq 0x28ac(%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 0x1885
cmpl $0x0, 0x289a(%rip)      # 0x4150
jle 0x18cb
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x12fc
incl %ebp
cmpl 0x2887(%rip), %ebp      # 0x4150
jl 0x18ba
movl %ebx, %edi
callq 0x10b0
movq 0x285f(%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