// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq 0x20(%rdi), %rsi
testq %rsi, %rsi
je 0x5027
movq %rcx, %r14
movl %edx, %r12d
movq 0x10(%r15), %rdi
movq 0x18(%r15), %rcx
movzbl (%rdi,%rcx), %eax
cmpq $0x1b, %rax
jne 0x5039
cmpq $0x1, %rsi
jne 0x504f
testl %r12d, %r12d
jne 0x503d
movl $0x3, %ebp
jmp 0x50ab
xorl %ebp, %ebp
cmpb $0x0, 0x8c(%r15)
setne %bpl
addl %ebp, %ebp
jmp 0x50ab
cmpb $-0x61, %al
ja 0x5086
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq *0x2a8(%r15)
jmp 0x509f
incq %rcx
movq %rcx, 0x18(%r15)
decq %rsi
movq %rsi, 0x20(%r15)
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movq %r14, %rcx
callq 0x3c37
movl %eax, %ebp
decq 0x18(%r15)
incq 0x20(%r15)
cmpl $0x1, %eax
jne 0x50ab
orb $0x2, 0x10(%rbx)
incq (%r14)
jmp 0x50ab
testb $0x8, 0x4(%r15)
jne 0x50ba
xorl %ecx, %ecx
movl %ecx, (%rbx)
movq %rax, 0x8(%rbx)
movl %ecx, 0x10(%rbx)
movb %al, 0x14(%rbx)
movb $0x0, 0x15(%rbx)
movq $0x1, (%r14)
movl $0x1, %ebp
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 %r14, %rcx
callq 0x4bd3
movl %eax, %ebp
testl %r12d, %r12d
je 0x50eb
cmpl $0x3, %ebp
jne 0x50eb
movq $0xfffd, 0x8(%rsp)      # imm = 0xFFFD
movq 0x20(%r15), %rax
movq %rax, (%r14)
movl $0x1, %ebp
xorl %eax, %eax
movl %eax, (%rbx)
movl %eax, 0x10(%rbx)
movq 0x8(%rsp), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq *0x2a8(%r15)
jmp 0x50ab