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

```asm
<pd_getline>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %rdi,%r12
  mov    $0x400,%edi
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %esi,0x20(%rsp)
  mov    %r8,0x8(%rsp)
  mov    %r9,0x18(%rsp)
  call   <malloc@plt>
  mov    0x78(%rsp),%rcx
  mov    %rax,(%rcx)
  test   %rax,%rax
  je     L124
  movb   $0x0,(%rax)
  mov    0x20(%rsp),%eax
  mov    $0x400,%r15d
  xor    %r14d,%r14d
  mov    0x0(%rbp),%ebx
  sub    $0x1,%eax
  mov    %eax,0x20(%rsp)
  jmp    L53
L16:
  movl   $0x0,0x0(%rbp)
  mov    0x88(%rsp),%r8d
  mov    %r12,%rsi
  mov    0x80(%rsp),%rcx
  mov    0x20(%rsp),%edx
  mov    0x70(%rsp),%edi
  mov    0x8(%rsp),%rax
  call   *%rax
  mov    %eax,0x0(%r13)
  test   %eax,%eax
  jle    L118
  cltq
  movb   $0x0,(%r12,%rax,1)
  mov    0x0(%rbp),%ebx
L53:
  cmp    %ebx,0x0(%r13)
  jle    L16
  movslq %ebx,%rdi
  mov    $0xa,%esi
  add    %r12,%rdi
  call   <strchr@plt>
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  je     L54
  mov    0x10(%rsp),%rcx
  mov    $0x1,%eax
  sub    0x0(%rbp),%eax
  mov    %rcx,%rdx
  movb   $0x0,(%rcx)
  sub    %r12,%rdx
  lea    (%rax,%rdx,1),%ebx
  mov    %ebx,0x24(%rsp)
L49:
  mov    0x78(%rsp),%rax
  mov    (%rax),%rdi
  mov    %r15d,%eax
  sub    %r14d,%eax
  cmp    %ebx,%eax
  jge    L4
  mov    %r12,0x28(%rsp)
  mov    %r15d,%r12d
  mov    %r13,%r15
  mov    %rbp,%r13
  mov    0x78(%rsp),%rbp
  jmp    L48
  nopl   0x0(%rax,%rax,1)
L140:
  mov    %rax,0x0(%rbp)
  mov    %r12d,%eax
  sub    %r14d,%eax
  cmp    %ebx,%eax
  jge    L151
L48:
  add    %r12d,%r12d
  mov    %r12d,%esi
  call   <realloc@plt>
  mov    %rax,%rdi
  test   %rax,%rax
  jne    L140
L118:
  mov    0x78(%rsp),%rax
  mov    (%rax),%rdi
  call   <free@plt>
  mov    0x78(%rsp),%rax
  cmpq   $0x0,0x18(%rsp)
  movq   $0x0,(%rax)
  je     L92
L64:
  mov    0x88(%rsp),%edx
  mov    0x80(%rsp),%rsi
  mov    0x70(%rsp),%edi
  mov    0x18(%rsp),%rax
  call   *%rax
  xor    %eax,%eax
L107:
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L151:
  mov    %r13,%rbp
  mov    %r15,%r13
  mov    %r12d,%r15d
  mov    0x28(%rsp),%r12
L4:
  mov    0x24(%rsp),%ebx
  movslq 0x0(%rbp),%rsi
  movslq %r14d,%rax
  add    %rax,%rdi
  add    %r12,%rsi
  mov    %ebx,%edx
  add    %ebx,%r14d
  call   <memcpy@plt>
  add    0x0(%rbp),%ebx
  cmpq   $0x0,0x10(%rsp)
  mov    %ebx,0x0(%rbp)
  je     L53
  mov    0x78(%rsp),%rax
  mov    $0xd,%esi
  mov    (%rax),%rdi
  call   <strchr@plt>
  test   %rax,%rax
  je     L62
  movb   $0x0,(%rax)
L62:
  movslq 0x0(%rbp),%rcx
  mov    $0x1,%eax
  cmpb   $0x0,(%r12,%rcx,1)
  mov    %rcx,%rdx
  jne    L107
  add    $0x1,%edx
  mov    %edx,0x0(%rbp)
  jmp    L107
  nopl   0x0(%rax,%rax,1)
L124:
  cmpq   $0x0,0x18(%rsp)
  jne    L64
L92:
  add    $0x38,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L54:
  movslq 0x0(%rbp),%rax
  mov    0x0(%r13),%edx
  xor    %esi,%esi
  sub    %eax,%edx
  lea    (%r12,%rax,1),%rdi
  call   <memchr@plt>
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  je     L114
  mov    0x10(%rsp),%rdx
  mov    $0x1,%eax
  sub    0x0(%rbp),%eax
  sub    %r12,%rdx
  add    %edx,%eax
  mov    %eax,0x24(%rsp)
  mov    %eax,%ebx
  jmp    L49
L114:
  mov    0x0(%r13),%ebx
  sub    0x0(%rbp),%ebx
  mov    %ebx,0x24(%rsp)
  jmp    L49
```

assistant: ```c
int pd_getline(char *buf, unsigned int bufsize, int *bufcur, int *buflen, int (*readfunc)(int, void *, unsigned int, char *, int), int (*closefunc)(int, char *, int), int readfd, char **line, char *errdesc, int errlen) {
  char *eol;
  unsigned int srcsize;
  int linelen;
  int linesize = 1024;
  linelen = 0;
  if (!(*line = malloc(linesize))) {
    if (closefunc)
      (void)closefunc(readfd, errdesc, errlen);
    return 0;
  }
  **line = 0;
top:
  while (*bufcur < *buflen) {
    if (!(eol = strchr(buf + *bufcur, '\n'))) {
      if (!(eol = memchr(buf + *bufcur, '\0', *buflen - *bufcur))) {
        srcsize = *buflen - *bufcur;
      } else {
        srcsize = eol - buf - *bufcur + 1;
      }
    } else {
      srcsize = eol - buf - *bufcur + 1;
      *eol = 0;
    }
    while ((int)srcsize > (linesize - linelen)) {
      char *newline;
      linesize *= 2;
      if ((newline = realloc(*line, linesize)) == NULL) {
        free(*line);
        *line = NULL;
        *line = NULL;
        if (closefunc)
          (void)closefunc(readfd, errdesc, errlen);
        return 0;
      }
      *line = newline;
    }
    memcpy(*line + linelen, buf + *bufcur, srcsize);
    linelen += srcsize;
    *bufcur += srcsize;
    if (eol) {
      if ((eol = strchr(*line, '\r')) != NULL)
        *eol = 0;
      if (!buf[*bufcur])
        (*bufcur)++;
      return 1;
    }
  }
  *bufcur = 0;
  if ((*buflen = readfunc(readfd, buf, bufsize - 1, errdesc, errlen)) <= 0) {
    free(*line);
    *line = NULL;
    *line = NULL;
    if (closefunc)
      (void)closefunc(readfd, errdesc, errlen);
    return 0;
  }
  buf[*buflen] = 0;
  goto top;
}
```