user: 请将以下的汇编代码转换成C语言代码：

```asm
<utf8_to_latin1>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    (%rsi),%esi
  cmp    $0x2,%esi
  jle    L144
  mov    %rdi,%rbx
  sub    $0x3,%esi
  je     L69
  xor    %r13d,%r13d
  xor    %r12d,%r12d
  xor    %edx,%edx
  jmp    L53
  nopw   0x0(%rax,%rax,1)
L116:
  add    $0x1,%edx
  cmp    %esi,%edx
  jge    L48
L53:
  movslq %edx,%rcx
  cmpb   $0x0,(%rbx,%rcx,1)
  jns    L116
  cmpb   $0x0,0x1(%rbx,%rcx,1)
  lea    0x1(%rcx),%rax
  js     L14
  add    $0x1,%r12d
  nopl   0x0(%rax,%rax,1)
L54:
  movzbl (%rbx,%rax,1),%ecx
  mov    %eax,%edx
  add    $0x1,%rax
  test   %cl,%cl
  js     L54
  add    $0x1,%edx
  cmp    %esi,%edx
  jl     L53
  nopl   (%rax)
L48:
  xor    %eax,%eax
  mov    %r13d,%edx
  lea    D5(%rip),%rdi
  mov    %r12d,%esi
  call   <printf@plt>
  cmp    %r13d,%r12d
  jg     L144
L127:
  lea    D9(%rip),%rdi
  call   <puts@plt>
  mov    0x0(%rbp),%edi
  call   <malloc@plt>
  movslq 0x0(%rbp),%rcx
  mov    %rax,%r12
  mov    %rcx,%r8
  add    %rbx,%rcx
  cmp    %rcx,%rbx
  jae    L199
  mov    %rbx,%rdx
  mov    %rax,%rsi
  mov    $0x3f,%r9d
  jmp    L154
  nopl   (%rax)
L100:
  cmp    $0xe0,%al
  ja     L77
  cmp    %rdi,%rcx
  jbe    L84
  movzbl 0x1(%rdx),%ecx
  shl    $0x6,%eax
  and    $0x7c0,%eax
  and    $0x3f,%ecx
  or     %ecx,%eax
  cmp    $0x100,%eax
  cmovge %r9d,%eax
  add    $0x2,%rdx
L152:
  mov    %al,-0x1(%rsi)
  movslq 0x0(%rbp),%rcx
  mov    %rcx,%r8
  add    %rbx,%rcx
  cmp    %rcx,%rdx
  jae    L159
L154:
  movzbl (%rdx),%eax
  mov    %rsi,%r8
  lea    0x1(%rdx),%rdi
  add    $0x1,%rsi
  test   %al,%al
  js     L100
  mov    %rdi,%rdx
  jmp    L152
  nopl   0x0(%rax)
L77:
  mov    %rdi,%rdx
  mov    $0x3f,%eax
  jmp    L152
  nopw   0x0(%rax,%rax,1)
L14:
  add    $0x1,%r13d
  jmp    L54
  nopl   0x0(%rax)
L144:
  add    $0x8,%rsp
  xor    %r12d,%r12d
  pop    %rbx
  mov    %r12,%rax
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopl   0x0(%rax)
L159:
  mov    %esi,%r13d
  sub    %r12d,%r13d
L31:
  mov    %r8d,%esi
  lea    D33(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %r13d,0x0(%rbp)
  mov    %r13d,%esi
  xor    %eax,%eax
  lea    D18(%rip),%rdi
  call   <printf@plt>
  add    $0x8,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopw   0x0(%rax,%rax,1)
L84:
  mov    %esi,%r13d
  movb   $0x3f,(%r8)
  mov    0x0(%rbp),%r8d
  sub    %r12d,%r13d
  jmp    L31
L69:
  xor    %edx,%edx
  xor    %esi,%esi
  lea    D5(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L127
L199:
  xor    %r13d,%r13d
  jmp    L31
```

tool_calls: name: disassemble_data
arguments: label: D5
datatype: string
name: disassemble_data
arguments: label: D9
datatype: string
name: disassemble_data
arguments: label: D33
datatype: string
name: disassemble_data
arguments: label: D18
datatype: string

tool: D5: singlebyte %d multibyte %d


tool: D9: converting utf-8 -> latin1

tool: D33: previous length %d


tool: D18: new length %d


assistant: ```c
unsigned char *utf8_to_latin1(unsigned char *text, int *length) {
  int i;
  int singlebyte = 0;
  int multibyte = 0;
  if (*length < 3)
    return NULL;
  for (i = 0; i < *length - 3; i++) {
    if (text[i] >= 128) {
      if (text[i + 1] < 128)
        singlebyte++;
      else
        multibyte++;
      while (text[i] >= 128)
        i++;
    }
  }
  printf("singlebyte %d multibyte %d\n", singlebyte, multibyte);
  if (singlebyte > multibyte)
    return NULL;
  printf("converting utf-8 -> latin1\n");
  unsigned char *convtext = malloc(*length);
  unsigned char *cc = convtext;
  unsigned char *tt = text;
  int ch;
  while (tt < text + *length) {
    if (*tt < 128) {
      *cc++ = *tt++;
      continue;
    }
    if (*tt > 0xe0) {
      *cc++ = '?';
      tt++;
      continue;
    }
    if (tt + 1 >= text + *length) {
      *cc++ = '?';
      break;
    }
    ch = ((tt[0] & 0x1f) << 6) | (tt[1] & 0x3f);
    if (ch > 255) {
      *cc++ = '?';
    } else
      *cc++ = ch;
    tt += 2;
  }
  printf("previous length %d\n", *length);
  *length = cc - convtext;
  printf("new length %d\n", *length);
  return convtext;
}
```