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

```asm
<dns_lookup>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x88,%rsp
  mov    %rdi,-0x78(%rbp)
  mov    %esi,-0x7c(%rbp)
  mov    %edx,-0x80(%rbp)
  mov    %rcx,-0x88(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x60(%rbp)
  cmpl   $0x0,-0x80(%rbp)
  je     L93
  mov    D17(%rip),%rax
  mov    (%rax),%eax
  jmp    L40
L93:
  mov    $0x0,%eax
L40:
  mov    %eax,-0x5c(%rbp)
  mov    -0x88(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L55
  mov    -0x88(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L55
  mov    -0x88(%rbp),%rax
  add    $0x10,%rax
  mov    (%rax),%rbx
  mov    $0xffff,%edi
  call   <htonl@plt>
  cmp    %rax,%rbx
  jne    L55
  movl   $0x1,-0x60(%rbp)
L55:
  cmpl   $0x0,-0x60(%rbp)
  jne    L85
  mov    -0x88(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L16
  mov    -0x88(%rbp),%rax
  add    $0x10,%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L16
  mov    -0x88(%rbp),%rax
  add    $0x18,%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L16
L85:
  mov    D15(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x40(%rbp)
  movq   $0x0,-0x48(%rbp)
  cmpl   $0x0,-0x60(%rbp)
  je     L64
  mov    -0x88(%rbp),%rax
  mov    0x18(%rax),%rax
  jmp    L0
L64:
  mov    -0x88(%rbp),%rax
  mov    (%rax),%rax
L0:
  mov    %rax,-0x50(%rbp)
  lea    -0x50(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  movl   $0x18,-0x64(%rbp)
  jmp    L71
L16:
  lea    -0x30(%rbp),%rax
  mov    $0x18,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    D1(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x20(%rbp)
  movq   $0x0,-0x28(%rbp)
  mov    -0x30(%rbp),%eax
  mov    -0x88(%rbp),%rcx
  mov    $0x10,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <memcpy@plt>
  lea    -0x30(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  movl   $0x18,-0x64(%rbp)
L71:
  mov    -0x7c(%rbp),%ecx
  mov    -0x78(%rbp),%rdx
  mov    -0x64(%rbp),%esi
  mov    -0x58(%rbp),%rax
  sub    $0x8,%rsp
  mov    -0x5c(%rbp),%edi
  push   %rdi
  mov    $0x0,%r9d
  mov    $0x0,%r8d
  mov    %rax,%rdi
  call   <getnameinfo@plt>
  add    $0x10,%rsp
  mov    -0x18(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L2
  call   <__stack_chk_fail@plt>
L2:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
int dns_lookup(char *result, int size, int useip, int32_t *a) {
  struct sockaddr_in sin;
  struct sockaddr_in6 sin6;
  struct sockaddr *sa;
  int salen, flags;
  int mapped = 0;
  flags = useip ? NI_NUMERICHOST : 0;
  if (a[0] == 0 && a[1] == 0 && a[2] == (int32_t)htonl(0xffff))
    mapped = 1;
  if (mapped || (a[1] == 0 && a[2] == 0 && a[3] == 0)) {
    sin.sin_family = AF_INET;
    sin.sin_port = 0;
    sin.sin_addr.s_addr = mapped ? a[3] : a[0];
    sa = (struct sockaddr *)&sin;
    salen = sizeof(sin);
  } else {
    memset(&sin6, 0, sizeof(sin6));
    sin6.sin6_family = AF_INET6;
    sin6.sin6_port = 0;
    memcpy(sin6.sin6_addr.s6_addr, a, 16);
    sa = (struct sockaddr *)&sin6;
    salen = sizeof(sin6);
  }
  return getnameinfo(sa, salen, result, size, NULL, 0, flags);
}
```