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

```asm
<nl_getmsg>:
  endbr64
  push   %r15
  push   %r14
  xor    %r14d,%r14d
  push   %r13
  mov    $0x10000,%r13d
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %edi,0x8(%rsp)
  lea    0x24(%rsp),%r15
  mov    %esi,0xc(%rsp)
  mov    %rcx,0x10(%rsp)
  mov    %r8,0x18(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  call   <getpid@plt>
  movq   $0x0,(%rsp)
  mov    %rax,%rbp
L89:
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <realloc@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L32
  cmp    (%rsp),%r13
  jb     L32
  mov    0xc(%rsp),%esi
  mov    0x8(%rsp),%edi
  mov    %r15,%r9
  mov    %r13,%r8
  mov    %rax,%rcx
  mov    %r12d,%edx
  call   <nl_recvmsg@plt>
  mov    %eax,%r14d
  test   %eax,%eax
  js     L8
  mov    D38(%rip),%rdx
  mov    0x24(%rsp),%eax
  and    (%rdx),%eax
  jne    L8
  mov    %rbx,%r13
  test   %r14d,%r14d
  jne    L136
L127:
  mov    0x10(%rsp),%rax
  mov    %rbx,(%rax)
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L99
  add    $0x38,%rsp
  mov    %r14d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L20:
  cmp    %rbp,0x0(%r13)
  jne    L147
  cmp    %r12d,0x8(%r13)
  jne    L147
  mov    D2(%rip),%rdx
  mov    0x10(%r13),%rax
  cmp    (%rdx),%rax
  je     L190
  mov    D47(%rip),%rdx
  cmp    (%rdx),%rax
  je     L100
L147:
  mov    %r13,%rdi
  mov    %r14d,%esi
  call   <NLMSG_NEXT@plt>
  mov    %rax,%r13
L136:
  mov    %r14d,%esi
  mov    %r13,%rdi
  call   <NLMSG_OK@plt>
  test   %rax,%rax
  jne    L20
  jmp    L127
L8:
  mov    %r13,(%rsp)
  mov    %rbx,%r14
  add    %r13,%r13
  jmp    L89
  nop
L32:
  test   %r14,%r14
  jne    L53
  xor    %ebx,%ebx
  mov    $0xffffffff,%r14d
  jmp    L127
  nopw   0x0(%rax,%rax,1)
L53:
  mov    D31(%rip),%rbp
  mov    %r14,%rbx
  mov    0x0(%rbp),%r12d
L102:
  mov    %rbx,%rdi
  mov    $0xffffffff,%r14d
  call   <free@plt>
  mov    %r12d,0x0(%rbp)
  jmp    L127
L190:
  mov    0x18(%rsp),%rax
  addl   $0x1,(%rax)
  jmp    L127
L100:
  mov    %r13,%rdi
  call   <NLMSG_DATA@plt>
  mov    0x18(%r13),%r12
  mov    $0x4,%edi
  mov    %rax,%rbp
  call   <NLMSG_LENGTH@plt>
  cmp    %rax,%r12
  jl     L152
  mov    0x0(%rbp),%r12d
  neg    %r12d
L5:
  mov    D31(%rip),%rbp
  mov    %r12d,0x0(%rbp)
  jmp    L102
L152:
  mov    D54(%rip),%rax
  mov    (%rax),%r12d
  jmp    L5
L99:
  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;
}
```