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

```asm
<nl_getmsg>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x78,%rsp
  mov    %edi,-0x64(%rbp)
  mov    %esi,-0x68(%rbp)
  mov    %edx,-0x6c(%rbp)
  mov    %rcx,-0x78(%rbp)
  mov    %r8,-0x80(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  movq   $0x10000,-0x48(%rbp)
  movq   $0x0,-0x40(%rbp)
  movq   $0x0,-0x38(%rbp)
  movl   $0x0,-0x5c(%rbp)
  mov    $0x0,%eax
  call   <getpid@plt>
  mov    %rax,-0x30(%rbp)
L136:
  mov    -0x48(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  je     L213
  mov    -0x48(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jae    L192
L213:
  movl   $0xffffffff,-0x5c(%rbp)
  jmp    L86
L192:
  mov    -0x28(%rbp),%rax
  mov    %rax,-0x38(%rbp)
  lea    -0x60(%rbp),%r8
  mov    -0x48(%rbp),%rdi
  mov    -0x38(%rbp),%rcx
  mov    -0x6c(%rbp),%edx
  mov    -0x68(%rbp),%esi
  mov    -0x64(%rbp),%eax
  mov    %r8,%r9
  mov    %rdi,%r8
  mov    %eax,%edi
  call   <nl_recvmsg@plt>
  mov    %eax,-0x58(%rbp)
  mov    -0x58(%rbp),%eax
  mov    %eax,-0x5c(%rbp)
  cmpl   $0x0,-0x58(%rbp)
  js     L164
  mov    -0x60(%rbp),%edx
  mov    D53(%rip),%rax
  mov    (%rax),%eax
  and    %edx,%eax
  test   %eax,%eax
  je     L5
L164:
  mov    -0x48(%rbp),%rax
  mov    %rax,-0x40(%rbp)
  shlq   -0x48(%rbp)
  jmp    L23
L5:
  cmpl   $0x0,-0x58(%rbp)
  je     L101
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x50(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x50(%rbp)
  jmp    L135
L195:
  mov    -0x50(%rbp),%rax
  mov    (%rax),%rax
  cmp    %rax,-0x30(%rbp)
  jne    L18
  mov    -0x50(%rbp),%rax
  mov    0x8(%rax),%eax
  cmp    %eax,-0x6c(%rbp)
  jne    L18
  mov    -0x50(%rbp),%rax
  mov    0x10(%rax),%rdx
  mov    D58(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  jne    L104
  mov    -0x80(%rbp),%rax
  mov    (%rax),%eax
  lea    0x1(%rax),%edx
  mov    -0x80(%rbp),%rax
  mov    %edx,(%rax)
  jmp    L120
L104:
  mov    -0x50(%rbp),%rax
  mov    0x10(%rax),%rdx
  mov    D3(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  jne    L212
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <NLMSG_DATA@plt>
  mov    %rax,-0x20(%rbp)
  movl   $0xffffffff,-0x5c(%rbp)
  mov    -0x50(%rbp),%rax
  mov    0x18(%rax),%rbx
  mov    $0x4,%edi
  call   <NLMSG_LENGTH@plt>
  cmp    %rax,%rbx
  jge    L132
  mov    D33(%rip),%rax
  mov    (%rax),%edx
  mov    D18(%rip),%rax
  mov    %edx,(%rax)
  jmp    L120
L132:
  mov    -0x20(%rbp),%rax
  mov    (%rax),%eax
  neg    %eax
  mov    %eax,%edx
  mov    D18(%rip),%rax
  mov    %edx,(%rax)
  jmp    L120
L18:
  nop
L212:
  mov    -0x58(%rbp),%edx
  mov    -0x50(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <NLMSG_NEXT@plt>
  mov    %rax,-0x50(%rbp)
L135:
  mov    -0x58(%rbp),%edx
  mov    -0x50(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <NLMSG_OK@plt>
  test   %rax,%rax
  jne    L195
  jmp    L86
L120:
  jmp    L86
L23:
  jmp    L136
L101:
  nop
L86:
  cmpl   $0x0,-0x5c(%rbp)
  jns    L210
  cmpq   $0x0,-0x38(%rbp)
  je     L210
  mov    D18(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x54(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    D18(%rip),%rax
  mov    -0x54(%rbp),%edx
  mov    %edx,(%rax)
L210:
  mov    -0x78(%rbp),%rax
  mov    -0x38(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x5c(%rbp),%eax
  mov    -0x18(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L100
  call   <__stack_chk_fail@plt>
L100:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
int nl_getmsg(int sd, int request, int seq, struct nlmsghdr **nlhp, int *done) {
  struct nlmsghdr *nh;
  size_t bufsize = 65536, lastbufsize = 0;
  void *buff = NULL;
  int result = 0, read_size;
  int msg_flags;
  pid_t pid = getpid();
  for (;;) {
    void *newbuff = realloc(buff, bufsize);
    if (newbuff == NULL || bufsize < lastbufsize) {
      result = -1;
      break;
    }
    buff = newbuff;
    result = read_size = nl_recvmsg(sd, request, seq, buff, bufsize, &msg_flags);
    if (read_size < 0 || (msg_flags & MSG_TRUNC)) {
      lastbufsize = bufsize;
      bufsize *= 2;
      continue;
    }
    if (read_size == 0)
      break;
    nh = (struct nlmsghdr *)buff;
    for (nh = (struct nlmsghdr *)buff; NLMSG_OK(nh, read_size); nh = (struct nlmsghdr *)NLMSG_NEXT(nh, read_size)) {
      if (nh->nlmsg_pid != pid || nh->nlmsg_seq != seq)
        continue;
      if (nh->nlmsg_type == NLMSG_DONE) {
        (*done)++;
        break;
      }
      if (nh->nlmsg_type == NLMSG_ERROR) {
        struct nlmsgerr *nlerr = (struct nlmsgerr *)NLMSG_DATA(nh);
        result = -1;
        if (nh->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
          errno = (EIO);
        else
          errno = (-nlerr->error);
        break;
      }
    }
    break;
  }
  if (result < 0)
    if (buff) {
      int saved_errno = errno;
      free(buff);
      errno = (saved_errno);
    }
  *nlhp = (struct nlmsghdr *)buff;
  return result;
}
```