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

```asm
<realhostname>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,%r13
  mov    %rdx,%r12
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    D2(%rip),%rax
  mov    (%rax),%ebx
  movslq %ebx,%rax
  add    $0xf,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffffff0,%rcx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rdx
  sub    %rax,%rdx
L152:
  cmp    %rdx,%rsp
  je     L5
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L152
L5:
  mov    %rcx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L34
  orq    $0x0,-0x8(%rsp,%rax,1)
L34:
  mov    %rsp,%r14
  mov    D17(%rip),%rax
  mov    (%rax),%edx
  mov    $0x4,%esi
  mov    %r12,%rdi
  call   <gethostbyaddr@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L64
  mov    %ebx,%edx
  mov    (%rax),%rsi
  mov    %r14,%rdi
  call   <strlcpy@plt>
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %rax,%rsi
  mov    %r14,%rdi
  call   <trimdomain@plt>
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    $0x2,%ebx
  cmp    %r13,%rax
  jbe    L120
L107:
  mov    (%r12),%edi
  call   <inet_ntoa@plt>
  mov    %rax,%rsi
  mov    %r13,%rdx
  mov    -0x48(%rbp),%rdi
  call   <strncpy@plt>
L100:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L139
  mov    %ebx,%eax
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L120:
  mov    %rsp,-0x50(%rbp)
  mov    D2(%rip),%rax
  movslq (%rax),%rbx
  lea    0xf(%rbx),%rax
  mov    %rax,%rcx
  and    $0xfffffffffffffff0,%rcx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rdx
  sub    %rax,%rdx
L70:
  cmp    %rdx,%rsp
  je     L92
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L70
L92:
  mov    %rcx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L149
  orq    $0x0,-0x8(%rsp,%rax,1)
L149:
  lea    -0x1(%rbx),%rdx
  mov    (%r15),%rsi
  mov    %rsp,%rdi
  call   <strncpy@plt>
  movb   $0x0,-0x1(%rsp,%rbx,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
  je     L68
L59:
  mov    $0x4,%edx
  mov    %r12,%rsi
  call   <memcmp@plt>
  mov    %eax,%ebx
  test   %eax,%eax
  je     L124
  mov    0x8(%r15),%rax
  lea    0x8(%rax),%rdx
  mov    %rdx,0x8(%r15)
  mov    0x8(%rax),%rdi
  test   %rdi,%rdi
  jne    L59
  mov    $0x1,%ebx
L151:
  mov    -0x50(%rbp),%rsp
  jmp    L107
L124:
  mov    %r13,%rdx
  mov    %r14,%rsi
  mov    -0x48(%rbp),%rdi
  call   <strncpy@plt>
  mov    -0x50(%rbp),%rsp
  jmp    L100
L130:
  mov    $0x3,%ebx
  jmp    L151
L68:
  mov    $0x1,%ebx
  jmp    L151
L64:
  mov    $0x2,%ebx
  jmp    L107
L139:
  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;
}
```