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

```asm
<copy_hostent>:
  endbr64
  push   %r15
  mov    %rsi,%r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x18,%rsp
  test   %rdi,%rdi
  setne  %dil
  mov    %rsi,0x8(%rsp)
  movzbl %dil,%edi
  call   <assert@plt>
  xor    %edi,%edi
  test   %r15,%r15
  setne  %dil
  call   <assert@plt>
  sub    $0x28,%ebx
  js     L145
  mov    0x20(%r12),%eax
  mov    0x8(%rsp),%rcx
  mov    %eax,0x20(%rcx)
  mov    (%r12),%eax
  mov    %eax,(%rcx)
  mov    %rcx,%rax
  lea    0x28(%rcx),%rcx
  mov    %rcx,0x8(%rax)
  mov    0x8(%r12),%r13
  mov    %rcx,%rbp
  cmpq   $0x0,0x0(%r13)
  je     L187
  mov    %r13,%rsi
  xor    %eax,%eax
  nopl   0x0(%rax)
L73:
  add    $0x8,%rsi
  add    $0x8,%rbp
  mov    %eax,%edi
  add    $0x1,%eax
  cmpq   $0x0,(%rsi)
  jne    L73
  lea    0x10(,%rdi,8),%eax
L2:
  sub    %eax,%ebx
  js     L145
  mov    0x8(%rsp),%rax
  lea    0x8(%rbp),%r14
  mov    %r14,0x10(%rax)
  mov    0x10(%r12),%r15
  mov    (%r15),%rsi
  test   %rsi,%rsi
  je     L149
  mov    %r14,%rdi
  mov    %r15,%rcx
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L188:
  add    $0x8,%rcx
  mov    %rdi,%rbp
  mov    %eax,%r8d
  add    $0x8,%rdi
  add    $0x1,%eax
  cmpq   $0x0,(%rcx)
  jne    L188
  lea    0x10(,%r8,8),%eax
  sub    %eax,%ebx
  js     L145
  mov    (%r12),%edx
  add    $0x10,%rbp
  jmp    L131
  nopl   (%rax)
L102:
  mov    %rbp,%rdi
  add    $0x8,%r15
  add    $0x8,%r14
  call   <memcpy@plt>
  mov    %rbp,-0x8(%r14)
  movslq (%r12),%rax
  mov    (%r15),%rsi
  mov    %rax,%rdx
  add    %rax,%rbp
  test   %rsi,%rsi
  je     L98
L131:
  sub    %edx,%ebx
  jns    L102
L145:
  add    $0x18,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  xchg   %ax,%ax
L98:
  mov    0x8(%rsp),%rax
  mov    0x8(%r12),%r13
  mov    0x8(%rax),%rcx
L80:
  movq   $0x0,(%r14)
  mov    0x0(%r13),%rsi
  test   %rsi,%rsi
  jne    L189
  jmp    L37
L15:
  mov    0x8(%r13),%rsi
  add    $0x8,%r13
  add    $0x8,%rcx
  test   %rsi,%rsi
  je     L37
L189:
  mov    %ebx,%edx
  mov    %rbp,%rdi
  mov    %rcx,(%rsp)
  call   <strlcpy@plt>
  mov    (%rsp),%rcx
  add    $0x1,%eax
  movslq %eax,%rdx
  mov    %rbp,(%rcx)
  add    %rdx,%rbp
  sub    %eax,%ebx
  jns    L15
  jmp    L145
  nopl   (%rax)
L37:
  mov    0x8(%rsp),%r14
  movq   $0x0,(%rcx)
  mov    %ebx,%edx
  mov    %rbp,%rdi
  mov    %rbp,0x18(%r14)
  mov    0x18(%r12),%rsi
  call   <strlcpy@plt>
  add    $0x1,%eax
  cmp    %eax,%ebx
  jl     L145
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <validate_hostent_copy@plt>
  not    %rax
  mov    %rax,%rdi
  shr    $0x3f,%rdi
  call   <assert@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L149:
  sub    $0x8,%ebx
  js     L145
  add    $0x10,%rbp
  jmp    L80
  nopw   0x0(%rax,%rax,1)
L187:
  mov    $0x8,%eax
  jmp    L2
```

assistant: ```c
int copy_hostent(const struct hostent *src, char *buf, int len) {
  struct hostent *dst;
  int n;
  char **p, **q;
  assert(src != NULL);
  assert(buf != NULL);
  dst = (struct hostent *)buf;
  if ((len -= sizeof(struct hostent)) < 0)
    return (-1);
  dst->h_addrtype = src->h_addrtype;
  dst->h_length = src->h_length;
  buf += sizeof(struct hostent);
  dst->h_aliases = (char **)buf;
  for (p = src->h_aliases, q = dst->h_aliases, n = 0; *p; p++, q++, n++) {
    ;
  }
  if ((len -= ++n * sizeof(char *)) < 0)
    return (-1);
  buf = (char *)(q + 1);
  dst->h_addr_list = (char **)buf;
  for (p = src->h_addr_list, q = dst->h_addr_list, n = 0; *p; p++, q++, n++) {
    ;
  }
  if ((len -= ++n * sizeof(char *)) < 0)
    return (-1);
  buf = (char *)(q + 1);
  for (p = src->h_addr_list, q = dst->h_addr_list; *p; p++, q++) {
    if ((len -= src->h_length) < 0)
      return (-1);
    memcpy(buf, *p, src->h_length);
    *q = buf;
    buf += src->h_length;
  }
  *q = NULL;
  for (p = src->h_aliases, q = dst->h_aliases; *p; p++, q++) {
    n = strlcpy(buf, *p, len);
    *q = buf;
    buf += ++n;
    if ((len -= n) < 0)
      return (-1);
  }
  *q = NULL;
  dst->h_name = buf;
  n = strlcpy(buf, src->h_name, len);
  buf += ++n;
  if ((len -= n) < 0)
    return (-1);
  assert(validate_hostent_copy(src, dst) >= 0);
  return (0);
}
```