user: 请将以下的汇编代码转换成C语言代码：

```asm
<vectorio_buffer>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %edi,%r14d
  mov    %rsi,%rbp
  mov    %edx,%r15d
  mov    %edx,0xc(%rsp)
  mov    %ecx,%ebx
  mov    %r8d,%r12d
  mov    %r8d,%edi
  call   <malloc@plt>
  test   %rax,%rax
  je     L42
  mov    %rax,%r13
  cmp    $0x1,%ebx
  je     L87
  cmp    $0x2,%ebx
  jne    L10
  test   %r15d,%r15d
  jle    L86
  mov    %rbp,%rbx
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%eax
  shl    $0x4,%rax
  lea    0x10(%rbp,%rax,1),%r15
  mov    $0x0,%ebp
L98:
  mov    0x8(%rbx),%rsi
  movslq %ebp,%rdi
  add    %r13,%rdi
  mov    (%rbx),%edx
  call   <memcpy@plt>
  add    (%rbx),%ebp
  add    $0x10,%rbx
  cmp    %r15,%rbx
  jne    L98
L115:
  cmp    %ebp,%r12d
  sete   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    %r12d,%edx
  mov    %r13,%rsi
  mov    %r14d,%edi
  call   <write@plt>
  mov    %eax,%r14d
  jmp    L48
L86:
  mov    $0x0,%ebp
  jmp    L115
L87:
  mov    %r12d,%edx
  mov    %rax,%rsi
  mov    %r14d,%edi
  call   <read@plt>
  mov    %eax,%r14d
  test   %eax,%eax
  jle    L62
  mov    $0x0,%r12d
  mov    $0x0,%r15d
L47:
  cmp    %r15d,0xc(%rsp)
  setg   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    %r14d,%ebx
  sub    %r12d,%ebx
  mov    0x0(%rbp),%eax
  cmp    %eax,%ebx
  cmovg  %eax,%ebx
  add    $0x1,%r15d
  movslq %r12d,%rsi
  add    %r13,%rsi
  mov    0x8(%rbp),%rdi
  mov    %ebx,%edx
  call   <memcpy@plt>
  add    %ebx,%r12d
  add    $0x10,%rbp
  cmp    %r12d,%r14d
  jg     L47
L3:
  mov    %r14d,%eax
  shr    $0x1f,%eax
  cmp    %r12d,%r14d
  sete   %dil
  movzbl %dil,%edi
  or     %eax,%edi
  call   <assert@plt>
L48:
  mov    D11(%rip),%rbx
  mov    (%rbx),%ebp
  mov    %r13,%rdi
  call   <free@plt>
  mov    %ebp,(%rbx)
L84:
  mov    %r14d,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L62:
  mov    $0x0,%r12d
  jmp    L3
L10:
  mov    $0x0,%edi
  call   <assert@plt>
  mov    D14(%rip),%rax
  mov    (%rax),%edx
  mov    D11(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r14d
  jmp    L48
L42:
  mov    $0xffffffff,%r14d
  jmp    L84
```

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;
}
```