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

```asm
<vectorio_buffer>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %edi,-0x24(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %edx,-0x28(%rbp)
  mov    %ecx,-0x34(%rbp)
  mov    %r8d,-0x38(%rbp)
  mov    -0x38(%rbp),%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x8(%rbp)
  cmpq   $0x0,-0x8(%rbp)
  jne    L79
  mov    $0xffffffff,%eax
  jmp    L135
L79:
  cmpl   $0x1,-0x34(%rbp)
  je     L63
  cmpl   $0x2,-0x34(%rbp)
  je     L41
  jmp    L36
L63:
  mov    -0x38(%rbp),%edx
  mov    -0x8(%rbp),%rcx
  mov    -0x24(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %eax,-0x14(%rbp)
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x1c(%rbp)
  jmp    L31
L83:
  mov    -0x1c(%rbp),%eax
  cmp    -0x28(%rbp),%eax
  setl   %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x4,%rax
  mov    %rax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x14(%rbp),%eax
  sub    -0x18(%rbp),%eax
  cmp    %eax,%edx
  cmovle %edx,%eax
  mov    %eax,-0x10(%rbp)
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x8(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  shl    $0x4,%rax
  mov    %rax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    0x8(%rax),%rax
  mov    -0x10(%rbp),%edx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x10(%rbp),%eax
  add    %eax,-0x18(%rbp)
L31:
  mov    -0x18(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L83
  cmpl   $0x0,-0x14(%rbp)
  js     L13
  mov    -0x14(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jne    L8
L13:
  mov    $0x1,%eax
  jmp    L136
L8:
  mov    $0x0,%eax
L136:
  mov    %eax,%edi
  call   <assert@plt>
  jmp    L137
L41:
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x1c(%rbp)
  jmp    L51
L113:
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x4,%rax
  mov    %rax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x4,%rax
  mov    %rax,%rcx
  mov    -0x30(%rbp),%rax
  add    %rcx,%rax
  mov    0x8(%rax),%rax
  mov    -0x18(%rbp),%ecx
  movslq %ecx,%rsi
  mov    -0x8(%rbp),%rcx
  add    %rsi,%rcx
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x4,%rax
  mov    %rax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  add    %eax,-0x18(%rbp)
  addl   $0x1,-0x1c(%rbp)
L51:
  mov    -0x1c(%rbp),%eax
  cmp    -0x28(%rbp),%eax
  jl     L113
  mov    -0x18(%rbp),%eax
  cmp    -0x38(%rbp),%eax
  sete   %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  mov    -0x38(%rbp),%edx
  mov    -0x8(%rbp),%rcx
  mov    -0x24(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <write@plt>
  mov    %eax,-0x14(%rbp)
  jmp    L137
L36:
  mov    $0x0,%edi
  call   <assert@plt>
  mov    D32(%rip),%rax
  mov    (%rax),%edx
  mov    D4(%rip),%rax
  mov    %edx,(%rax)
  movl   $0xffffffff,-0x14(%rbp)
L137:
  mov    D4(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0xc(%rbp)
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    D4(%rip),%rax
  mov    -0xc(%rbp),%edx
  mov    %edx,(%rax)
  mov    -0x14(%rbp),%eax
L135:
  leave
  ret
```

assistant: ```c
ssize_t vectorio_buffer(int fildes, const struct iovec *iov, int iovcnt, int readwrite, ssize_t totallen) {
  char *buffer;
  int iovidx, errno_saved;
  ssize_t copied, len, r;
  buffer = (char *)malloc(totallen);
  if (!buffer)
    return -1;
  switch (readwrite) {
  case 1:
    r = read(fildes, buffer, totallen);
    copied = 0;
    iovidx = 0;
    while (copied < r) {
      assert(iovidx < iovcnt);
      len = (((r - copied) < (iov[iovidx].iov_len)) ? (r - copied) : (iov[iovidx].iov_len));
      memcpy(iov[iovidx++].iov_base, buffer + copied, len);
      copied += len;
    }
    assert(r < 0 || r == copied);
    break;
  case 2:
    copied = 0;
    for (iovidx = 0; iovidx < iovcnt; iovidx++) {
      memcpy(buffer + copied, iov[iovidx].iov_base, iov[iovidx].iov_len);
      copied += iov[iovidx].iov_len;
    }
    assert(copied == totallen);
    r = write(fildes, buffer, totallen);
    break;
  default:
    assert(0);
    errno = EINVAL;
    r = -1;
  }
  errno_saved = errno;
  free(buffer);
  errno = errno_saved;
  return r;
}
```