user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<fcitx_utf8_get_char_extended>:
  endbr64
  movzbl (%rdi),%eax
  mov    %eax,%edx
  test   %al,%al
  jns    L202
  cmp    $0xbf,%eax
  jbe    L18
  cmp    $0xdf,%eax
  ja     L217
  and    $0x1f,%edx
  mov    $0x2,%eax
  mov    $0x2,%r8d
L70:
  cmp    %eax,%esi
  jae    L95
  cmp    $0x1,%esi
  jle    L165
  lea    -0x2(%rsi),%eax
  lea    0x1(%rdi),%rdx
  lea    0x2(%rdi,%rax,1),%rcx
  jmp    L114
  nopl   0x0(%rax)
L139:
  add    $0x1,%rdx
  cmp    %rcx,%rdx
  je     L165
L114:
  movzbl (%rdx),%eax
  and    $0xffffffc0,%eax
  cmp    $0x80,%al
  je     L139
L18:
  mov    $0xffffffff,%eax
L202:
  ret
  nopl   (%rax)
L217:
  cmp    $0xef,%eax
  jbe    L51
  cmp    $0xf7,%eax
  ja     L99
  and    $0x7,%edx
  mov    $0x4,%eax
  mov    $0x4,%r8d
  jmp    L70
  xchg   %ax,%ax
L95:
  lea    -0x2(%r8),%eax
  lea    0x1(%rdi),%rcx
  lea    0x2(%rdi,%rax,1),%rdi
  nopl   (%rax)
L17:
  movzbl (%rcx),%eax
  mov    %eax,%esi
  and    $0xffffffc0,%esi
  cmp    $0x80,%sil
  jne    L203
  shl    $0x6,%edx
  and    $0x3f,%eax
  add    $0x1,%rcx
  or     %eax,%edx
  cmp    %rcx,%rdi
  jne    L17
  mov    $0xffffffff,%eax
  cmp    $0x7f,%edx
  jbe    L202
  mov    $0x2,%eax
  cmp    $0x7ff,%edx
  jbe    L180
  mov    $0x3,%eax
  cmp    $0xffff,%edx
  jbe    L180
  mov    $0x4,%eax
  cmp    $0x1fffff,%edx
  jbe    L180
  xor    %eax,%eax
  cmp    $0x3ffffff,%edx
  seta   %al
  add    $0x5,%eax
L180:
  cmp    %eax,%r8d
  mov    $0xffffffff,%eax
  cmove  %edx,%eax
  ret
  xchg   %ax,%ax
L51:
  and    $0xf,%edx
  mov    $0x3,%eax
  mov    $0x3,%r8d
  jmp    L70
  nopl   0x0(%rax,%rax,1)
L165:
  mov    $0xfffffffe,%eax
  ret
  xchg   %ax,%ax
L203:
  cmp    $0x1,%al
  mov    $0xfffffffe,%eax
  sbb    $0xffffffff,%eax
  ret
  nopl   0x0(%rax,%rax,1)
L99:
  cmp    $0xfb,%eax
  jbe    L108
  cmp    $0xfd,%eax
  ja     L18
  and    $0x1,%edx
  mov    $0x6,%eax
  mov    $0x6,%r8d
  jmp    L70
  nopl   (%rax)
L108:
  and    $0x3,%edx
  mov    $0x5,%eax
  mov    $0x5,%r8d
  jmp    L70
```

assistant: ```c
__attribute__((visibility("default"))) int fcitx_utf8_get_char_extended(const char *s, int max_len) {
  const unsigned char *p = (const unsigned char *)s;
  int i, len;
  unsigned int wc = (unsigned char)*p;
  if (wc < 0x80) {
    return wc;
  } else if (wc < 0xc0) {
    return (unsigned int)-1;
  } else if (wc < 0xe0) {
    len = 2;
    wc &= 0x1f;
  } else if (wc < 0xf0) {
    len = 3;
    wc &= 0x0f;
  } else if (wc < 0xf8) {
    len = 4;
    wc &= 0x07;
  } else if (wc < 0xfc) {
    len = 5;
    wc &= 0x03;
  } else if (wc < 0xfe) {
    len = 6;
    wc &= 0x01;
  } else {
    return (unsigned int)-1;
  }
  if (max_len >= 0 && len > max_len) {
    for (i = 1; i < max_len; i++) {
      if ((((unsigned char *)p)[i] & 0xc0) != 0x80)
        return (unsigned int)-1;
    }
    return (unsigned int)-2;
  }
  for (i = 1; i < len; ++i) {
    unsigned int ch = ((unsigned char *)p)[i];
    if ((ch & 0xc0) != 0x80) {
      if (ch)
        return (unsigned int)-1;
      else
        return (unsigned int)-2;
    }
    wc <<= 6;
    wc |= (ch & 0x3f);
  }
  if (((wc) < 0x80 ? 1 : ((wc) < 0x800 ? 2 : ((wc) < 0x10000 ? 3 : ((wc) < 0x200000 ? 4 : ((wc) < 0x4000000 ? 5 : 6))))) != len)
    return (unsigned int)-1;
  return wc;
}
```