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

```asm
<read_nul_sep>:
  endbr64
  push   %r15
  xor    %r15d,%r15d
  push   %r14
  push   %r13
  push   %r12
  mov    $0x1000,%r12d
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    D9(%rip),%rax
  mov    (%rax),%esi
  call   <open@plt>
  mov    $0x1000,%edi
  mov    %eax,%r14d
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L30
  xchg   %ax,%ax
L96:
  movslq %r15d,%r13
  mov    %r12d,%edx
  mov    %r14d,%edi
  sub    %r15d,%edx
  lea    0x0(%rbp,%r13,1),%rsi
  call   <read@plt>
  mov    %eax,%ebx
  test   %eax,%eax
  js     L143
  je     L12
  add    %eax,%r15d
  cmp    %r15d,%r12d
  jne    L96
  add    %r12d,%r12d
  mov    %rbp,%rdi
  mov    %r12d,%esi
  call   <realloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L96
L30:
  mov    %r14d,%edi
  xor    %r12d,%r12d
  call   <close@plt>
L15:
  add    $0x18,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L143:
  mov    %r14d,%edi
  xor    %r12d,%r12d
  call   <close@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  jmp    L15
  nopl   (%rax)
L12:
  mov    %r14d,%edi
  call   <close@plt>
  test   %r15d,%r15d
  je     L121
  lea    -0x1(%r15),%edx
  mov    %rbp,%rax
  lea    0x1(%rbp,%rdx,1),%rcx
  xor    %edx,%edx
  nopw   0x0(%rax,%rax,1)
L29:
  cmpb   $0x1,(%rax)
  adc    $0x0,%edx
  add    $0x1,%rax
  cmp    %rax,%rcx
  jne    L29
  lea    0x1(%rdx),%eax
  lea    -0x1(%r13),%rsi
  movslq %eax,%rcx
  shl    $0x3,%rcx
L208:
  cmpb   $0x0,0x0(%rbp,%rsi,1)
  jne    L141
  mov    %rcx,0x8(%rsp)
  movslq %edx,%rdx
  lea    0x0(,%rdx,8),%r14
L126:
  lea    0x1(%r15,%rax,8),%edi
  call   <malloc@plt>
  mov    %r15d,%edx
  mov    %rbp,%rsi
  movq   $0x0,(%rax,%r14,1)
  mov    0x8(%rsp),%r14
  mov    %rax,%r12
  add    %rax,%r14
  mov    %r14,%rdi
  call   <memcpy@plt>
  movb   $0x0,(%r14,%r13,1)
  mov    %rbp,%rdi
  call   <free@plt>
  test   %r15d,%r15d
  je     L15
  movslq %ebx,%rax
  mov    %r12,%rcx
  add    %r14,%rax
  mov    %rax,(%rcx)
  cmp    %r15d,%ebx
  jl     L75
  jmp    L159
  nopl   0x0(%rax)
L85:
  add    $0x1,%rax
  cmp    %ebx,%r15d
  je     L27
L75:
  cmpb   $0x0,(%rax)
  mov    %ebx,%edx
  lea    0x1(%rbx),%ebx
  jne    L85
  lea    0x1(%rdx),%ebx
  add    $0x8,%rcx
  cmp    %ebx,%r15d
  jle    L15
L13:
  movslq %ebx,%rax
  add    %r14,%rax
  mov    %rax,(%rcx)
  cmp    %r15d,%ebx
  jl     L75
L159:
  mov    %ebx,%edx
  add    $0x8,%rcx
  lea    0x1(%rdx),%ebx
  cmp    %ebx,%r15d
  jg     L13
  jmp    L15
  nopl   0x0(%rax)
L141:
  add    $0x1,%eax
  movslq %eax,%r14
  lea    0x0(,%r14,8),%rdi
  mov    %rcx,%r14
  mov    %rdi,0x8(%rsp)
  jmp    L126
  nopl   0x0(%rax,%rax,1)
L27:
  mov    %r15d,%edx
  add    $0x8,%rcx
  lea    0x1(%rdx),%ebx
  cmp    %ebx,%r15d
  jg     L13
  jmp    L15
L121:
  xor    %edx,%edx
  mov    $0x8,%ecx
  mov    $0x1,%eax
  mov    $0xffffffffffffffff,%rsi
  jmp    L208
```

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