// File: /workspace/github_c_makefile_star2_O2/neovim[P]libtermkey/termkey.c
// Function: peekkey_simple
static TermKeyResult peekkey_simple(TermKey *tk, TermKeyKey *key, int force, size_t *nbytep)
{
  if(tk->buffcount == 0)
    return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE;

  unsigned char b0 = CHARAT(0);

  if(b0 == 0x1b) {
    // Escape-prefixed value? Might therefore be Alt+key
    if(tk->buffcount == 1) {
      // This might be an <Esc> press, or it may want to be part of a longer
      // sequence
      if(!force)
        return TERMKEY_RES_AGAIN;

      (*tk->method.emit_codepoint)(tk, b0, key);
      *nbytep = 1;
      return TERMKEY_RES_KEY;
    }

    // Try another key there
    tk->buffstart++;
    tk->buffcount--;

    // Run the full driver
    TermKeyResult metakey_result = peekkey(tk, key, force, nbytep);

    tk->buffstart--;
    tk->buffcount++;

    switch(metakey_result) {
      case TERMKEY_RES_KEY:
        key->modifiers |= TERMKEY_KEYMOD_ALT;
        (*nbytep)++;
        break;

      case TERMKEY_RES_NONE:
      case TERMKEY_RES_EOF:
      case TERMKEY_RES_AGAIN:
      case TERMKEY_RES_ERROR:
        break;
    }

    return metakey_result;
  }
  else if(b0 < 0xa0) {
    // Single byte C0, G0 or C1 - C1 is never UTF-8 initial byte
    (*tk->method.emit_codepoint)(tk, b0, key);
    *nbytep = 1;
    return TERMKEY_RES_KEY;
  }
  else if(tk->flags & TERMKEY_FLAG_UTF8) {
    // Some UTF-8
    long codepoint;
    TermKeyResult res = parse_utf8(tk->buffer + tk->buffstart, tk->buffcount, &codepoint, nbytep);

    if(res == TERMKEY_RES_AGAIN && force) {
      /* There weren't enough bytes for a complete UTF-8 sequence but caller
       * demands an answer. About the best thing we can do here is eat as many
       * bytes as we have, and emit a UTF8_INVALID. If the remaining bytes
       * arrive later, they'll be invalid too.
       */
      codepoint = UTF8_INVALID;
      *nbytep = tk->buffcount;
      res = TERMKEY_RES_KEY;
    }

    key->type = TERMKEY_TYPE_UNICODE;
    key->modifiers = 0;
    (*tk->method.emit_codepoint)(tk, codepoint, key);
    return res;
  }
  else {
    // Non UTF-8 case - just report the raw byte
    key->type = TERMKEY_TYPE_UNICODE;
    key->code.codepoint = b0;
    key->modifiers = 0;

    key->utf8[0] = key->code.codepoint;
    key->utf8[1] = 0;

    *nbytep = 1;

    return TERMKEY_RES_KEY;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x20(%rdi), %rsi
testq %rsi, %rsi
je 0x4da4
movq %rcx, %r15
movl %edx, %r12d
movq 0x10(%r14), %rdi
movq 0x18(%r14), %rcx
movzbl (%rdi,%rcx), %eax
cmpq $0x1b, %rax
jne 0x4db6
cmpq $0x1, %rsi
jne 0x4dcc
testl %r12d, %r12d
je 0x4e6e
pushq $0x1b
popq %rsi
movq %r14, %rdi
jmp 0x4dc0
xorl %ebp, %ebp
cmpb $0x0, 0x8c(%r14)
setne %bpl
addl %ebp, %ebp
jmp 0x4e32
cmpb $-0x61, %al
ja 0x4e0f
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq *0x2a8(%r14)
jmp 0x4e28
incq %rcx
movq %rcx, 0x18(%r14)
decq %rsi
movq %rsi, 0x20(%r14)
movq %r14, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movq %r15, %rcx
callq 0x3b7a
movl %eax, %ebp
movdqu 0x18(%r14), %xmm0
paddq 0x2295(%rip), %xmm0     # 0x7090
movdqu %xmm0, 0x18(%r14)
cmpl $0x1, %eax
jne 0x4e32
orb $0x2, 0x10(%rbx)
incq (%r15)
jmp 0x4e2f
testb $0x8, 0x4(%r14)
jne 0x4e41
andl $0x0, (%rbx)
movq %rax, 0x8(%rbx)
andl $0x0, 0x10(%rbx)
movb %al, 0x14(%rbx)
movb $0x0, 0x15(%rbx)
movq $0x1, (%r15)
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
addq %rcx, %rdi
leaq 0x8(%rsp), %rdx
movq %r15, %rcx
callq 0x49ca
movl %eax, %ebp
testl %r12d, %r12d
je 0x4e72
cmpl $0x3, %ebp
jne 0x4e72
movq 0x20(%r14), %rax
movq %rax, (%r15)
pushq $0x1
popq %rbp
movl $0xfffd, %esi           # imm = 0xFFFD
jmp 0x4e77
pushq $0x3
jmp 0x4e31
movq 0x8(%rsp), %rsi
andl $0x0, (%rbx)
andl $0x0, 0x10(%rbx)
movq %r14, %rdi
movq %rbx, %rdx
callq *0x2a8(%r14)
jmp 0x4e32