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

```asm
<makeutf8>:
  endbr64
  add    %edx,%edx
  test   %edx,%edx
  jle    L65
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rax
  sub    $0x1,%edx
  shr    %edx
  mov    %edx,%edx
  lea    0x2(%rsi,%rdx,2),%r9
  mov    $0x0,%edx
  mov    $0x0,%ebx
  mov    $0x0,%ecx
  mov    $0x2,%r11d
  mov    $0x1,%r12d
  mov    $0x0,%ebp
  jmp    L95
L41:
  mov    %rax,%r10
  movzbl 0x1(%rax),%esi
  movsbl %sil,%r8d
  mov    %esi,%r13d
  and    $0xf8,%r13d
  je     L60
  cmp    $0xd8,%r13d
  je     L111
  mov    %ecx,%r8d
  shr    $0x4,%sil
  sub    $0x20,%esi
  mov    %sil,(%rdi,%r8,1)
  lea    0x2(%rcx),%r8d
  lea    0x1(%rcx),%r13d
  movsbl 0x1(%rax),%esi
  shl    $0x2,%esi
  and    $0x3c,%esi
  movzbl (%rax),%r14d
  shr    $0x6,%r14b
  lea    -0x80(%rsi,%r14,1),%esi
  mov    %sil,(%rdi,%r13,1)
  add    $0x3,%ecx
  mov    %r8d,%r8d
  movzbl (%rax),%esi
  and    $0x3f,%esi
  add    $0xffffff80,%esi
  mov    %sil,(%rdi,%r8,1)
  jmp    L44
L111:
  mov    %r11d,%edx
  test   $0x4,%sil
  jne    L44
  lea    0x1(%rcx),%edx
  mov    %ecx,%ebx
  movsbl (%rax),%r8d
  and    $0xc0,%r8d
  cmp    $0xc0,%r8d
  sete   %r8b
  and    $0x7,%esi
  lea    -0x10(%r8,%rsi,1),%esi
  mov    %sil,(%rdi,%rbx,1)
  add    $0x2,%ecx
  mov    %edx,%esi
  movsbl (%rax),%edx
  add    $0x40,%edx
  shr    $0x2,%dl
  add    $0xffffff80,%edx
  mov    %dl,(%rdi,%rsi,1)
  movzbl (%rax),%ebx
  and    $0x3,%ebx
  mov    %r12d,%edx
  jmp    L44
L60:
  movzbl (%rax),%r13d
  test   %sil,%sil
  jne    L91
  test   %r13b,%r13b
  jns    L56
L91:
  lea    0x1(%rcx),%esi
  mov    %ecx,%r14d
  shl    $0x2,%r8d
  and    $0x3c,%r8d
  shr    $0x6,%r13b
  lea    -0x40(%r8,%r13,1),%r8d
  mov    %r8b,(%rdi,%r14,1)
  add    $0x2,%ecx
  mov    %esi,%esi
  movzbl (%r10),%r8d
  and    $0x3f,%r8d
  add    $0xffffff80,%r8d
  mov    %r8b,(%rdi,%rsi,1)
L44:
  add    $0x2,%rax
  cmp    %r9,%rax
  je     L104
L95:
  test   %edx,%edx
  je     L41
  cmp    $0x1,%edx
  jne    L44
  movzbl 0x1(%rax),%r13d
  mov    %r13d,%esi
  and    $0xfc,%esi
  mov    %r11d,%edx
  cmp    $0xdc,%esi
  jne    L44
  lea    0x1(%rcx),%r8d
  mov    %ecx,%r10d
  movzbl (%rax),%esi
  shr    $0x6,%sil
  mov    %ebx,%edx
  shl    $0x4,%edx
  lea    -0x80(%rsi,%rdx,1),%esi
  lea    0x0(,%r13,4),%edx
  and    $0xc,%edx
  add    %esi,%edx
  mov    %dl,(%rdi,%r10,1)
  add    $0x2,%ecx
  mov    %r8d,%esi
  movzbl (%rax),%edx
  and    $0x3f,%edx
  add    $0xffffff80,%edx
  mov    %dl,(%rdi,%rsi,1)
  mov    %ebp,%edx
  jmp    L44
L56:
  mov    %ecx,%esi
  mov    %r13b,(%rdi,%rsi,1)
  lea    0x1(%rcx),%ecx
  jmp    L44
L104:
  mov    %ecx,%eax
  movb   $0x0,(%rdi,%rax,1)
  test   %edx,%edx
  mov    $0x0,%eax
  cmovne %eax,%ecx
  mov    %ecx,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L65:
  movb   $0x0,(%rdi)
  mov    $0x0,%ecx
  mov    %ecx,%eax
  ret
```

assistant: ```c
unsigned int makeutf8(char *utf8, const char *utf16, int length) {
  int i;
  unsigned int size;
  unsigned int rem;
  enum { BASE, SURR, ERR } state;
  size = 0;
  rem = 0;
  state = BASE;
  for (i = 0; i < 2 * length; i += 2) {
    switch (state) {
    case BASE:
      if (utf16[i + 1] & 0xf8) {
        if ((utf16[i + 1] & 0xf8) == 0xd8) {
          if (utf16[i + 1] & 4)
            state = ERR;
          else {
            utf8[size++] = 0xf0 + (utf16[i + 1] & 7) + ((utf16[i] & 0xc0) == 0xc0);
            utf8[size++] = 0x80 + (((utf16[i] + 64) >> 2) & 63);
            rem = utf16[i] & 3;
            state = SURR;
          }
        } else {
          utf8[size++] = 0xe0 + ((utf16[i + 1] >> 4) & 15);
          utf8[size++] = 0x80 + ((utf16[i + 1] & 15) << 2) + ((utf16[i] >> 6) & 3);
          utf8[size++] = 0x80 + (utf16[i] & 63);
        }
      } else if ((utf16[i] & 0x80) || utf16[i + 1]) {
        utf8[size++] = 0xc0 + ((utf16[i + 1] & 15) << 2) + ((utf16[i] >> 6) & 3);
        utf8[size++] = 0x80 + (utf16[i] & 63);
      } else
        utf8[size++] = utf16[i];
      break;
    case SURR:
      if ((utf16[i + 1] & 0xfc) == 0xdc) {
        utf8[size++] = 0x80 + (rem << 4) + ((utf16[i + 1] & 3) << 2) + ((utf16[i] >> 6) & 3);
        utf8[size++] = 0x80 + (utf16[i] & 63);
        state = BASE;
      } else
        state = ERR;
      break;
    case ERR:
      break;
    }
  }
  utf8[size] = 0;
  if (state != BASE)
    state = ERR;
  return (state == ERR ? 0 : size);
}
```