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

```asm
<realhostname>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  mov    %rdi,%r13
  push   %r12
  mov    %rsi,%r12
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  mov    D11(%rip),%rax
  mov    %rsp,%rcx
  movslq (%rax),%rax
  mov    %rax,%r15
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L89
L160:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L160
L89:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L24
L4:
  mov    D24(%rip),%rax
  mov    $0x4,%esi
  mov    %rbx,%rdi
  mov    %rsp,-0x50(%rbp)
  mov    (%rax),%edx
  call   <gethostbyaddr@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L66
  mov    (%rax),%rsi
  mov    %r15d,%edx
  mov    %rsp,%rdi
  call   <strlcpy@plt>
  mov    %rsp,%rdi
  call   <strlen@plt>
  mov    %rsp,%rdi
  mov    %rax,%rsi
  call   <trimdomain@plt>
  mov    %rsp,%rdi
  call   <strlen@plt>
  cmp    %r12,%rax
  jbe    L9
L66:
  mov    $0x2,%r14d
L54:
  mov    (%rbx),%edi
  call   <inet_ntoa@plt>
  mov    %r12,%rdx
  mov    %r13,%rdi
  mov    %rax,%rsi
  call   <strncpy@plt>
L50:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L34
  lea    -0x28(%rbp),%rsp
  mov    %r14d,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   0x0(%rax,%rax,1)
L9:
  mov    D11(%rip),%rax
  mov    %rsp,-0x48(%rbp)
  mov    %rsp,%rsi
  movslq (%rax),%r15
  lea    0xf(%r15),%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  and    $0xfffffffffffffff0,%rdx
  sub    %rax,%rsi
L110:
  cmp    %rsi,%rsp
  je     L172
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L110
  nopl   0x0(%rax)
L24:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L4
  nopl   0x0(%rax,%rax,1)
L172:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L26
L136:
  mov    (%r14),%rsi
  lea    -0x1(%r15),%rdx
  mov    %rsp,%rdi
  call   <strncpy@plt>
  movb   $0x0,-0x1(%rsp,%r15,1)
  mov    %rsp,%rdi
  call   <gethostbyname@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L130
  mov    0x8(%rax),%rax
  mov    (%rax),%rdi
  test   %rdi,%rdi
  jne    L60
  jmp    L86
  nopl   (%rax)
L94:
  mov    0x8(%r15),%rax
  mov    0x8(%rax),%rdi
  lea    0x8(%rax),%rdx
  mov    %rdx,0x8(%r15)
  test   %rdi,%rdi
  je     L86
L60:
  mov    $0x4,%edx
  mov    %rbx,%rsi
  call   <memcmp@plt>
  mov    %eax,%r14d
  test   %eax,%eax
  jne    L94
  mov    -0x50(%rbp),%rsi
  mov    %r12,%rdx
  mov    %r13,%rdi
  call   <strncpy@plt>
  mov    -0x48(%rbp),%rsp
  jmp    L50
  nopl   0x0(%rax)
L130:
  mov    $0x3,%r14d
L33:
  mov    -0x48(%rbp),%rsp
  jmp    L54
  nop
L86:
  mov    $0x1,%r14d
  jmp    L33
  nopl   0x0(%rax,%rax,1)
L26:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L136
L34:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int realhostname(char *host, size_t hsize, const struct in_addr *ip) {
  char trimmed[MAXHOSTNAMELEN];
  int result;
  struct hostent *hp;
  result = (2);
  hp = gethostbyaddr((const char *)ip, sizeof(*ip), AF_INET);
  if (hp != NULL) {
    strlcpy(trimmed, hp->h_name, sizeof(trimmed));
    trimdomain(trimmed, strlen(trimmed));
    if (strlen(trimmed) <= hsize) {
      char lookup[MAXHOSTNAMELEN];
      strncpy(lookup, hp->h_name, sizeof(lookup) - 1);
      lookup[sizeof(lookup) - 1] = '\0';
      hp = gethostbyname(lookup);
      if (hp == NULL)
        result = (3);
      else
        for (;; hp->h_addr_list++) {
          if (*hp->h_addr_list == NULL) {
            result = (1);
            break;
          }
          if (!memcmp(*hp->h_addr_list, ip, sizeof(*ip))) {
            strncpy(host, trimmed, hsize);
            return (0);
          }
        }
    }
  }
  strncpy(host, inet_ntoa(*ip), hsize);
  return result;
}
```