// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/encoding.c
// Function: decode_utf8
static void decode_utf8(VTermEncoding *enc, void *data_,
                        uint32_t cp[], int *cpi, int cplen,
                        const char bytes[], size_t *pos, size_t bytelen)
{
  struct UTF8DecoderData *data = data_;

#ifdef DEBUG_PRINT_UTF8
  printf("BEGIN UTF-8\n");
#endif

  for(; *pos < bytelen && *cpi < cplen; (*pos)++) {
    unsigned char c = bytes[*pos];

#ifdef DEBUG_PRINT_UTF8
    printf(" pos=%zd c=%02x rem=%d\n", *pos, c, data->bytes_remaining);
#endif

    if(c < 0x20) // C0
      return;

    else if(c >= 0x20 && c < 0x7f) {
      if(data->bytes_remaining)
        cp[(*cpi)++] = UNICODE_INVALID;

      cp[(*cpi)++] = c;
#ifdef DEBUG_PRINT_UTF8
      printf(" UTF-8 char: U+%04x\n", c);
#endif
      data->bytes_remaining = 0;
    }

    else if(c == 0x7f) // DEL
      return;

    else if(c >= 0x80 && c < 0xc0) {
      if(!data->bytes_remaining) {
        cp[(*cpi)++] = UNICODE_INVALID;
        continue;
      }

      data->this_cp <<= 6;
      data->this_cp |= c & 0x3f;
      data->bytes_remaining--;

      if(!data->bytes_remaining) {
#ifdef DEBUG_PRINT_UTF8
        printf(" UTF-8 raw char U+%04x bytelen=%d ", data->this_cp, data->bytes_total);
#endif
        // Check for overlong sequences
        switch(data->bytes_total) {
        case 2:
          if(data->this_cp <  0x0080) data->this_cp = UNICODE_INVALID;
          break;
        case 3:
          if(data->this_cp <  0x0800) data->this_cp = UNICODE_INVALID;
          break;
        case 4:
          if(data->this_cp < 0x10000) data->this_cp = UNICODE_INVALID;
          break;
        case 5:
          if(data->this_cp < 0x200000) data->this_cp = UNICODE_INVALID;
          break;
        case 6:
          if(data->this_cp < 0x4000000) data->this_cp = UNICODE_INVALID;
          break;
        }
        // Now look for plain invalid ones
        if((data->this_cp >= 0xD800 && data->this_cp <= 0xDFFF) ||
           data->this_cp == 0xFFFE ||
           data->this_cp == 0xFFFF)
          data->this_cp = UNICODE_INVALID;
#ifdef DEBUG_PRINT_UTF8
        printf(" char: U+%04x\n", data->this_cp);
#endif
        cp[(*cpi)++] = data->this_cp;
      }
    }

    else if(c >= 0xc0 && c < 0xe0) {
      if(data->bytes_remaining)
        cp[(*cpi)++] = UNICODE_INVALID;

      data->this_cp = c & 0x1f;
      data->bytes_total = 2;
      data->bytes_remaining = 1;
    }

    else if(c >= 0xe0 && c < 0xf0) {
      if(data->bytes_remaining)
        cp[(*cpi)++] = UNICODE_INVALID;

      data->this_cp = c & 0x0f;
      data->bytes_total = 3;
      data->bytes_remaining = 2;
    }

    else if(c >= 0xf0 && c < 0xf8) {
      if(data->bytes_remaining)
        cp[(*cpi)++] = UNICODE_INVALID;

      data->this_cp = c & 0x07;
      data->bytes_total = 4;
      data->bytes_remaining = 3;
    }

    else if(c >= 0xf8 && c < 0xfc) {
      if(data->bytes_remaining)
        cp[(*cpi)++] = UNICODE_INVALID;

      data->this_cp = c & 0x03;
      data->bytes_total = 5;
      data->bytes_remaining = 4;
    }

    else if(c >= 0xfc && c < 0xfe) {
      if(data->bytes_remaining)
        cp[(*cpi)++] = UNICODE_INVALID;

      data->this_cp = c & 0x01;
      data->bytes_total = 6;
      data->bytes_remaining = 5;
    }

    else {
      cp[(*cpi)++] = UNICODE_INVALID;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rcx
xorl %eax, %eax
cmpq 0x18(%rbp), %rcx
movb %al, -0x3a(%rbp)
jae 0x240d
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x24(%rbp), %eax
setl %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x2419
jmp 0x2858
movq -0x30(%rbp), %rax
movq 0x10(%rbp), %rcx
movq (%rcx), %rcx
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x20, %eax
jge 0x2438
jmp 0x2858
movzbl -0x39(%rbp), %eax
cmpl $0x20, %eax
jl 0x2498
movzbl -0x39(%rbp), %eax
cmpl $0x7f, %eax
jge 0x2498
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x246e
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
movzbl -0x39(%rbp), %edx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
jmp 0x2841
movzbl -0x39(%rbp), %eax
cmpl $0x7f, %eax
jne 0x24a6
jmp 0x2858
movzbl -0x39(%rbp), %eax
cmpl $0x80, %eax
jl 0x2634
movzbl -0x39(%rbp), %eax
cmpl $0xc0, %eax
jge 0x2634
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x24ed
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
jmp 0x2845
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
shll $0x6, %ecx
movl %ecx, 0x8(%rax)
movzbl -0x39(%rbp), %ecx
andl $0x3f, %ecx
movq -0x38(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x262f
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x4, %eax
ja 0x25d2
movq -0x48(%rbp), %rax
leaq 0x10ab9(%rip), %rcx     # 0x13000
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rax
cmpl $0x80, 0x8(%rax)
jge 0x2568
movq -0x38(%rbp), %rax
movl $0xfffd, 0x8(%rax)      # imm = 0xFFFD
jmp 0x25d2
movq -0x38(%rbp), %rax
cmpl $0x800, 0x8(%rax)       # imm = 0x800
jge 0x2582
movq -0x38(%rbp), %rax
movl $0xfffd, 0x8(%rax)      # imm = 0xFFFD
jmp 0x25d2
movq -0x38(%rbp), %rax
cmpl $0x10000, 0x8(%rax)     # imm = 0x10000
jge 0x259c
movq -0x38(%rbp), %rax
movl $0xfffd, 0x8(%rax)      # imm = 0xFFFD
jmp 0x25d2
movq -0x38(%rbp), %rax
cmpl $0x200000, 0x8(%rax)    # imm = 0x200000
jge 0x25b6
movq -0x38(%rbp), %rax
movl $0xfffd, 0x8(%rax)      # imm = 0xFFFD
jmp 0x25d2
movq -0x38(%rbp), %rax
cmpl $0x4000000, 0x8(%rax)   # imm = 0x4000000
jge 0x25d0
movq -0x38(%rbp), %rax
movl $0xfffd, 0x8(%rax)      # imm = 0xFFFD
jmp 0x25d2
movq -0x38(%rbp), %rax
cmpl $0xd800, 0x8(%rax)      # imm = 0xD800
jl 0x25ec
movq -0x38(%rbp), %rax
cmpl $0xdfff, 0x8(%rax)      # imm = 0xDFFF
jle 0x2606
movq -0x38(%rbp), %rax
cmpl $0xfffe, 0x8(%rax)      # imm = 0xFFFE
je 0x2606
movq -0x38(%rbp), %rax
cmpl $0xffff, 0x8(%rax)      # imm = 0xFFFF
jne 0x2611
movq -0x38(%rbp), %rax
movl $0xfffd, 0x8(%rax)      # imm = 0xFFFD
movq -0x38(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x283d
movzbl -0x39(%rbp), %eax
cmpl $0xc0, %eax
jl 0x2696
movzbl -0x39(%rbp), %eax
cmpl $0xe0, %eax
jge 0x2696
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x266e
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
movzbl -0x39(%rbp), %ecx
andl $0x1f, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x2, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
jmp 0x283b
movzbl -0x39(%rbp), %eax
cmpl $0xe0, %eax
jl 0x26f8
movzbl -0x39(%rbp), %eax
cmpl $0xf0, %eax
jge 0x26f8
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x26d0
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
movzbl -0x39(%rbp), %ecx
andl $0xf, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x3, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x2, (%rax)
jmp 0x2839
movzbl -0x39(%rbp), %eax
cmpl $0xf0, %eax
jl 0x275a
movzbl -0x39(%rbp), %eax
cmpl $0xf8, %eax
jge 0x275a
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2732
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
movzbl -0x39(%rbp), %ecx
andl $0x7, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x4, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x3, (%rax)
jmp 0x2837
movzbl -0x39(%rbp), %eax
cmpl $0xf8, %eax
jl 0x27b9
movzbl -0x39(%rbp), %eax
cmpl $0xfc, %eax
jge 0x27b9
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2794
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
movzbl -0x39(%rbp), %ecx
andl $0x3, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x5, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x4, (%rax)
jmp 0x2835
movzbl -0x39(%rbp), %eax
cmpl $0xfc, %eax
jl 0x2818
movzbl -0x39(%rbp), %eax
cmpl $0xfe, %eax
jge 0x2818
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x27f3
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
movzbl -0x39(%rbp), %ecx
andl $0x1, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x6, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x5, (%rax)
jmp 0x2833
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movl $0xfffd, (%rax,%rcx,4)  # imm = 0xFFFD
jmp 0x2835
jmp 0x2837
jmp 0x2839
jmp 0x283b
jmp 0x283d
jmp 0x283f
jmp 0x2841
jmp 0x2843
jmp 0x2845
movq 0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x23ec
popq %rbp
retq
nopw (%rax,%rax)