// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x60b2
movq -0x10(%rbp), %rax
movsbl 0x8c(%rax), %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x62ea
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movb (%rax,%rcx), %al
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0x1b, %eax
jne 0x61c4
movq -0x10(%rbp), %rax
cmpq $0x1, 0x20(%rax)
jne 0x6124
cmpl $0x0, -0x1c(%rbp)
jne 0x60f2
movl $0x3, -0x4(%rbp)
jmp 0x62ea
movq -0x10(%rbp), %rax
movq 0x2a8(%rax), %rax
movq -0x10(%rbp), %rdi
movzbl -0x29(%rbp), %ecx
movl %ecx, %esi
movq -0x18(%rbp), %rdx
callq *%rax
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x62ea
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
incq %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
decq %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x4230
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
decq %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
incq %rcx
movq %rcx, 0x20(%rax)
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
testl %eax, %eax
je 0x61b7
jmp 0x6183
movl -0x40(%rbp), %eax
subl $0x1, %eax
je 0x619a
jmp 0x618d
movl -0x40(%rbp), %eax
addl $-0x2, %eax
subl $0x3, %eax
jb 0x61b7
jmp 0x61b9
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x61b9
jmp 0x61b9
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62ea
movzbl -0x29(%rbp), %eax
cmpl $0xa0, %eax
jge 0x6201
movq -0x10(%rbp), %rax
movq 0x2a8(%rax), %rax
movq -0x10(%rbp), %rdi
movzbl -0x29(%rbp), %ecx
movl %ecx, %esi
movq -0x18(%rbp), %rdx
callq *%rax
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x62ea
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x629c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rcx
leaq -0x38(%rbp), %rdx
callq 0x5960
movl %eax, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jne 0x6266
cmpl $0x0, -0x1c(%rbp)
je 0x6266
movq $0xfffd, -0x38(%rbp)    # imm = 0xFFFD
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x2a8(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq *%rax
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62ea
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x14(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x15(%rax)
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)