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

```asm
<fd_readline>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %edi,-0x24(%rbp)
  mov    %esi,-0x28(%rbp)
  mov    %rdx,-0x30(%rbp)
  mov    %ecx,-0x34(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x34(%rbp),%eax
  cltq
  lea    -0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x10(%rbp)
L198:
  lea    -0x1d(%rbp),%rcx
  mov    -0x24(%rbp),%eax
  mov    $0x1,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %eax,-0x1c(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  jg     L4
  movl   $0xffffffff,-0x1c(%rbp)
  jmp    L47
L4:
  movzbl -0x1d(%rbp),%eax
  movzbl %al,%eax
  cmp    $0x7f,%eax
  je     L11
  cmp    $0x7f,%eax
  jg     L94
  cmp    $0xd,%eax
  je     L43
  cmp    $0xd,%eax
  jg     L94
  cmp    $0x3,%eax
  je     L65
  cmp    $0x8,%eax
  jne    L94
L11:
  mov    -0x18(%rbp),%rax
  cmp    -0x30(%rbp),%rax
  jbe    L115
  subq   $0x1,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <isprint@plt>
  test   %eax,%eax
  je     L135
  mov    -0x28(%rbp),%eax
  mov    %eax,%edi
  call   <cdel@plt>
  jmp    L157
L135:
  mov    -0x28(%rbp),%eax
  mov    %eax,%edi
  call   <xdel@plt>
  jmp    L157
L115:
  mov    -0x28(%rbp),%eax
  mov    $0x7,%esi
  mov    %eax,%edi
  call   <cput@plt>
  jmp    L157
L65:
  movl   $0xffffffff,-0x1c(%rbp)
  mov    D14(%rip),%rax
  mov    (%rax),%edx
  mov    D17(%rip),%rax
  mov    %edx,(%rax)
  jmp    L47
L43:
  mov    -0x18(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x18(%rbp),%rax
  sub    -0x30(%rbp),%rax
  mov    %eax,-0x1c(%rbp)
  jmp    L47
L94:
  mov    -0x18(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  jae    L110
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl -0x1d(%rbp),%edx
  mov    %dl,(%rax)
  movzbl -0x1d(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <isprint@plt>
  test   %eax,%eax
  je     L98
  movzbl -0x1d(%rbp),%eax
  movsbl %al,%edx
  mov    -0x28(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <cput@plt>
  jmp    L143
L98:
  movzbl -0x1d(%rbp),%eax
  movzbl %al,%edx
  mov    -0x28(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <xput@plt>
  jmp    L143
L110:
  mov    -0x28(%rbp),%eax
  mov    $0x7,%esi
  mov    %eax,%edi
  call   <cput@plt>
L143:
  nop
L157:
  jmp    L198
L47:
  mov    -0x1c(%rbp),%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L132
  call   <__stack_chk_fail@plt>
L132:
  leave
  ret
```

assistant: ```c
int fd_readline(int fdi, int fdo, char *b, int bsz) {
  int r;
  unsigned char c;
  unsigned char *bp, *bpe;
  bp = (unsigned char *)b;
  bpe = (unsigned char *)b + bsz - 1;
  while (1) {
    r = read(fdi, &c, 1);
    if (r <= 0) {
      r = -1;
      goto out;
    }
    switch (c) {
    case '\b':
    case '\x7f':
      if (bp > (unsigned char *)b) {
        bp--;
        if (isprint(*bp))
          cdel(fdo);
        else
          xdel(fdo);
      } else {
        cput(fdo, '\x07');
      }
      break;
    case '\x03':
      r = -1;
      errno = EINTR;
      goto out;
    case '\r':
      *bp = '\0';
      r = bp - (unsigned char *)b;
      goto out;
    default:
      if (bp < bpe) {
        *bp++ = c;
        if (isprint(c))
          cput(fdo, c);
        else
          xput(fdo, c);
      } else {
        cput(fdo, '\x07');
      }
      break;
    }
  }
out:
  return r;
}
```