// File: /workspace/github_c_makefile_star2_O0/neovim[P]libtermkey/driver-csi.c
// Function: peekkey_csi
static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep)
{
  size_t csi_len;
  size_t args = 16;
  long arg[16];
  unsigned long cmd;

  TermKeyResult ret = parse_csi(tk, introlen, &csi_len, arg, &args, &cmd);

  if(ret == TERMKEY_RES_AGAIN) {
    if(!force)
      return TERMKEY_RES_AGAIN;

    (*tk->method.emit_codepoint)(tk, '[', key);
    key->modifiers |= TERMKEY_KEYMOD_ALT;
    *nbytep = introlen;
    return TERMKEY_RES_KEY;
  }

  if(cmd == 'M' && args < 3) { // Mouse in X10 encoding consumes the next 3 bytes also
    tk->buffstart += csi_len;
    tk->buffcount -= csi_len;

    TermKeyResult mouse_result = (*tk->method.peekkey_mouse)(tk, key, nbytep);

    tk->buffstart -= csi_len;
    tk->buffcount += csi_len;

    if(mouse_result == TERMKEY_RES_KEY)
      *nbytep += csi_len;

    return mouse_result;
  }

  TermKeyResult result = TERMKEY_RES_NONE;

  // We know from the logic above that cmd must be >= 0x40 and < 0x80
  if(csi_handlers[(cmd & 0xff) - 0x40])
    result = (*csi_handlers[(cmd & 0xff) - 0x40])(tk, key, cmd, arg, args);

  if(result == TERMKEY_RES_NONE) {
#ifdef DEBUG
    switch(args) {
      case 0:
        fprintf(stderr, "CSI: Unknown cmd=%c\n", (char)cmd);
        break;
      case 1:
        fprintf(stderr, "CSI: Unknown arg1=%ld cmd=%c\n", arg[0], (char)cmd);
        break;
      case 2:
        fprintf(stderr, "CSI: Unknown arg1=%ld arg2=%ld cmd=%c\n", arg[0], arg[1], (char)cmd);
        break;
      case 3:
        fprintf(stderr, "CSI: Unknown arg1=%ld arg2=%ld arg3=%ld cmd=%c\n", arg[0], arg[1], arg[2], (char)cmd);
        break;
      default:
        fprintf(stderr, "CSI: Unknown arg1=%ld arg2=%ld arg3=%ld ... args=%d cmd=%c\n", arg[0], arg[1], arg[2], args, (char)cmd);
        break;
    }
#endif
    key->type = TERMKEY_TYPE_UNKNOWN_CSI;
    key->code.number = cmd;
    key->modifiers = 0;

    tk->hightide = csi_len - introlen;
    *nbytep = introlen; // Do not yet eat the data bytes
    return TERMKEY_RES_KEY;
  }

  *nbytep = csi_len;
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq $0x10, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0xd0(%rbp), %rcx
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %r8
leaq -0xd8(%rbp), %r9
callq 0x69b0
movl %eax, -0xdc(%rbp)
cmpl $0x3, -0xdc(%rbp)
jne 0x831d
cmpl $0x0, -0x2c(%rbp)
jne 0x82df
movl $0x3, -0x4(%rbp)
jmp 0x8491
movq -0x10(%rbp), %rax
movq 0x2a8(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x5b, %esi
callq *%rax
movq -0x28(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x8491
cmpq $0x4d, -0xd8(%rbp)
jne 0x83c0
cmpq $0x3, -0x48(%rbp)
jae 0x83c0
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x2b8(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
movl %eax, -0xe0(%rbp)
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
cmpl $0x1, -0xe0(%rbp)
jne 0x83b2
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl -0xe0(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8491
movl $0x0, -0xe4(%rbp)
movq -0xd8(%rbp), %rcx
andq $0xff, %rcx
subq $0x40, %rcx
leaq 0x616d(%rip), %rax      # 0xe550
cmpq $0x0, (%rax,%rcx,8)
je 0x842b
movq -0xd8(%rbp), %rcx
andq $0xff, %rcx
subq $0x40, %rcx
leaq 0x614d(%rip), %rax      # 0xe550
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0xd8(%rbp), %rcx
movl %ecx, %edx
leaq -0xd0(%rbp), %rcx
movq -0x48(%rbp), %r8
callq *%rax
movl %eax, -0xe4(%rbp)
cmpl $0x0, -0xe4(%rbp)
jne 0x847d
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0xd8(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x40(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x8491
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl -0xe4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)