// File: /workspace/github_c_makefile_star2_O2/neovim[P]libvterm/src/state.c
// Function: on_escape
static int on_escape(const char *bytes, size_t len, void *user)
{
  VTermState *state = user;

  /* Easier to decode this from the first byte, even though the final
   * byte terminates it
   */
  switch(bytes[0]) {
  case ' ':
    if(len != 2)
      return 0;

    switch(bytes[1]) {
      case 'F': // S7C1T
        state->vt->mode.ctrl8bit = 0;
        break;

      case 'G': // S8C1T
        state->vt->mode.ctrl8bit = 1;
        break;

      default:
        return 0;
    }
    return 2;

  case '#':
    if(len != 2)
      return 0;

    switch(bytes[1]) {
      case '3': // DECDHL top
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_TOP);
        break;

      case '4': // DECDHL bottom
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_BOTTOM);
        break;

      case '5': // DECSWL
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_OFF, DHL_OFF);
        break;

      case '6': // DECDWL
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_OFF);
        break;

      case '8': // DECALN
      {
        VTermPos pos;
        uint32_t E[] = { 'E', 0 };
        for(pos.row = 0; pos.row < state->rows; pos.row++)
          for(pos.col = 0; pos.col < ROWWIDTH(state, pos.row); pos.col++)
            putglyph(state, E, 1, pos);
        break;
      }

      default:
        return 0;
    }
    return 2;

  case '(': case ')': case '*': case '+': // SCS
    if(len != 2)
      return 0;

    {
      int setnum = bytes[0] - 0x28;
      VTermEncoding *newenc = vterm_lookup_encoding(ENC_SINGLE_94, bytes[1]);

      if(newenc) {
        state->encoding[setnum].enc = newenc;

        if(newenc->init)
          (*newenc->init)(newenc, state->encoding[setnum].data);
      }
    }

    return 2;

  case '7': // DECSC
    savecursor(state, 1);
    return 1;

  case '8': // DECRC
    savecursor(state, 0);
    return 1;

  case '<': // Ignored by VT100. Used in VT52 mode to switch up to VT100
    return 1;

  case '=': // DECKPAM
    state->mode.keypad = 1;
    return 1;

  case '>': // DECKPNM
    state->mode.keypad = 0;
    return 1;

  case 'c': // RIS - ECMA-48 8.3.105
  {
    VTermPos oldpos = state->pos;
    vterm_state_reset(state, 1);
    if(state->callbacks && state->callbacks->movecursor)
      (*state->callbacks->movecursor)(state->pos, oldpos, state->mode.cursor_visible, state->cbdata);
    return 1;
  }

  case 'n': // LS2 - ECMA-48 8.3.78
    state->gl_set = 2;
    return 1;

  case 'o': // LS3 - ECMA-48 8.3.80
    state->gl_set = 3;
    return 1;

  case '~': // LS1R - ECMA-48 8.3.77
    state->gr_set = 1;
    return 1;

  case '}': // LS2R - ECMA-48 8.3.79
    state->gr_set = 2;
    return 1;

  case '|': // LS3R - ECMA-48 8.3.81
    state->gr_set = 3;
    return 1;

  default:
    return 0;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movzbl (%rdi), %r15d
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
leal -0x37(%r15), %eax
cmpl $0x7, %eax
jbe 0x6da4
leal -0x28(%r15), %eax
cmpl $0x4, %eax
jb 0x6dc0
cmpl $0x7e, %r15d
je 0x6f3c
cmpl $0x23, %r15d
je 0x6e85
cmpl $0x63, %r15d
je 0x6ef0
cmpl $0x6e, %r15d
je 0x6ee0
cmpl $0x6f, %r15d
je 0x6e55
cmpl $0x7c, %r15d
je 0x6e75
cmpl $0x7d, %r15d
je 0x6e65
cmpl $0x20, %r15d
jne 0x6e1f
movl $0x0, 0xc(%rsp)
cmpq $0x2, %rsi
jne 0x6fbd
movzbl 0x1(%rdi), %eax
cmpl $0x47, %eax
je 0x6f49
cmpl $0x46, %eax
jne 0x6fbd
movq (%r14), %rax
andb $-0x3, 0x18(%rax)
jmp 0x6f50
leaq 0x3971(%rip), %rcx      # 0xa71c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x1
popq %rsi
movq %r14, %rdi
movl %esi, 0xc(%rsp)
jmp 0x6e3e
movl $0x0, 0xc(%rsp)
cmpq $0x2, %rsi
jne 0x6fbd
movsbl 0x1(%rdi), %esi
pushq $0x1
popq %rdi
callq 0x2130
pushq $0x2
popq %rcx
movl %ecx, 0xc(%rsp)
testq %rax, %rax
je 0x6fbd
imulq $0x18, %r15, %rdx
movq %rax, -0x310(%rdx,%r14)
movq (%rax), %rcx
testq %rcx, %rcx
je 0x6fbd
leaq (%rdx,%r14), %rsi
addq $-0x310, %rsi           # imm = 0xFCF0
addq $0x8, %rsi
movq %rax, %rdi
callq *%rcx
jmp 0x6fbd
movl $0x0, 0xc(%rsp)
jmp 0x6fbd
orb $0x1, 0xac(%r14)
jmp 0x6fbd
movq %r14, %rdi
xorl %esi, %esi
callq 0x8fbd
jmp 0x6fbd
andb $-0x2, 0xac(%r14)
jmp 0x6fbd
movl $0x3, 0x128(%r14)
jmp 0x6fbd
movl $0x2, 0x12c(%r14)
jmp 0x6fbd
movl $0x3, 0x12c(%r14)
jmp 0x6fbd
movl $0x0, 0xc(%rsp)
cmpq $0x2, %rsi
jne 0x6fbd
movzbl 0x1(%rdi), %eax
addl $-0x33, %eax
cmpl $0x5, %eax
ja 0x6fbd
leaq 0x388e(%rip), %rcx      # 0xa73c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
testb $0x10, 0xad(%r14)
jne 0x6fbd
movl 0x38(%r14), %esi
pushq $0x1
popq %rcx
movq %r14, %rdi
xorl %edx, %edx
movl %ecx, %r8d
jmp 0x6fb8
movl $0x2, 0x128(%r14)
jmp 0x6fbd
movq 0x38(%r14), %r15
pushq $0x1
popq %rsi
movq %r14, %rdi
movl %esi, 0xc(%rsp)
callq 0x2100
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x6fbd
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x6fbd
movl 0xac(%r14), %edx
shrl $0x5, %edx
andl $0x1, %edx
movq 0x10(%r14), %rcx
movq 0x38(%r14), %rdi
movq %r15, %rsi
callq *%rax
jmp 0x6fbd
movl $0x1, 0x12c(%r14)
jmp 0x6fbd
movq (%r14), %rax
orb $0x2, 0x18(%rax)
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
jmp 0x6fbd
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
testb $0x10, 0xad(%r14)
jne 0x6fbd
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
jmp 0x6fb5
testb $0x10, 0xad(%r14)
jne 0x6f50
movl 0x38(%r14), %esi
pushq $0x1
popq %rcx
pushq $0x2
popq %r8
movq %r14, %rdi
xorl %edx, %edx
movl %r8d, 0xc(%rsp)
jmp 0x6fb8
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
testb $0x10, 0xad(%r14)
jne 0x6fbd
movl 0x38(%r14), %esi
pushq $0x1
popq %rcx
movq %r14, %rdi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x60ef
movl 0xc(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rax
movq $0x45, (%rax)
xorl %r13d, %r13d
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
pushq $0x1
popq %rbp
movabsq $0x100000000, %rbx      # imm = 0x100000000
movslq 0x30(%r14), %rax
cmpq %rax, %r13
jge 0x6fbd
movq %r13, %r12
xorl %r15d, %r15d
movq 0x70(%r14), %rsi
movl 0x34(%r14), %ecx
movl %ecx, %eax
cltd
pushq $0x2
popq %rdi
idivl %edi
testb $0x1, (%rsi,%r13,4)
cmovel %ecx, %eax
cltq
cmpq %rax, %r15
jge 0x703b
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movl %ebp, %edx
movq %r12, %rcx
callq 0x8bed
incq %r15
addq %rbx, %r12
jmp 0x7002
incq %r13
jmp 0x6ff3