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

```asm
<htmlspecialchars>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  test   %rdi,%rdi
  je     L150
  mov    %rdi,%r14
  call   <strlen@plt>
  lea    0x1(%rax),%edi
  call   <malloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L150
  movb   $0x0,(%rax)
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  test   %eax,%eax
  jle    L123
  lea    -0x1(%rax),%eax
  lea    D3(%rip),%r13
  lea    0x1(%r14,%rax,1),%rbp
  lea    D24(%rip),%r12
  jmp    L149
  nopl   0x0(%rax)
L189:
  cmp    $0x22,%al
  je     L21
  cmp    $0x27,%al
  je     L29
  cmp    $0x3c,%al
  je     L75
  cmp    $0x3e,%al
  je     L13
  mov    $0x1,%edx
  mov    %r14,%rsi
  mov    %r15,%rdi
  call   <strncat@plt>
L9:
  add    $0x1,%r14
  cmp    %rbp,%r14
  je     L123
L149:
  movzbl (%r14),%eax
  cmp    $0x26,%al
  jne    L189
  lea    D19(%rip),%r9
  mov    %r9,%rdi
  call   <strlen@plt>
  mov    %r15,%rdi
  add    %eax,%ebx
  mov    %ebx,%esi
  call   <realloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L150
  lea    D19(%rip),%r9
  mov    %rax,%rdi
  add    $0x1,%r14
  mov    %r9,%rsi
  call   <strcat@plt>
  cmp    %rbp,%r14
  jne    L149
L123:
  add    $0x8,%rsp
  mov    %r15,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L21:
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %r15,%rdi
  add    %eax,%ebx
  mov    %ebx,%esi
  call   <realloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L150
  mov    %r12,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L9
L13:
  mov    %r13,%rdi
  call   <strlen@plt>
  mov    %r15,%rdi
  add    %eax,%ebx
  mov    %ebx,%esi
  call   <realloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L150
  mov    %r13,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L9
L29:
  lea    D21(%rip),%rdi
  call   <strlen@plt>
  mov    %r15,%rdi
  add    %eax,%ebx
  mov    %ebx,%esi
  call   <realloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L150
  lea    D21(%rip),%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L9
  nopl   0x0(%rax)
L75:
  lea    D11(%rip),%rdi
  call   <strlen@plt>
  mov    %r15,%rdi
  add    %eax,%ebx
  mov    %ebx,%esi
  call   <realloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L150
  lea    D11(%rip),%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L9
  nopl   0x0(%rax)
L150:
  xor    %r15d,%r15d
  jmp    L123
```

tool_calls: name: parse_data
arguments: tag: D3
type: string
name: parse_data
arguments: tag: D24
type: string
name: parse_data
arguments: tag: D19
type: string
name: parse_data
arguments: tag: D21
type: string
name: parse_data
arguments: tag: D11
type: string

tool: D3: &gt;

tool: D24: &quot;

tool: D19: &amp;

tool: D21: &#039;

tool: D11: &lt;

assistant: ```c
char *htmlspecialchars(const char *s) {
  if (s == NULL) {
    return NULL;
  }
  char *t = malloc(strlen(s) + 1);
  if (t == NULL) {
    return NULL;
  }
  t[0] = '\0';
  for (int i = 0, old = strlen(s), new = old; i < old; i++) {
    if (s[i] == '&') {
      const char *entity = "&amp;";
      new += strlen(entity);
      t = realloc(t, new);
      if (t == NULL) {
        return NULL;
      }
      strcat(t, entity);
    } else if (s[i] == '"') {
      const char *entity = "&quot;";
      new += strlen(entity);
      t = realloc(t, new);
      if (t == NULL) {
        return NULL;
      }
      strcat(t, entity);
    } else if (s[i] == '\'') {
      const char *entity = "&#039;";
      new += strlen(entity);
      t = realloc(t, new);
      if (t == NULL) {
        return NULL;
      }
      strcat(t, entity);
    } else if (s[i] == '<') {
      const char *entity = "&lt;";
      new += strlen(entity);
      t = realloc(t, new);
      if (t == NULL) {
        return NULL;
      }
      strcat(t, entity);
    } else if (s[i] == '>') {
      const char *entity = "&gt;";
      new += strlen(entity);
      t = realloc(t, new);
      if (t == NULL) {
        return NULL;
      }
      strcat(t, entity);
    } else {
      strncat(t, s + i, 1);
    }
  }
  return t;
}
```