// File: /workspace/github_c_makefile_star2_O0/neovim[P]libtermkey/termkey.c
// Function: parse_utf8
static TermKeyResult parse_utf8(const unsigned char *bytes, size_t len, long *cp, size_t *nbytep)
{
  unsigned int nbytes;

  unsigned char b0 = bytes[0];

  if(b0 < 0x80) {
    // Single byte ASCII
    *cp = b0;
    *nbytep = 1;
    return TERMKEY_RES_KEY;
  }
  else if(b0 < 0xc0) {
    // Starts with a continuation byte - that's not right
    *cp = UTF8_INVALID;
    *nbytep = 1;
    return TERMKEY_RES_KEY;
  }
  else if(b0 < 0xe0) {
    nbytes = 2;
    *cp = b0 & 0x1f;
  }
  else if(b0 < 0xf0) {
    nbytes = 3;
    *cp = b0 & 0x0f;
  }
  else if(b0 < 0xf8) {
    nbytes = 4;
    *cp = b0 & 0x07;
  }
  else if(b0 < 0xfc) {
    nbytes = 5;
    *cp = b0 & 0x03;
  }
  else if(b0 < 0xfe) {
    nbytes = 6;
    *cp = b0 & 0x01;
  }
  else {
    *cp = UTF8_INVALID;
    *nbytep = 1;
    return TERMKEY_RES_KEY;
  }

  for(unsigned int b = 1; b < nbytes; b++) {
    unsigned char cb;

    if(b >= len)
      return TERMKEY_RES_AGAIN;

    cb = bytes[b];
    if(cb < 0x80 || cb >= 0xc0) {
      *cp = UTF8_INVALID;
      *nbytep = b;
      return TERMKEY_RES_KEY;
    }

    *cp <<= 6;
    *cp |= cb & 0x3f;
  }

  // Check for overlong sequences
  if(nbytes > utf8_seqlen(*cp))
    *cp = UTF8_INVALID;

  // Check for UTF-16 surrogates or invalid *cps
  if((*cp >= 0xD800 && *cp <= 0xDFFF) ||
     *cp == 0xFFFE ||
     *cp == 0xFFFF)
    *cp = UTF8_INVALID;

  *nbytep = nbytes;
  return TERMKEY_RES_KEY;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movb (%rax), %al
movb %al, -0x2d(%rbp)
movzbl -0x2d(%rbp), %eax
cmpl $0x80, %eax
jge 0x59b0
movzbl -0x2d(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x5be0
movzbl -0x2d(%rbp), %eax
cmpl $0xc0, %eax
jge 0x59dd
movq -0x20(%rbp), %rax
movq $0xfffd, (%rax)         # imm = 0xFFFD
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x5be0
movzbl -0x2d(%rbp), %eax
cmpl $0xe0, %eax
jge 0x5a05
movl $0x2, -0x2c(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x1f, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5ac6
movzbl -0x2d(%rbp), %eax
cmpl $0xf0, %eax
jge 0x5a2d
movl $0x3, -0x2c(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0xf, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5ac4
movzbl -0x2d(%rbp), %eax
cmpl $0xf8, %eax
jge 0x5a52
movl $0x4, -0x2c(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x7, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5ac2
movzbl -0x2d(%rbp), %eax
cmpl $0xfc, %eax
jge 0x5a77
movl $0x5, -0x2c(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5ac0
movzbl -0x2d(%rbp), %eax
cmpl $0xfe, %eax
jge 0x5a9c
movl $0x6, -0x2c(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x1, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5abe
movq -0x20(%rbp), %rax
movq $0xfffd, (%rax)         # imm = 0xFFFD
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x5be0
jmp 0x5ac0
jmp 0x5ac2
jmp 0x5ac4
jmp 0x5ac6
jmp 0x5ac8
jmp 0x5aca
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x5b68
movl -0x34(%rbp), %eax
cmpq -0x18(%rbp), %rax
jb 0x5af2
movl $0x3, -0x4(%rbp)
jmp 0x5be0
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x35(%rbp)
movzbl -0x35(%rbp), %eax
cmpl $0x80, %eax
jl 0x5b15
movzbl -0x35(%rbp), %eax
cmpl $0xc0, %eax
jl 0x5b38
movq -0x20(%rbp), %rax
movq $0xfffd, (%rax)         # imm = 0xFFFD
movl -0x34(%rbp), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x5be0
movq -0x20(%rbp), %rax
movq (%rax), %rcx
shlq $0x6, %rcx
movq %rcx, (%rax)
movzbl -0x35(%rbp), %eax
andl $0x3f, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5ad1
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x64e0
movl %eax, %ecx
movl -0x3c(%rbp), %eax
cmpl %ecx, %eax
jbe 0x5b8e
movq -0x20(%rbp), %rax
movq $0xfffd, (%rax)         # imm = 0xFFFD
movq -0x20(%rbp), %rax
cmpq $0xd800, (%rax)         # imm = 0xD800
jl 0x5ba8
movq -0x20(%rbp), %rax
cmpq $0xdfff, (%rax)         # imm = 0xDFFF
jle 0x5bc2
movq -0x20(%rbp), %rax
cmpq $0xfffe, (%rax)         # imm = 0xFFFE
je 0x5bc2
movq -0x20(%rbp), %rax
cmpq $0xffff, (%rax)         # imm = 0xFFFF
jne 0x5bcd
movq -0x20(%rbp), %rax
movq $0xfffd, (%rax)         # imm = 0xFFFD
movl -0x2c(%rbp), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)