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

```asm
<if_nameindex>:
  endbr64
  push   %rbp
  xor    %edx,%edx
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x48,%rsp
  mov    D5(%rip),%rbx
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    D59(%rip),%rax
  mov    (%rbx),%esi
  mov    (%rax),%edi
  call   <socket@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L54
L101:
  mov    D55(%rip),%rbx
  lea    -0x60(%rbp),%r13
  mov    %r12d,%edi
  movq   $0x0,-0x40(%rbp)
  mov    %r13,%rdx
  movl   $0x0,-0x60(%rbp)
  mov    (%rbx),%esi
  call   <ioctl@plt>
  test   %eax,%eax
  js     L16
  movslq -0x60(%rbp),%rdi
  call   <alloca@plt>
  mov    (%rbx),%esi
  mov    %r13,%rdx
  mov    %r12d,%edi
  mov    %rax,-0x40(%rbp)
  call   <ioctl@plt>
  test   %eax,%eax
  js     L16
  movabs $0xcccccccccccccccd,%rcx
  movslq -0x60(%rbp),%rdx
  mov    %rdx,%rax
  mul    %rcx
  mov    D57(%rip),%rcx
  mov    (%rcx),%eax
  shr    $0x5,%rdx
  imul   %edx,%eax
  lea    0x1(%rdx),%edi
  mov    %rdx,%r14
  shl    $0x4,%edi
  add    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x70(%rbp)
  mov    %rax,%rdx
  test   %rax,%rax
  je     L16
  movslq %r14d,%rcx
  add    $0x1,%rcx
  shl    $0x4,%rcx
  lea    (%rax,%rcx,1),%r13
  test   %r14d,%r14d
  jle    L81
  lea    -0x1(%r14),%eax
  xor    %r15d,%r15d
  mov    %rdx,%r14
  lea    0x4(,%rax,4),%rax
  mov    %rax,-0x68(%rbp)
  nopl   0x0(%rax,%rax,1)
L25:
  mov    -0x48(%rbp),%rbx
  mov    D57(%rip),%rax
  mov    %r13,(%r14)
  mov    %r13,%rdi
  add    %r15,%rbx
  mov    (%rax),%edx
  mov    0x10(%rbx),%esi
  call   <memcpy@plt>
  mov    D3(%rip),%rax
  mov    %rbx,%rdx
  mov    %r12d,%edi
  mov    (%rax),%esi
  call   <ioctl@plt>
  cmp    $0xffffffff,%eax
  je     L51
  mov    0x8(%rbx),%rax
  add    $0x10,%r14
  mov    %rax,-0x8(%r14)
  mov    D57(%rip),%rax
  movslq (%rax),%rax
  add    %rax,%r13
L51:
  add    $0x4,%r15
  cmp    -0x68(%rbp),%r15
  jne    L25
L70:
  movq   $0x0,(%r14)
  movq   $0x0,0x8(%r14)
  jmp    L53
  nopl   0x0(%rax,%rax,1)
L16:
  movq   $0x0,-0x70(%rbp)
L53:
  mov    %r12d,%edi
  call   <close@plt>
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L60
  mov    -0x70(%rbp),%rax
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopw   0x0(%rax,%rax,1)
L54:
  mov    D42(%rip),%rax
  mov    (%rbx),%esi
  xor    %edx,%edx
  mov    (%rax),%edi
  call   <socket@plt>
  mov    %eax,%r12d
  jmp    L101
  nopw   0x0(%rax,%rax,1)
L81:
  mov    -0x70(%rbp),%r14
  jmp    L70
L60:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
struct if_nameindex *if_nameindex(void) {
  struct ifconf ic;
  int fd, len, i;
  struct if_nameindex *x = 0, *y;
  char *dest;
  fd = socket(AF_INET6, SOCK_DGRAM, 0);
  if (fd < 0)
    fd = socket(AF_INET, SOCK_DGRAM, 0);
  ic.ifc_buf = 0;
  ic.ifc_len = 0;
  if (ioctl(fd, SIOCGIFCONF, &ic) < 0)
    goto b0rken;
  ic.ifc_buf = alloca((size_t)ic.ifc_len);
  if (ioctl(fd, SIOCGIFCONF, &ic) < 0)
    goto b0rken;
  len = (ic.ifc_len / sizeof(struct ifreq));
  x = (struct if_nameindex *)malloc((len + 1) * sizeof(struct if_nameindex) + len * IFNAMSIZ);
  if (!x)
    goto b0rken;
  dest = (char *)(x + len + 1);
  y = x;
  for (i = 0; i < len; ++i) {
    struct ifreq *ir = (struct ifreq *)&ic.ifc_req[i];
    y->if_name = dest;
    memcpy(dest, ir->ifr_name, IFNAMSIZ);
    if (ioctl(fd, SIOCGIFINDEX, ir) == -1)
      continue;
    y->if_index = ir->ifr_ifindex;
    dest += IFNAMSIZ;
    ++y;
  }
  y->if_name = 0;
  y->if_index = 0;
b0rken:
  close(fd);
  return x;
}
```