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

```asm
<nextline>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %rdx,-0x28(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L165
  mov    $0x0,%eax
  jmp    L116
L53:
  addq   $0x1,-0x8(%rbp)
L165:
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L162
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  je     L162
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0xd,%al
  jne    L53
L162:
  mov    -0x8(%rbp),%rax
  sub    -0x28(%rbp),%rax
  add    $0x1,%eax
  mov    %eax,-0xc(%rbp)
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L77
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  jne    L89
  addq   $0x1,-0x8(%rbp)
  jmp    L77
L89:
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0xd,%al
  jne    L77
  mov    -0x8(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  jne    L77
  addq   $0x2,-0x8(%rbp)
L77:
  cmpl   $0x0,-0xc(%rbp)
  jne    L128
  mov    -0x8(%rbp),%rax
  jmp    L116
L128:
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L51
  mov    -0xc(%rbp),%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  mov    %rdx,(%rax)
  jmp    L130
L51:
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  cmp    %rax,%rdx
  jae    L130
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rax
  mov    -0xc(%rbp),%edx
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  mov    %rdx,(%rax)
L130:
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L92
  lea    D9(%rip),%rax
  mov    %rax,%rdi
  call   <debug@plt>
  mov    $0x0,%eax
  jmp    L116
L92:
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rax
  mov    -0xc(%rbp),%edx
  mov    -0x28(%rbp),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  sub    $0x1,%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x8(%rbp),%rax
L116:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_tag: D9
type: string

tool: D9: [nextline] Insufficient memory!


assistant: ```c
const char *nextline(char **lineptr, size_t *n, const char *text) {
  int len;
  const char *to = text;
  if (!*to)
    return NULL;
  while (*to && (*to != '\n') && (*to != '\r'))
    to++;
  len = to - text + 1;
  if (*to) {
    if (*to == '\n')
      to++;
    else if ((*to == '\r') && (*(to + 1) == '\n'))
      to += 2;
  }
  if (!len)
    return to;
  if (!*lineptr) {
    *lineptr = (char *)malloc(len);
    *n = len;
  } else if (*n < len) {
    *lineptr = (char *)realloc(*lineptr, len);
    *n = len;
  }
  if (!*lineptr) {
    debug("[nextline] Insufficient memory!\n");
    return 0;
  }
  memcpy(*lineptr, text, len);
  (*lineptr)[len - 1] = 0;
  return to;
}
```