user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<getstr>:
  endbr64
  push   %r15
  mov    %rdx,%r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  test   %rsi,%rsi
  sete   %al
  test   %rdx,%rdx
  mov    %r8,0x18(%rsp)
  sete   %dl
  or     %dl,%al
  jne    L45
  mov    %rdi,%r14
  test   %rdi,%rdi
  je     L45
  mov    (%rdi),%r12
  mov    %rsi,%r13
  test   %r12,%r12
  je     L16
  mov    (%rsi),%ebp
L135:
  mov    0x18(%rsp),%rax
  sub    %eax,%ebp
  add    %rax,%r12
  movsbl %cl,%eax
  mov    %eax,0x14(%rsp)
  jmp    L13
  xchg   %ax,%ax
L42:
  mov    D5(%rip),%rax
  cmp    %ebx,(%rax)
  je     L121
L65:
  mov    %r15,%rdi
  mov    %rdx,0x8(%rsp)
  call   <ferror@plt>
  mov    0x8(%rsp),%rdx
  test   %rax,%rax
  jne    L121
  mov    %bl,(%rdx)
  lea    0x1(%rdx),%r12
  sub    $0x1,%ebp
  cmp    %ebx,0x14(%rsp)
  je     L22
L13:
  mov    %r15,%rdi
  call   <getc@plt>
  movslq %ebp,%rdx
  xor    %edi,%edi
  mov    %eax,%ebx
  mov    0x0(%r13),%rax
  sub    %rdx,%rax
  mov    %r12,%rdx
  sub    (%r14),%rdx
  cmp    %rdx,%rax
  sete   %dil
  call   <assert@plt>
  mov    %r12,%rdx
  cmp    $0x1,%ebp
  jg     L42
  mov    0x0(%r13),%rax
  mov    (%r14),%rdi
  cmp    $0x41,%rax
  lea    (%rax,%rax,1),%rcx
  lea    0x40(%rax),%rsi
  cmovae %rcx,%rsi
  mov    %rsi,0x0(%r13)
  lea    (%rdi,%rsi,1),%r12
  sub    %rdx,%r12
  mov    %r12d,%ebp
  call   <realloc@plt>
  mov    %rax,(%r14)
  mov    %rax,%rdx
  test   %rax,%rax
  je     L45
  movslq %r12d,%r12
  mov    $0x1,%edi
  sub    %r12,%rdx
  add    0x0(%r13),%rdx
  mov    %rdx,0x8(%rsp)
  call   <assert@plt>
  mov    D5(%rip),%rax
  mov    0x8(%rsp),%rdx
  cmp    %ebx,(%rax)
  jne    L65
L121:
  cmp    %rdx,(%r14)
  je     L45
L21:
  movb   $0x0,(%rdx)
  mov    0x18(%rsp),%rcx
  mov    %edx,%eax
  add    (%r14),%rcx
  add    $0x28,%rsp
  pop    %rbx
  sub    %ecx,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L22:
  mov    %r12,%rdx
  jmp    L21
  nopl   (%rax)
L16:
  movq   $0x40,(%rsi)
  mov    $0x40,%edi
  mov    %cl,0x8(%rsp)
  call   <malloc@plt>
  mov    %rax,(%r14)
  mov    %rax,%r12
  test   %rax,%rax
  je     L45
  movzbl 0x8(%rsp),%ecx
  mov    $0x40,%ebp
  jmp    L135
  nopw   0x0(%rax,%rax,1)
L45:
  add    $0x28,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, size_t offset) {
  int nchars_avail;
  char *read_pos;
  int ret;
  if (!lineptr || !n || !stream)
    return -1;
  if (!*lineptr) {
    *n = 64;
    *lineptr = malloc(*n);
    if (!*lineptr)
      return -1;
  }
  nchars_avail = *n - offset;
  read_pos = *lineptr + offset;
  for (;;) {
    register int c = getc(stream);
    assert(*n - nchars_avail == read_pos - *lineptr);
    if (nchars_avail < 2) {
      if (*n > 64)
        *n *= 2;
      else
        *n += 64;
      nchars_avail = *n + *lineptr - read_pos;
      *lineptr = realloc(*lineptr, *n);
      if (!*lineptr)
        return -1;
      read_pos = *n - nchars_avail + *lineptr;
      assert(*n - nchars_avail == read_pos - *lineptr);
    }
    if (c == EOF || ferror(stream)) {
      if (read_pos == *lineptr)
        return -1;
      else
        break;
    }
    *read_pos++ = c;
    nchars_avail--;
    if (c == terminator)
      break;
  }
  *read_pos = '\0';
  ret = read_pos - (*lineptr + offset);
  return ret;
}
```