// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdx, %r14
movzbl (%rdi), %r15d
movl $0x1, %ebx
cmpl $0x62, %r15d
jg 0x77c9
cmpl $0x36, %r15d
jg 0x77fd
leal -0x28(%r15), %eax
cmpl $0x4, %eax
jae 0x7856
xorl %ebx, %ebx
cmpq $0x2, %rsi
jne 0x7a8b
movsbl 0x1(%rdi), %esi
movl $0x1, %edi
callq 0x2140
movl $0x2, %ebx
testq %rax, %rax
je 0x7a8b
movsbq %r15b, %rcx
leaq (%rcx,%rcx,2), %rdx
movq %rax, -0x310(%r14,%rdx,8)
movq (%rax), %rcx
testq %rcx, %rcx
je 0x7a8b
leaq (%r14,%rdx,8), %rsi
addq $-0x310, %rsi           # imm = 0xFCF0
addq $0x8, %rsi
movq %rax, %rdi
callq *%rcx
jmp 0x7a8b
cmpl $0x7b, %r15d
jg 0x7828
cmpl $0x63, %r15d
je 0x78eb
cmpl $0x6e, %r15d
je 0x7945
cmpl $0x6f, %r15d
jne 0x798f
movl $0x3, 0x128(%r14)
jmp 0x7a8b
addl $-0x37, %r15d
cmpl $0x7, %r15d
ja 0x798f
leaq 0x3f1a(%rip), %rax      # 0xb72c
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
movl $0x1, %esi
jmp 0x78d4
cmpl $0x7c, %r15d
je 0x7935
cmpl $0x7d, %r15d
je 0x7955
cmpl $0x7e, %r15d
jne 0x798f
movl $0x1, 0x12c(%r14)
jmp 0x7a8b
cmpl $0x20, %r15d
je 0x7965
cmpl $0x23, %r15d
jne 0x798f
xorl %ebx, %ebx
cmpq $0x2, %rsi
jne 0x7a8b
movzbl 0x1(%rdi), %eax
addl $-0x33, %eax
cmpl $0x5, %eax
ja 0x7a8b
leaq 0x3ebf(%rip), %rcx      # 0xb74c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x7a8b
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x1, %r8d
jmp 0x7a0f
orb $0x1, 0xac(%r14)
jmp 0x7a8b
movq %r14, %rdi
xorl %esi, %esi
callq 0x9ba2
jmp 0x7a8b
andb $-0x2, 0xac(%r14)
jmp 0x7a8b
movq 0x38(%r14), %r15
movq %r14, %rdi
movl $0x1, %esi
callq 0x2110
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x7a8b
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x7a8b
movl 0xac(%r14), %edx
shrl $0x5, %edx
andl $0x1, %edx
movq 0x10(%r14), %rcx
movq 0x38(%r14), %rdi
movq %r15, %rsi
callq *%rax
jmp 0x7a8b
movl $0x3, 0x12c(%r14)
jmp 0x7a8b
movl $0x2, 0x128(%r14)
jmp 0x7a8b
movl $0x2, 0x12c(%r14)
jmp 0x7a8b
xorl %ebx, %ebx
cmpq $0x2, %rsi
jne 0x7a8b
movzbl 0x1(%rdi), %eax
cmpl $0x47, %eax
je 0x7996
cmpl $0x46, %eax
jne 0x7a8b
movq (%r14), %rax
andb $-0x3, 0x18(%rax)
jmp 0x7a86
xorl %ebx, %ebx
jmp 0x7a8b
movq (%r14), %rax
orb $0x2, 0x18(%rax)
jmp 0x7a86
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x7a8b
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
jmp 0x7a0c
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x7a8b
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x2, %r8d
jmp 0x7a0f
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x7a8b
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x6a61
jmp 0x7a8b
movq $0x45, (%rsp)
cmpl $0x0, 0x30(%r14)
jle 0x7a86
xorl %r12d, %r12d
movq %rsp, %rbx
movabsq $0x100000000, %r13      # imm = 0x100000000
movq %r12, %r15
xorl %ebp, %ebp
movq 0x70(%r14), %rax
testb $0x1, (%rax,%r12,4)
jne 0x7a4b
movl 0x34(%r14), %eax
jmp 0x7a58
movl 0x34(%r14), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cltq
cmpq %rax, %rbp
jge 0x7a7a
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movq %r15, %rcx
callq 0x97b0
incq %rbp
addq %r13, %r15
jmp 0x7a3a
incq %r12
movslq 0x30(%r14), %rax
cmpq %rax, %r12
jl 0x7a35
movl $0x2, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq