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

```asm
<read_nul_sep>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x10(%rbp)
  movl   $0x0,-0x30(%rbp)
  movl   $0x0,-0x2c(%rbp)
  movl   $0x0,-0x28(%rbp)
  movl   $0x0,-0x24(%rbp)
  mov    D8(%rip),%rax
  mov    (%rax),%edx
  mov    -0x38(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <open@plt>
  mov    %eax,-0x20(%rbp)
  mov    $0x1000,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  movl   $0x1000,-0x28(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L121
  mov    -0x20(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    $0x0,%eax
  jmp    L20
L121:
  movl   $0x0,-0x1c(%rbp)
  mov    -0x28(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jne    L78
  mov    -0x28(%rbp),%eax
  lea    (%rax,%rax,1),%edx
  mov    -0x18(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x18(%rbp)
  shll   -0x28(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L78
  mov    -0x20(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    $0x0,%eax
  jmp    L20
L78:
  mov    -0x28(%rbp),%eax
  sub    -0x30(%rbp),%eax
  mov    %eax,%edx
  mov    -0x30(%rbp),%eax
  movslq %eax,%rcx
  mov    -0x18(%rbp),%rax
  add    %rax,%rcx
  mov    -0x20(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %eax,-0x1c(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  jns    L92
  mov    -0x20(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
  jmp    L20
L92:
  cmpl   $0x0,-0x1c(%rbp)
  jne    L199
  mov    -0x20(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  nop
  movl   $0x0,-0x24(%rbp)
  jmp    L180
L199:
  mov    -0x1c(%rbp),%eax
  add    %eax,-0x30(%rbp)
  jmp    L121
L104:
  mov    -0x24(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L197
  addl   $0x1,-0x2c(%rbp)
L197:
  addl   $0x1,-0x24(%rbp)
L180:
  mov    -0x24(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jl     L104
  mov    -0x24(%rbp),%eax
  cltq
  lea    -0x1(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L7
  addl   $0x1,-0x2c(%rbp)
L7:
  mov    -0x2c(%rbp),%eax
  add    $0x1,%eax
  cltq
  lea    0x0(,%rax,8),%edx
  mov    -0x30(%rbp),%eax
  add    %edx,%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x8(%rbp)
  mov    -0x2c(%rbp),%eax
  mov    %eax,-0x24(%rbp)
  jmp    L165
L12:
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  movq   $0x0,(%rax)
  addl   $0x1,-0x24(%rbp)
L165:
  mov    -0x2c(%rbp),%eax
  cmp    -0x24(%rbp),%eax
  jge    L12
  mov    -0x2c(%rbp),%eax
  add    $0x1,%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x30(%rbp),%edx
  mov    -0x18(%rbp),%rcx
  mov    -0x10(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x30(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  movl   $0x0,-0x2c(%rbp)
  movl   $0x0,-0x24(%rbp)
  jmp    L11
L31:
  mov    -0x24(%rbp),%eax
  movslq %eax,%rcx
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x2c(%rbp)
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  mov    -0x10(%rbp),%rdx
  add    %rcx,%rdx
  mov    %rdx,(%rax)
  jmp    L59
L147:
  addl   $0x1,-0x24(%rbp)
L59:
  mov    -0x24(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jge    L178
  mov    -0x24(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L147
L178:
  addl   $0x1,-0x24(%rbp)
L11:
  mov    -0x24(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jl     L31
  mov    -0x8(%rbp),%rax
L20:
  leave
  ret
```

assistant: ```c
const char **read_nul_sep(const char *filename) {
  char *buf = NULL;
  char *newbuf = NULL;
  int buflen = 0;
  int count = 0;
  int size = 0;
  int i = 0;
  char **results;
  int fd = open(filename, O_RDONLY);
  buf = (char *)malloc(4096);
  size = 4096;
  if (buf == NULL) {
    close(fd);
    return NULL;
  }
  while (1) {
    int r = 0;
    if (size - buflen == 0) {
      buf = (char *)realloc(buf, size * 2);
      size = size * 2;
      if (buf == NULL) {
        close(fd);
        return NULL;
      }
    }
    r = read(fd, &buf[buflen], size - buflen);
    if (r < 0) {
      close(fd);
      free(buf);
      return NULL;
    }
    if (r == 0) {
      close(fd);
      break;
    }
    buflen += r;
  }
  for (i = 0; i < buflen; i += 1) {
    if (buf[i] == '\0') {
      count += 1;
    }
  }
  if (buf[i - 1] != '\0') {
    count += 1;
  }
  results = (char **)malloc(sizeof(char *) * (count + 1) + (buflen + 1));
  for (i = count; i < count + 1; i += 1) {
    results[i] = NULL;
  }
  newbuf = ((char *)results) + sizeof(char *) * (count + 1);
  memcpy(newbuf, buf, buflen);
  newbuf[buflen] = '\0';
  free(buf);
  count = 0;
  for (i = 0; i < buflen;) {
    results[count++] = &newbuf[i];
    for (; i < buflen && newbuf[i] != '\0'; i += 1)
      ;
    i += 1;
  }
  return (const char **)results;
}
```