user: Converte this assembly snippet into its equivalent C code:

```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     L70
  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     L180
  mov    %r13,%rsi
  xor    %eax,%eax
  nopl   0x0(%rax)
L8:
  add    $0x8,%rsi
  add    $0x8,%rbp
  mov    %eax,%edi
  add    $0x1,%eax
  cmpq   $0x0,(%rsi)
  jne    L8
  lea    0x10(,%rdi,8),%eax
L133:
  sub    %eax,%ebx
  js     L70
  mov    0x8(%rsp),%rax
  lea    0x8(%rbp),%r14
  mov    %r14,0x10(%rax)
  mov    0x10(%r12),%r15
  mov    (%r15),%rsi
  test   %rsi,%rsi
  je     L129
  mov    %r14,%rdi
  mov    %r15,%rcx
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L177:
  add    $0x8,%rcx
  mov    %rdi,%rbp
  mov    %eax,%r8d
  add    $0x8,%rdi
  add    $0x1,%eax
  cmpq   $0x0,(%rcx)
  jne    L177
  lea    0x10(,%r8,8),%eax
  sub    %eax,%ebx
  js     L70
  mov    (%r12),%edx
  add    $0x10,%rbp
  jmp    L5
  nopl   (%rax)
L152:
  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     L22
L5:
  sub    %edx,%ebx
  jns    L152
L70:
  add    $0x18,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  xchg   %ax,%ax
L22:
  mov    0x8(%rsp),%rax
  mov    0x8(%r12),%r13
  mov    0x8(%rax),%rcx
L4:
  movq   $0x0,(%r14)
  mov    0x0(%r13),%rsi
  test   %rsi,%rsi
  jne    L18
  jmp    L181
L30:
  mov    0x8(%r13),%rsi
  add    $0x8,%r13
  add    $0x8,%rcx
  test   %rsi,%rsi
  je     L181
L18:
  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    L30
  jmp    L70
  nopl   (%rax)
L181:
  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     L70
  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)
L129:
  sub    $0x8,%ebx
  js     L70
  add    $0x10,%rbp
  jmp    L4
  nopw   0x0(%rax,%rax,1)
L180:
  mov    $0x8,%eax
  jmp    L133
```

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);
}
```