// File: /workspace/github_c_makefile_star2_O3/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
movq %rsi, 0x8(%rsp)
cmpl $0x1, %edi
je 0x1912
movl %edi, %ebp
xorl %edi, %edi
xorl %esi, %esi
callq 0x12ea
movb %al, 0x2d30(%rip)       # 0x4099
leaq -0x94(%rip), %rdi       # 0x12dc
callq 0x1b10
cmpl $0x2, %ebp
jl 0x1901
movl $0x1, %eax
leaq 0xc8a(%rip), %r14       # 0x2014
leaq 0xc89(%rip), %r13       # 0x201a
leaq 0xcac(%rip), %r12       # 0x2044
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%rsp)
cltq
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1070
testl %eax, %eax
je 0x151d
movq %r15, %rdi
leaq 0xc56(%rip), %rsi       # 0x201d
callq 0x1070
testl %eax, %eax
je 0x1538
movq %r15, %rdi
leaq 0xc51(%rip), %rsi       # 0x202f
callq 0x1070
testl %eax, %eax
je 0x1562
movq %r12, %rbx
movq %r15, %rdi
leaq 0xcc2(%rip), %r12       # 0x20ba
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x158c
movq %r15, %rdi
movq %rbx, %r12
movq %rbx, %rsi
callq 0x1070
testl %eax, %eax
je 0x15c7
movq %r15, %rdi
leaq 0xc23(%rip), %r13       # 0x204b
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x15ff
movq %r15, %rdi
leaq 0xc12(%rip), %rsi       # 0x2054
callq 0x1070
testl %eax, %eax
je 0x1626
movq %r15, %rdi
leaq 0xc11(%rip), %rsi       # 0x206a
callq 0x1070
testl %eax, %eax
leaq 0xc44(%rip), %rbx       # 0x20ab
leaq 0xc49(%rip), %r13       # 0x20b7
je 0x1664
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1070
testl %eax, %eax
je 0x1793
movq %r15, %rdi
movq %r13, %rsi
callq 0x1070
testl %eax, %eax
je 0x17b2
movq %r15, %rdi
leaq 0xc1d(%rip), %rbx       # 0x20c1
movq %rbx, %rsi
callq 0x1070
testl %eax, %eax
je 0x17d4
movq %r15, %rdi
leaq 0xc10(%rip), %rsi       # 0x20ce
callq 0x1070
testl %eax, %eax
leaq 0xb4e(%rip), %r13       # 0x201a
je 0x182b
movq %r15, %rdi
leaq 0xc04(%rip), %rsi       # 0x20e0
callq 0x1070
testl %eax, %eax
je 0x1845
movq %r15, %rdi
leaq 0xbdf(%rip), %rsi       # 0x20d2
callq 0x1070
testl %eax, %eax
jne 0x1917
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
callq 0x1aa7
leaq 0xbd5(%rip), %rdi       # 0x20ed
jmp 0x185d
movq %r13, %rdi
xorl %eax, %eax
callq 0x1060
movl 0x4(%rsp), %eax
cmpl %ebp, %eax
jl 0x1398
jmp 0x1901
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x2775(%rip), %rcx      # 0x3cc0
callq 0x191f
cmpl $0x1, %eax
je 0x15bb
testl %eax, %eax
jne 0x1527
leaq 0xac7(%rip), %rdi       # 0x2027
jmp 0x1520
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x2763(%rip), %rcx      # 0x3cd8
callq 0x191f
cmpl $0x1, %eax
je 0x15f3
testl %eax, %eax
jne 0x1527
leaq 0xab4(%rip), %rdi       # 0x203e
jmp 0x1520
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x2819(%rip), %rcx      # 0x3db8
callq 0x191f
movl $0x5, %edi
movl %eax, %esi
movq %r12, %rdx
callq 0x195c
movq %rbx, %r12
jmp 0x1527
leaq 0xa69(%rip), %rdi       # 0x202b
jmp 0x1520
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x27de(%rip), %rcx      # 0x3db8
callq 0x191f
movl $0x19, %edi
movl %eax, %esi
movq %r12, %rdx
callq 0x195c
jmp 0x1527
leaq 0xa47(%rip), %rdi       # 0x2041
jmp 0x1520
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x27a6(%rip), %rcx      # 0x3db8
callq 0x191f
movl $0xc, %edi
movl %eax, %esi
movq %r13, %rdx
jmp 0x17f6
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x26b7(%rip), %rcx      # 0x3cf0
callq 0x191f
cmpl $0x3, %eax
leaq 0x9d2(%rip), %r13       # 0x201a
jae 0x16aa
leal 0x1(,%rax,2), %esi
leaq 0xa0b(%rip), %rdi       # 0x2063
xorl %eax, %eax
callq 0x1060
jmp 0x1527
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x26a1(%rip), %rcx      # 0x3d18
callq 0x191f
cmpl $0x3, %eax
leaq 0x994(%rip), %r13       # 0x201a
ja 0x1527
movl %eax, %eax
leaq 0x96f(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x9e2(%rip), %rdi       # 0x2087
jmp 0x1520
jne 0x1527
leaq 0xbf0(%rip), %rdi       # 0x22a7
leaq 0x9a9(%rip), %rsi       # 0x2067
xorl %eax, %eax
callq 0x1060
xorl %r15d, %r15d
movq %r13, %r14
testq %r15, %r15
je 0x16d8
movq %r15, %rdi
callq 0x1030
movl $0x90, %edi
callq 0x1abe
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
callq 0x1080
movzbl %al, %ecx
cmpl $0x5c, %ecx
sete %dl
cmpl $0x9c, %ecx
je 0x172a
andb %r12b, %dl
jne 0x172a
cmpl $0x1b, %ecx
setne %cl
orb %cl, %r12b
testb $0x1, %r12b
je 0x171d
incl %r15d
movb %al, 0x10(%rsp,%r13)
xorb $0x1, %r12b
movl %r15d, %r13d
cmpl $0x1f, %r15d
jb 0x16eb
movslq %r15d, %rax
leaq 0x10(%rsp), %rdi
movb $0x0, 0x1(%rax,%rdi)
callq 0x1100
testq %rax, %rax
movq %r14, %r13
leaq 0x8cb(%rip), %r14       # 0x2014
movq %rbx, %r12
je 0x1527
movq %rax, %r15
movq %rax, %rdi
callq 0x1050
cmpq $0x2, %rax
jb 0x1527
cmpb $0x20, -0x2(%r15,%rax)
jne 0x1782
cmpb $0x71, -0x1(%r15,%rax)
jne 0x1782
cmpb $0x0, (%r15,%rax)
je 0x186c
leaq 0xb6f(%rip), %rdi       # 0x22f8
callq 0x1040
jmp 0x16c8
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x2612(%rip), %rcx      # 0x3db8
callq 0x191f
movl $0x3ec, %edi            # imm = 0x3EC
jmp 0x17f1
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x25f3(%rip), %rcx      # 0x3db8
callq 0x191f
movl $0x419, %edi            # imm = 0x419
jmp 0x161c
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
leaq 0x25d1(%rip), %rcx      # 0x3db8
callq 0x191f
movl $0x7d4, %edi            # imm = 0x7D4
movl %eax, %esi
movq %rbx, %rdx
callq 0x195c
leaq 0x818(%rip), %r13       # 0x201a
jmp 0x1527
leaq 0x88b(%rip), %rdi       # 0x2099
jmp 0x1520
leaq 0x888(%rip), %rdi       # 0x20a2
jmp 0x1520
leaq 0x86a(%rip), %rdi       # 0x2090
jmp 0x1520
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
callq 0x1aa7
leaq 0x895(%rip), %rdi       # 0x20d8
jmp 0x185d
leaq 0x4(%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
callq 0x1aa7
leaq 0x888(%rip), %rdi       # 0x20e5
movq %rax, %rsi
xorl %eax, %eax
callq 0x1060
jmp 0x1527
cmpb $0x31, (%r15)
jne 0x1527
cmpb $0x24, 0x1(%r15)
jne 0x1527
cmpb $0x72, 0x2(%r15)
jne 0x1527
addq $0x3, %r15
movq %r15, %rdi
leaq 0xa16(%rip), %rsi       # 0x22b0
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x10a0
cmpl $0x1, %eax
jne 0x1527
movl 0x10(%rsp), %eax
cmpl $0x6, %eax
ja 0x1527
movl $0x6, %ecx
btl %eax, %ecx
jb 0x18f0
movl $0x18, %ecx
btl %eax, %ecx
jb 0x18e7
movl $0x60, %ecx
btl %eax, %ecx
jae 0x1527
leaq 0x9e8(%rip), %rdi       # 0x22cd
jmp 0x18f7
leaq 0x9ec(%rip), %rdi       # 0x22da
jmp 0x18f7
leaq 0x9f2(%rip), %rdi       # 0x22e9
callq 0x1040
jmp 0x1527
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1144
movq %r15, %rdi
callq 0x1120