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

```asm
<text_read_file>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x238,%rsp
  mov    %rdx,0x8(%rsp)
  mov    %rcx,0x10(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x228(%rsp)
  xor    %eax,%eax
  test   %esi,%esi
  mov    $0x1,%eax
  cmovg  %esi,%eax
  lea    D3(%rip),%rsi
  mov    %eax,0x1c(%rsp)
  mov    %eax,%r15d
  call   <fopen@plt>
  test   %rax,%rax
  je     L31
  mov    %rax,%r13
  movslq %r15d,%rax
  xor    %ebx,%ebx
  xor    %ebp,%ebp
  mov    %rax,(%rsp)
  lea    0x20(%rsp),%r12
  nopl   0x0(%rax,%rax,1)
L17:
  mov    %r13,%rcx
  mov    $0x200,%edx
  mov    $0x1,%esi
  mov    %r12,%rdi
  call   <fread@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L5
  test   %rbx,%rbx
  jne    L51
  mov    (%rsp),%rax
  mov    $0x1,%esi
  mov    %r14,%rbx
  lea    (%rax,%r14,1),%rdi
  call   <xcalloc@plt>
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    %rax,%rdi
  mov    %rax,%rbp
  call   <memcpy@plt>
  jmp    L17
  nopw   0x0(%rax,%rax,1)
L51:
  lea    (%rbx,%rax,1),%r15
  mov    (%rsp),%rax
  mov    %rbp,%rdi
  lea    (%rax,%r15,1),%rsi
  call   <xrealloc@plt>
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    %rax,%rbp
  lea    (%rax,%rbx,1),%rdi
  mov    %r15,%rbx
  call   <memcpy@plt>
  movb   $0x0,0x0(%rbp,%r15,1)
  jmp    L17
  nopl   0x0(%rax)
L5:
  mov    %r13,%rdi
  call   <ferror@plt>
  test   %rax,%rax
  jne    L126
  test   %rbx,%rbx
  je     L63
L21:
  mov    0x8(%rsp),%rax
  test   %rax,%rax
  je     L61
  mov    %rbp,(%rax)
L61:
  mov    0x10(%rsp),%rax
  test   %rax,%rax
  je     L56
  mov    %rbx,(%rax)
L56:
  mov    %ebx,%eax
L14:
  mov    0x228(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L83
  add    $0x238,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L63:
  mov    0x1c(%rsp),%edi
  call   <xmalloc@plt>
  movb   $0x0,(%rax)
  mov    %rax,%rbp
  jmp    L21
L126:
  mov    %rbp,%rdi
  call   <xfree@plt>
  mov    %r13,%rdi
  call   <fclose@plt>
  mov    $0xffffffff,%eax
  jmp    L14
L31:
  mov    $0xffffffff,%eax
  jmp    L14
L83:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: tag: D3
type_guessed: string

tool: D3: r

assistant: ```c
int text_read_file(const unsigned char *path, int reserve, unsigned char **out, size_t *out_len) {
  unsigned char read_buf[512];
  unsigned char *buf = 0;
  size_t buf_len = 0, read_len = 0;
  FILE *f = 0;
  if (reserve <= 0)
    reserve = 1;
  if (!(f = fopen(path, "r"))) {
    return -1;
  }
  while (1) {
    read_len = fread(read_buf, 1, sizeof(read_buf), f);
    if (!read_len)
      break;
    if (!buf_len) {
      buf = (unsigned char *)xcalloc(read_len + reserve, 1);
      memcpy(buf, read_buf, read_len);
      buf_len = read_len;
    } else {
      buf = (unsigned char *)xrealloc(buf, buf_len + reserve + read_len);
      memcpy(buf + buf_len, read_buf, read_len);
      buf_len += read_len;
      buf[buf_len] = 0;
    }
  }
  if (ferror(f)) {
    xfree(buf);
    fclose(f);
    return -1;
  }
  if (!buf_len) {
    buf = (unsigned char *)xmalloc(reserve);
    buf[0] = 0;
    buf_len = 0;
  }
  if (out)
    *out = buf;
  if (out_len)
    *out_len = buf_len;
  return (int)buf_len;
}
```