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    D28(%rip),%rax
  mov    %rsp,%rcx
  movslq (%rax),%rax
  mov    %rax,%r14
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L23
L143:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L143
L23:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L110
L137:
  mov    D8(%rip),%rax
  mov    $0x4,%esi
  mov    %rbx,%rdi
  mov    %rsp,-0x50(%rbp)
  mov    (%rax),%edx
  call   <gethostbyaddr@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L98
  mov    0x8(%rax),%esi
  mov    %r14d,%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    L147
L98:
  mov    $0x2,%r15d
L9:
  mov    (%rbx),%edi
  call   <inet_ntoa@plt>
  mov    %r12,%rdx
  mov    %r13,%rdi
  mov    %rax,%rsi
  call   <strncpy@plt>
L94:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L89
  lea    -0x28(%rbp),%rsp
  mov    %r15d,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   0x0(%rax,%rax,1)
L147:
  mov    D28(%rip),%rax
  mov    %rsp,-0x48(%rbp)
  mov    %rsp,%rsi
  movslq (%rax),%rax
  mov    %rax,%r8
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  and    $0xfffffffffffffff0,%rdx
  sub    %rax,%rsi
L30:
  cmp    %rsi,%rsp
  je     L156
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L30
  nop
L110:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L137
  nopl   0x0(%rax,%rax,1)
L156:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L62
L76:
  mov    0x8(%r15),%esi
  mov    %r8d,%edx
  mov    %rsp,%rdi
  call   <strlcpy@plt>
  mov    %rsp,%rdi
  call   <gethostbyname@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L187
  mov    (%rax),%rax
  mov    (%rax),%rdi
  test   %rdi,%rdi
  jne    L188
  jmp    L77
  xchg   %ax,%ax
L172:
  mov    (%r14),%rax
  mov    0x8(%rax),%rdi
  lea    0x8(%rax),%rdx
  mov    %rdx,(%r14)
  test   %rdi,%rdi
  je     L77
L188:
  mov    $0x4,%edx
  mov    %rbx,%rsi
  call   <memcmp@plt>
  mov    %eax,%r15d
  test   %eax,%eax
  jne    L172
  mov    -0x50(%rbp),%rsi
  mov    %r12,%rdx
  mov    %r13,%rdi
  call   <strncpy@plt>
  mov    -0x48(%rbp),%rsp
  jmp    L94
  nop
L187:
  mov    $0x3,%r15d
L16:
  mov    -0x48(%rbp),%rsp
  jmp    L9
  nop
L77:
  mov    $0x1,%r15d
  jmp    L16
  nopl   0x0(%rax,%rax,1)
L62:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L76
L89:
  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];
      strlcpy(lookup, hp->h_name, sizeof(lookup));
      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;
}
```