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

```asm
<nl_getmsg>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %edi,0x8(%rsp)
  mov    %esi,0xc(%rsp)
  mov    %edx,%r13d
  mov    %rcx,0x10(%rsp)
  mov    %r8,0x18(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  call   <getpid@plt>
  mov    %rax,%rbp
  mov    $0x0,%r14d
  movq   $0x0,(%rsp)
  mov    $0x10000,%r12d
  lea    0x24(%rsp),%r15
L174:
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <realloc@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L158
  cmp    (%rsp),%r12
  jb     L158
  mov    %r15,%r9
  mov    %r12,%r8
  mov    %rax,%rcx
  mov    %r13d,%edx
  mov    0xc(%rsp),%esi
  mov    0x8(%rsp),%edi
  call   <nl_recvmsg@plt>
  mov    %eax,%r14d
  test   %eax,%eax
  js     L1
  mov    D54(%rip),%rdx
  mov    0x24(%rsp),%eax
  and    (%rdx),%eax
  jne    L1
  mov    %rbx,%r12
  test   %r14d,%r14d
  jne    L170
L52:
  mov    0x10(%rsp),%rax
  mov    %rbx,(%rax)
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L38
  mov    %r14d,%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L1:
  mov    %rbx,%r14
  mov    %r12,(%rsp)
  add    %r12,%r12
  jmp    L174
L32:
  mov    0x18(%rsp),%rax
  addl   $0x1,(%rax)
  jmp    L52
L113:
  mov    0x0(%rbp),%eax
  neg    %eax
  jmp    L139
L13:
  mov    %r14d,%esi
  mov    %r12,%rdi
  call   <NLMSG_NEXT@plt>
  mov    %rax,%r12
L170:
  mov    %r14d,%esi
  mov    %r12,%rdi
  call   <NLMSG_OK@plt>
  test   %rax,%rax
  je     L52
  cmp    %rbp,(%r12)
  jne    L13
  cmp    %r13d,0x8(%r12)
  jne    L13
  mov    0x10(%r12),%rax
  mov    D1(%rip),%rdx
  cmp    (%rdx),%rax
  je     L32
  mov    D0(%rip),%rdx
  cmp    (%rdx),%rax
  jne    L13
  mov    %r12,%rdi
  call   <NLMSG_DATA@plt>
  mov    %rax,%rbp
  mov    0x18(%r12),%r12
  mov    $0x4,%edi
  call   <NLMSG_LENGTH@plt>
  cmp    %rax,%r12
  jge    L113
  mov    D6(%rip),%rax
  mov    (%rax),%eax
L139:
  mov    D55(%rip),%rdx
  mov    %eax,(%rdx)
  mov    %rbx,%r14
L137:
  mov    D55(%rip),%rbx
  mov    (%rbx),%ebp
  mov    %r14,%rdi
  call   <free@plt>
  mov    %ebp,(%rbx)
  mov    %r14,%rbx
  mov    $0xffffffff,%r14d
  jmp    L52
L158:
  test   %r14,%r14
  jne    L137
  mov    %r14,%rbx
  mov    $0xffffffff,%r14d
  jmp    L52
L38:
  call   <__stack_chk_fail@plt>
```

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