// File: /workspace/github_c_makefile_star2_O2/neovim[P]libvterm/bin/vterm-ctrl.c
// Function: main
int main(int argc, char *argv[])
{
  int argi = 1;

  if(argc == 1)
    usage(0);

  wasicanon = seticanon(false, false);
  atexit(restoreicanon);

  while(argi < argc) {
    const char *arg = argv[argi++];

    if(streq(arg, "reset")) {
      printf("\x1b" "c");
    }
    else if(streq(arg, "s8c1t")) {
      switch(getchoice(&argi, argc, argv, (const char *[]){"off", "on", NULL})) {
      case 0:
        printf("\x1b F"); break;
      case 1:
        printf("\x1b G"); break;
      }
    }
    else if(streq(arg, "keypad")) {
      switch(getchoice(&argi, argc, argv, (const char *[]){"app", "num", NULL})) {
      case 0:
        printf("\x1b="); break;
      case 1:
        printf("\x1b>"); break;
      }
    }
    else if(streq(arg, "screen")) {
      do_dec_mode(5, getboolq(&argi, argc, argv), "screen");
    }
    else if(streq(arg, "cursor")) {
      do_dec_mode(25, getboolq(&argi, argc, argv), "cursor");
    }
    else if(streq(arg, "curblink")) {
      do_dec_mode(12, getboolq(&argi, argc, argv), "curblink");
    }
    else if(streq(arg, "curshape")) {
      // TODO: This ought to query the current value of DECSCUSR because it
      //   may need blinking on or off
      int shape = getchoice(&argi, argc, argv, (const char *[]){"block", "under", "bar", "query", NULL});
      switch(shape) {
        case 3: // query
          shape = query_rqss_numeric(" q");
          switch(shape) {
            case 1: case 2:
              printf("curshape block\n");
              break;
            case 3: case 4:
              printf("curshape under\n");
              break;
            case 5: case 6:
              printf("curshape bar\n");
              break;
          }
          break;

        case 0:
        case 1:
        case 2:
          printf("\x1b[%d q", 1 + (shape * 2));
          break;
      }
    }
    else if(streq(arg, "mouse")) {
      switch(getchoice(&argi, argc, argv, (const char *[]){"off", "click", "clickdrag", "motion", NULL})) {
      case 0:
        printf("\x1b[?1000l"); break;
      case 1:
        printf("\x1b[?1000h"); break;
      case 2:
        printf("\x1b[?1002h"); break;
      case 3:
        printf("\x1b[?1003h"); break;
      }
    }
    else if(streq(arg, "reportfocus")) {
      do_dec_mode(1004, getboolq(&argi, argc, argv), "reportfocus");
    }
    else if(streq(arg, "altscreen")) {
      do_dec_mode(1049, getboolq(&argi, argc, argv), "altscreen");
    }
    else if(streq(arg, "bracketpaste")) {
      do_dec_mode(2004, getboolq(&argi, argc, argv), "bracketpaste");
    }
    else if(streq(arg, "icontitle")) {
      printf("\x1b]0;%s\a", getvalue(&argi, argc, argv));
    }
    else if(streq(arg, "icon")) {
      printf("\x1b]1;%s\a", getvalue(&argi, argc, argv));
    }
    else if(streq(arg, "title")) {
      printf("\x1b]2;%s\a", getvalue(&argi, argc, argv));
    }
    else {
      fprintf(stderr, "Unrecognised command %s\n", arg);
      exit(1);
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edi, 0x8(%rsp)
cmpl $0x1, %edi
je 0x17f5
movq %rsi, %r12
xorl %edi, %edi
xorl %esi, %esi
callq 0x1218
movb %al, 0x2e02(%rip)       # 0x4099
leaq -0x92(%rip), %rdi       # 0x120c
callq 0x1a80
pushq $0x1
popq %rax
leaq 0xd67(%rip), %r14       # 0x2014
leaq 0xd69(%rip), %r13       # 0x201d
leaq 0xdff(%rip), %rbx       # 0x20ba
cmpl 0x8(%rsp), %eax
jge 0x17e4
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
cltq
movq (%r12,%rax,8), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1070
testl %eax, %eax
je 0x1444
movq %r15, %rdi
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x145b
movq %r15, %rdi
leaq 0xd2d(%rip), %rsi       # 0x202f
callq 0x1070
testl %eax, %eax
je 0x1485
movq %r12, %rbp
movq %r15, %rdi
movq %rbx, %r12
movq %rbx, %rsi
callq 0x1070
testl %eax, %eax
je 0x14af
movq %r15, %rdi
leaq 0xd12(%rip), %r13       # 0x2044
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x14de
movq %r15, %rdi
leaq 0xcff(%rip), %r13       # 0x204b
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
movq %rbp, %r12
je 0x1502
movq %r15, %rdi
leaq 0xceb(%rip), %rsi       # 0x2054
callq 0x1070
testl %eax, %eax
je 0x152c
movq %r15, %rdi
leaq 0xcea(%rip), %rsi       # 0x206a
callq 0x1070
testl %eax, %eax
leaq 0xd1d(%rip), %r13       # 0x20ab
je 0x156a
movq %r15, %rdi
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x1692
movq %r15, %rdi
leaq 0xd06(%rip), %r13       # 0x20b7
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x16ad
movq %r15, %rdi
leaq 0xcf6(%rip), %r13       # 0x20c1
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x16c8
movq %r15, %rdi
leaq 0xce9(%rip), %rsi       # 0x20ce
callq 0x1070
testl %eax, %eax
je 0x1707
movq %r15, %rdi
leaq 0xce4(%rip), %rsi       # 0x20e0
callq 0x1070
testl %eax, %eax
leaq 0xc13(%rip), %r13       # 0x201d
je 0x172e
movq %r15, %rdi
leaq 0xcb8(%rip), %rsi       # 0x20d2
callq 0x1070
testl %eax, %eax
jne 0x1841
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x1a08
leaq 0xcae(%rip), %rdi       # 0x20ed
jmp 0x1746
leaq 0xbcf(%rip), %rdi       # 0x201a
xorl %eax, %eax
callq 0x1060
movl 0xc(%rsp), %eax
jmp 0x12bb
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
leaq 0x2852(%rip), %rcx      # 0x3cc0
callq 0x1864
cmpl $0x1, %eax
je 0x14d2
testl %eax, %eax
jne 0x1452
leaq 0xba4(%rip), %rdi       # 0x2027
jmp 0x144b
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
leaq 0x2840(%rip), %rcx      # 0x3cd8
callq 0x1864
cmpl $0x1, %eax
je 0x14f6
testl %eax, %eax
jne 0x1452
leaq 0xb91(%rip), %rdi       # 0x203e
jmp 0x144b
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %rbp, %rdx
callq 0x19fc
pushq $0x5
popq %rdi
movl %eax, %esi
movq %r12, %rdx
movq %rbp, %r12
callq 0x18ba
jmp 0x1452
leaq 0xb52(%rip), %rdi       # 0x202b
jmp 0x144b
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %rbp, %r12
movq %rbp, %rdx
callq 0x19fc
pushq $0x19
jmp 0x1515
leaq 0xb44(%rip), %rdi       # 0x2041
jmp 0x144b
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x19fc
pushq $0xc
popq %rdi
movl %eax, %esi
movq %r13, %rdx
callq 0x18ba
leaq 0xaf6(%rip), %r13       # 0x201d
jmp 0x1452
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
leaq 0x27b1(%rip), %rcx      # 0x3cf0
callq 0x1864
cmpl $0x3, %eax
leaq 0xacf(%rip), %r13       # 0x201d
jae 0x15b0
leal 0x1(,%rax,2), %esi
leaq 0xb05(%rip), %rdi       # 0x2063
xorl %eax, %eax
callq 0x1060
jmp 0x1452
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
leaq 0x279b(%rip), %rcx      # 0x3d18
callq 0x1864
cmpl $0x3, %eax
leaq 0xa91(%rip), %r13       # 0x201d
ja 0x1452
movl %eax, %eax
leaq 0xa69(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xadc(%rip), %rdi       # 0x2087
jmp 0x144b
jne 0x1452
leaq 0xcea(%rip), %rdi       # 0x22a7
leaq 0xaa3(%rip), %rsi       # 0x2067
xorl %eax, %eax
callq 0x1060
xorl %r15d, %r15d
movq %r13, %r14
movq %r15, %rdi
callq 0x1030
movl $0x90, %edi
callq 0x1a3e
xorl %r12d, %r12d
xorl %r15d, %r15d
movslq %r12d, %r13
cmpl $0x1e, %r13d
ja 0x162b
callq 0x1080
movzbl %al, %ecx
cmpl $0x5c, %ecx
sete %dl
cmpl $0x9c, %ecx
je 0x162b
andb %r15b, %dl
jne 0x162b
cmpl $0x1b, %ecx
setne %cl
orb %cl, %r15b
testb $0x1, %r15b
je 0x1625
leal 0x1(%r13), %r12d
movb %al, 0x10(%rsp,%r13)
xorb $0x1, %r15b
jmp 0x15e9
leaq 0x10(%rsp), %rdi
movb $0x0, 0x1(%r13,%rdi)
callq 0x1100
testq %rax, %rax
movq %r14, %r13
leaq 0x9cc(%rip), %r14       # 0x2014
movq %rbp, %r12
je 0x1452
movq %rax, %r15
movq %rax, %rdi
callq 0x1050
cmpq $0x2, %rax
jb 0x1452
cmpb $0x20, -0x2(%r15,%rax)
jne 0x1681
cmpb $0x71, -0x1(%r15,%rax)
jne 0x1681
cmpb $0x0, (%r15,%rax)
je 0x1755
leaq 0xc70(%rip), %rdi       # 0x22f8
callq 0x1040
jmp 0x15ce
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x19fc
movl $0x3ec, %edi            # imm = 0x3EC
jmp 0x1516
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x19fc
movl $0x419, %edi            # imm = 0x419
jmp 0x1516
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x19fc
movl $0x7d4, %edi            # imm = 0x7D4
jmp 0x1516
leaq 0x9af(%rip), %rdi       # 0x2099
jmp 0x144b
leaq 0x9ac(%rip), %rdi       # 0x20a2
jmp 0x144b
leaq 0x98e(%rip), %rdi       # 0x2090
jmp 0x144b
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x1a08
leaq 0x9b9(%rip), %rdi       # 0x20d8
movq %rax, %rsi
xorl %eax, %eax
callq 0x1060
jmp 0x1520
leaq 0xc(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
callq 0x1a08
leaq 0x99f(%rip), %rdi       # 0x20e5
movq %rax, %rsi
xorl %eax, %eax
callq 0x1060
jmp 0x1452
cmpb $0x31, (%r15)
jne 0x1452
cmpb $0x24, 0x1(%r15)
jne 0x1452
cmpb $0x72, 0x2(%r15)
jne 0x1452
addq $0x3, %r15
movq %r15, %rdi
leaq 0xb2d(%rip), %rsi       # 0x22b0
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x10a0
cmpl $0x1, %eax
jne 0x1452
movl 0x10(%rsp), %eax
cmpl $0x6, %eax
ja 0x1452
pushq $0x6
popq %rcx
btl %eax, %ecx
jb 0x17d3
pushq $0x18
popq %rcx
btl %eax, %ecx
jb 0x17ca
pushq $0x60
popq %rcx
btl %eax, %ecx
jae 0x1452
leaq 0xb05(%rip), %rdi       # 0x22cd
jmp 0x17da
leaq 0xb09(%rip), %rdi       # 0x22da
jmp 0x17da
leaq 0xb0f(%rip), %rdi       # 0x22e9
callq 0x1040
jmp 0x1452
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x27f4(%rip), %r14      # 0x3ff0
movq (%r14), %rcx
leaq 0x908(%rip), %rdi       # 0x210e
pushq $0x2c
popq %rsi
pushq $0x1
popq %rdx
callq 0x10f0
leaq 0x2528(%rip), %r15      # 0x3d40
leaq 0x91c(%rip), %rbx       # 0x213b
movq (%r15), %rdx
testq %rdx, %rdx
je 0x183a
movq (%r14), %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1090
addq $0x8, %r15
jmp 0x181f
xorl %edi, %edi
callq 0x10e0
movq 0x27a8(%rip), %rax      # 0x3ff0
movq (%rax), %rdi
leaq 0x8a3(%rip), %rsi       # 0x20f5
movq %r15, %rdx
xorl %eax, %eax
callq 0x1090
pushq $0x1
popq %rdi
callq 0x10e0