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

```asm
<realtek_mst_i2c_spi_send_command>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %r8,0x8(%rsp)
  cmp    $0x3,%edx
  ja     L122
  mov    %esi,%r14d
  mov    %edx,%r15d
  mov    %rcx,%rbx
  lea    -0x1(%rsi),%r13d
  cmp    $0x3,%r13d
  ja     L122
  call   <get_fd_from_context@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L211
  lea    0x0(,%r13,8),%eax
  lea    (%r15,%r15,1),%edx
  or     %eax,%edx
  movzbl (%rbx),%eax
  cmp    $0x20,%al
  je     L0
  ja     L238
  cmp    $0x1,%al
  je     L219
  cmp    $0x6,%al
  jne    L10
  mov    $0x0,%ebx
L255:
  mov    %ebx,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L238:
  cmp    $0xc7,%al
  je     L220
  jbe    L169
  add    $0x29,%eax
  cmp    $0x1,%al
  ja     L10
  movl   $0x1,(%rsp)
  jmp    L112
L169:
  cmp    $0x52,%al
  je     L201
  cmp    $0x60,%al
  jne    L10
  movl   $0x1,(%rsp)
L112:
  or     $0xa0,%dl
  mov    %edx,0x4(%rsp)
L218:
  mov    0x4(%rsp),%edx
  mov    $0x60,%esi
  mov    %r12d,%edi
  call   <realtek_mst_i2c_spi_write_register@plt>
  mov    %eax,%ebp
  movzbl (%rbx),%edx
  mov    $0x61,%esi
  mov    %r12d,%edi
  call   <realtek_mst_i2c_spi_write_register@plt>
  or     %eax,%ebp
  test   %r13d,%r13d
  je     L267
  lea    0x1(%rbx),%rax
  lea    -0x2(%r14),%edx
  lea    0x2(%rbx,%rdx,1),%r14
  mov    %rax,%rbx
  mov    $0x64,%r13d
  sub    %eax,%r13d
L123:
  movzbl (%rbx),%edx
  lea    0x0(%r13,%rbx,1),%esi
  mov    %r12d,%edi
  call   <realtek_mst_i2c_spi_write_register@plt>
  or     %eax,%ebp
  add    $0x1,%rbx
  cmp    %r14,%rbx
  jne    L123
L267:
  movzbl 0x4(%rsp),%edx
  or     $0x1,%edx
  movzbl %dl,%edx
  mov    $0x60,%esi
  mov    %r12d,%edi
  call   <realtek_mst_i2c_spi_write_register@plt>
  or     %ebp,%eax
  mov    %eax,%ebx
  jne    L255
  mov    (%rsp),%r8d
  mov    $0x0,%ecx
  mov    $0x1,%edx
  mov    $0x60,%esi
  mov    %r12d,%edi
  call   <realtek_mst_i2c_spi_wait_command_done@plt>
  mov    %eax,%ebx
  test   %eax,%eax
  jne    L255
  test   %r15d,%r15d
  je     L255
  lea    -0x1(%r15),%eax
  mov    0x8(%rsp),%rcx
  lea    0x1(%rcx,%rax,1),%r14
  mov    %rcx,%rbp
  mov    $0x67,%r13d
  sub    %ecx,%r13d
L207:
  lea    0x0(%r13,%rbp,1),%esi
  mov    %rbp,%rdx
  mov    %r12d,%edi
  call   <realtek_mst_i2c_spi_read_register@plt>
  or     %eax,%ebx
  add    $0x1,%rbp
  cmp    %r14,%rbp
  jne    L207
  jmp    L255
L219:
  or     $0x60,%edx
  mov    %edx,0x4(%rsp)
  movl   $0x1,(%rsp)
  jmp    L218
L0:
  movl   $0x1,(%rsp)
  jmp    L112
L220:
  movl   $0x14,(%rsp)
  jmp    L112
L201:
  movl   $0x1,(%rsp)
  jmp    L112
L10:
  or     $0x40,%edx
  mov    %edx,0x4(%rsp)
  movl   $0x1,(%rsp)
  jmp    L218
L122:
  mov    $0xffffffff,%ebx
  jmp    L255
L211:
  mov    $0xffffffff,%ebx
  jmp    L255
```

assistant: ```c
int realtek_mst_i2c_spi_send_command(const struct flashrom_flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) {
  unsigned i;
  int max_timeout_mul = 1;
  int ret = 0;
  if (writecnt > 4 || readcnt > 3 || writecnt == 0) {
    return -1;
  }
  int fd = get_fd_from_context(flash);
  if (fd < 0)
    return -1;
  writecnt--;
  uint8_t ctrl_reg_val = (writecnt << 3) | (readcnt << 1);
  switch (writearr[0]) {
  case 0x06:
    return 0;
  case 0x01:
    ctrl_reg_val |= (1 << 5);
    ctrl_reg_val |= (2 << 5);
    break;
  case 0xc7:
    max_timeout_mul *= 20;
  case 0x60:
  case 0x52:
  case 0xd8:
  case 0xd7:
  case 0x20:
    ctrl_reg_val |= (1 << 5);
    ctrl_reg_val |= (4 << 5);
    break;
  default:
    ctrl_reg_val |= (2 << 5);
  }
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x60, ctrl_reg_val);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x61, writearr[0]);
  for (i = 0; i < writecnt; ++i)
    ret |= realtek_mst_i2c_spi_write_register(fd, 0x64 + i, writearr[i + 1]);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x60, ctrl_reg_val | 0x1);
  if (ret)
    return ret;
  ret = realtek_mst_i2c_spi_wait_command_done(fd, 0x60, 0x01, 0, max_timeout_mul);
  if (ret)
    return ret;
  for (i = 0; i < readcnt; ++i)
    ret |= realtek_mst_i2c_spi_read_register(fd, 0x67 + i, &readarr[i]);
  return ret;
}
```