// File: /workspace/github_c_makefile_star2_O1/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 $0x1, 0xc(%rsp)
cmpl $0x1, %edi
je 0x18bb
movq %rsi, %rbx
movl %edi, %ebp
xorl %edi, %edi
xorl %esi, %esi
callq 0x12ea
movb %al, 0x2d2a(%rip)       # 0x4099
leaq -0x9a(%rip), %rdi       # 0x12dc
callq 0x1ad0
movl 0xc(%rsp), %eax
cmpl %ebp, %eax
jge 0x18aa
leaq 0xc86(%rip), %r14       # 0x2014
leaq 0xd25(%rip), %r12       # 0x20ba
movq %r12, %r13
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
cltq
movq (%rbx,%rax,8), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1070
testl %eax, %eax
je 0x1509
movq %r15, %rdi
leaq 0xc5b(%rip), %rsi       # 0x201d
callq 0x1070
testl %eax, %eax
je 0x151c
movq %r15, %rdi
leaq 0xc56(%rip), %rsi       # 0x202f
callq 0x1070
testl %eax, %eax
je 0x1548
movq %r15, %rdi
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x1574
movq %r15, %rdi
leaq 0xc41(%rip), %r12       # 0x2044
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x159d
movq %r15, %rdi
leaq 0xc2e(%rip), %r12       # 0x204b
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x15c6
movq %r15, %rdi
leaq 0xc1d(%rip), %rsi       # 0x2054
callq 0x1070
testl %eax, %eax
je 0x15ff
movq %r15, %rdi
leaq 0xc1c(%rip), %rsi       # 0x206a
callq 0x1070
testl %eax, %eax
je 0x1631
movq %r15, %rdi
leaq 0xc46(%rip), %r12       # 0x20ab
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x1756
movq %r15, %rdi
leaq 0xc38(%rip), %r12       # 0x20b7
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x1776
movq %r15, %rdi
leaq 0xc28(%rip), %r12       # 0x20c1
movq %r12, %rsi
callq 0x1070
testl %eax, %eax
je 0x1796
movq %r15, %rdi
leaq 0xc1b(%rip), %rsi       # 0x20ce
callq 0x1070
testl %eax, %eax
je 0x17da
movq %r15, %rdi
leaq 0xc16(%rip), %rsi       # 0x20e0
callq 0x1070
testl %eax, %eax
je 0x186b
movq %r15, %rdi
leaq 0xbf1(%rip), %rsi       # 0x20d2
callq 0x1070
testl %eax, %eax
jne 0x18c0
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1a66
leaq 0xbe9(%rip), %rdi       # 0x20ed
jmp 0x1881
leaq 0xb0a(%rip), %rdi       # 0x201a
xorl %eax, %eax
callq 0x1060
jmp 0x15eb
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x2793(%rip), %rcx      # 0x3cc0
callq 0x18c8
cmpl $0x1, %eax
je 0x1591
testl %eax, %eax
jne 0x15eb
leaq 0xae1(%rip), %rdi       # 0x2027
jmp 0x1510
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x277f(%rip), %rcx      # 0x3cd8
callq 0x18c8
cmpl $0x1, %eax
je 0x15ba
testl %eax, %eax
jne 0x15eb
leaq 0xacc(%rip), %rdi       # 0x203e
jmp 0x1510
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x2833(%rip), %rcx      # 0x3db8
callq 0x18c8
movl $0x5, %edi
jmp 0x15e1
leaq 0xa93(%rip), %rdi       # 0x202b
jmp 0x1510
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x280a(%rip), %rcx      # 0x3db8
callq 0x18c8
movl $0x19, %edi
jmp 0x15e1
leaq 0xa80(%rip), %rdi       # 0x2041
jmp 0x1510
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x27e1(%rip), %rcx      # 0x3db8
callq 0x18c8
movl $0xc, %edi
movl %eax, %esi
movq %r12, %rdx
callq 0x1905
movl 0xc(%rsp), %eax
cmpl %ebp, %eax
movq %r13, %r12
jl 0x1398
jmp 0x18aa
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x26e0(%rip), %rcx      # 0x3cf0
callq 0x18c8
cmpl $0x3, %eax
jae 0x166a
leal 0x1(,%rax,2), %esi
leaq 0xa3b(%rip), %rdi       # 0x2063
xorl %eax, %eax
callq 0x1060
jmp 0x15eb
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x26d6(%rip), %rcx      # 0x3d18
callq 0x18c8
cmpl $0x3, %eax
ja 0x15eb
movl %eax, %eax
leaq 0x9af(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa22(%rip), %rdi       # 0x2087
jmp 0x1510
jne 0x15eb
leaq 0xc30(%rip), %rdi       # 0x22a7
leaq 0x9e9(%rip), %rsi       # 0x2067
xorl %eax, %eax
callq 0x1060
xorl %r15d, %r15d
testq %r15, %r15
je 0x1695
movq %r15, %rdi
callq 0x1030
movl $0x90, %edi
callq 0x1a7d
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpl $0x1e, %r15d
ja 0x16f3
callq 0x1080
movzbl %al, %ecx
cmpl $0x9c, %ecx
je 0x16c6
cmpl $0x5c, %ecx
sete %dl
testb %r12b, %dl
je 0x16ce
xorl %ecx, %ecx
testb %cl, %cl
jne 0x16a5
jmp 0x16f3
xorb $0x1, %r12b
cmpl $0x1b, %ecx
sete %dl
movb $0x1, %cl
testb %r12b, %dl
jne 0x16ee
movslq %r15d, %rdx
incl %r15d
movb %al, 0x10(%rsp,%rdx)
xorl %r12d, %r12d
jmp 0x16c8
movb $0x1, %r12b
jmp 0x16c8
movslq %r15d, %rax
leaq 0x10(%rsp), %rdi
movb $0x0, 0x1(%rax,%rdi)
callq 0x1100
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1833
movq %rax, %r15
movq %rax, %rdi
callq 0x1050
cmpq $0x2, %rax
jb 0x1833
leaq (%r15,%rax), %rdi
addq $-0x2, %rdi
leaq 0x92f(%rip), %rsi       # 0x2067
callq 0x1070
testl %eax, %eax
je 0x17f5
leaq 0xbac(%rip), %rdi       # 0x22f8
callq 0x1040
jmp 0x1688
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x2651(%rip), %rcx      # 0x3db8
callq 0x18c8
movl $0x3ec, %edi            # imm = 0x3EC
jmp 0x15e1
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x2631(%rip), %rcx      # 0x3db8
callq 0x18c8
movl $0x419, %edi            # imm = 0x419
jmp 0x15e1
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x2611(%rip), %rcx      # 0x3db8
callq 0x18c8
movl $0x7d4, %edi            # imm = 0x7D4
jmp 0x15e1
leaq 0x8dc(%rip), %rdi       # 0x2099
jmp 0x1510
leaq 0x8d9(%rip), %rdi       # 0x20a2
jmp 0x1510
leaq 0x8bb(%rip), %rdi       # 0x2090
jmp 0x1510
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1a66
leaq 0x8e8(%rip), %rdi       # 0x20d8
jmp 0x1881
cmpb $0x31, (%r15)
jne 0x1833
cmpb $0x24, 0x1(%r15)
jne 0x1833
cmpb $0x72, 0x2(%r15)
jne 0x1833
addq $0x3, %r15
movq %r15, %rdi
leaq 0xa99(%rip), %rsi       # 0x22b0
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x10a0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x1, %eax
jne 0x1833
movl 0x10(%rsp), %r12d
cmpl $0x6, %r12d
ja 0x15eb
movl $0x6, %eax
btl %r12d, %eax
jb 0x1899
movl $0x18, %eax
btl %r12d, %eax
jb 0x1890
movl $0x60, %eax
btl %r12d, %eax
jae 0x15eb
leaq 0xa64(%rip), %rdi       # 0x22cd
jmp 0x18a0
leaq 0xc(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1a66
leaq 0x864(%rip), %rdi       # 0x20e5
movq %rax, %rsi
xorl %eax, %eax
callq 0x1060
jmp 0x15eb
leaq 0xa43(%rip), %rdi       # 0x22da
jmp 0x18a0
leaq 0xa49(%rip), %rdi       # 0x22e9
callq 0x1040
jmp 0x15eb
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