user: Please show me the C implementation that matches the assembly code listed below:

```asm
<realhostname>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r12
  push   %rbx
  sub    $0x70,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %rsi,-0x70(%rbp)
  mov    %rdx,-0x78(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x28(%rbp)
  xor    %eax,%eax
  mov    %rsp,%rax
  mov    %rax,%r12
  mov    D27(%rip),%rax
  mov    (%rax),%ebx
  movslq %ebx,%rax
  sub    $0x1,%rax
  mov    %rax,-0x50(%rbp)
  movslq %ebx,%rax
  mov    %rax,%r10
  mov    $0x0,%r11d
  movslq %ebx,%rax
  mov    %rax,%r8
  mov    $0x0,%r9d
  movslq %ebx,%rax
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%edi
  mov    $0x0,%edx
  div    %rdi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L23:
  cmp    %rdx,%rsp
  je     L123
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L23
L123:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L86
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L86:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x48(%rbp)
  movl   $0x2,-0x54(%rbp)
  mov    D25(%rip),%rax
  mov    (%rax),%edx
  mov    -0x78(%rbp),%rax
  mov    $0x4,%esi
  mov    %rax,%rdi
  call   <gethostbyaddr@plt>
  mov    %rax,-0x40(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  je     L43
  mov    -0x40(%rbp),%rax
  mov    0x8(%rax),%ecx
  mov    -0x48(%rbp),%rax
  mov    %ebx,%edx
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <strlcpy@plt>
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <trimdomain@plt>
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cmp    %rax,-0x70(%rbp)
  jb     L43
  mov    %rsp,%rax
  mov    %rax,%rbx
  mov    D27(%rip),%rax
  mov    (%rax),%ecx
  movslq %ecx,%rax
  sub    $0x1,%rax
  mov    %rax,-0x38(%rbp)
  movslq %ecx,%rax
  mov    %rax,-0x90(%rbp)
  movq   $0x0,-0x88(%rbp)
  movslq %ecx,%rax
  mov    %rax,%r14
  mov    $0x0,%r15d
  movslq %ecx,%rax
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%edi
  mov    $0x0,%edx
  div    %rdi
  imul   $0x10,%rax,%rax
  mov    %rax,%rsi
  and    $0xfffffffffffff000,%rsi
  mov    %rsp,%rdx
  sub    %rsi,%rdx
L150:
  cmp    %rdx,%rsp
  je     L6
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L150
L6:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L108
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L108:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x30(%rbp)
  mov    -0x40(%rbp),%rax
  mov    0x8(%rax),%esi
  mov    -0x30(%rbp),%rax
  mov    %ecx,%edx
  mov    %rax,%rdi
  call   <strlcpy@plt>
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <gethostbyname@plt>
  mov    %rax,-0x40(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L60
  movl   $0x3,-0x54(%rbp)
  jmp    L53
L60:
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L112
  movl   $0x1,-0x54(%rbp)
  jmp    L53
L112:
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  mov    (%rax),%rax
  mov    -0x78(%rbp),%rcx
  mov    $0x4,%edx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcmp@plt>
  test   %eax,%eax
  jne    L114
  mov    -0x70(%rbp),%rdx
  mov    -0x48(%rbp),%rcx
  mov    -0x68(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    $0x0,%eax
  mov    %rbx,%rsp
  jmp    L75
L114:
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  lea    0x8(%rax),%rdx
  mov    -0x40(%rbp),%rax
  mov    %rdx,(%rax)
  jmp    L60
L53:
  mov    %rbx,%rsp
L43:
  mov    -0x78(%rbp),%rax
  mov    (%rax),%edi
  call   <inet_ntoa@plt>
  mov    %rax,%rcx
  mov    -0x70(%rbp),%rdx
  mov    -0x68(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x54(%rbp),%eax
L75:
  mov    %r12,%rsp
  mov    -0x28(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L134
  call   <__stack_chk_fail@plt>
L134:
  lea    -0x20(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

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