user: What would the C source look like for the assembly code provided here?

```asm
<read_write_test>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x5c8,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x5b8(%rsp)
  xor    %eax,%eax
  mov    D23(%rip),%eax
  lea    0x1(%rax),%edx
  mov    %edx,D7(%rip)
  cmp    $0x1,%eax
  je     L47
  cmp    $0x2,%eax
  je     L169
  test   %eax,%eax
  je     L24
  movl   $0x1,D7(%rip)
L24:
  mov    $0x0,%edx
  mov    $0x3,%esi
  mov    $0x3,%edi
  call   <FS460_image_request_freeze@plt>
L130:
  mov    0x5b8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L94
  add    $0x5c8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L47:
  mov    $0x0,%eax
L34:
  mov    %al,0x10(%rsp,%rax,1)
  add    $0x1,%rax
  cmp    $0x5a0,%rax
  jne    L34
  mov    $0x0,%r13d
  lea    0x10(%rsp),%r12
L45:
  mov    %r13d,%edi
  call   <FS460_image_set_begin_field@plt>
  test   %eax,%eax
  je     L15
L139:
  add    $0x1,%r13d
  cmp    $0x2,%r13d
  jne    L45
  mov    $0x0,%edi
  call   <FS460_image_get_begin_field@plt>
  test   %eax,%eax
  jne    L130
  mov    $0x5a0,%edi
  call   <FS460_image_get_start_read@plt>
  test   %eax,%eax
  jne    L130
  movl   $0x0,0xc(%rsp)
  lea    0xc(%rsp),%rbx
L68:
  mov    %rbx,%rdi
  call   <FS460_image_is_transfer_completed@plt>
  mov    %eax,%ecx
  or     0xc(%rsp),%ecx
  je     L68
  test   %eax,%eax
  jne    L130
  lea    0x10(%rsp),%rdi
  mov    $0x5a0,%esi
  call   <FS460_image_get_finish_read@plt>
  jmp    L130
L15:
  mov    $0xf0,%ebx
  jmp    L179
L109:
  sub    $0x1,%ebx
  je     L139
L179:
  mov    $0x5a0,%esi
  mov    %r12,%rdi
  call   <FS460_image_set_start_write@plt>
  test   %eax,%eax
  jne    L109
  movl   $0x0,0xc(%rsp)
  lea    0xc(%rsp),%rbp
L83:
  mov    %rbp,%rdi
  call   <FS460_image_is_transfer_completed@plt>
  or     0xc(%rsp),%eax
  je     L83
  jmp    L109
L169:
  mov    $0x0,%edx
  mov    $0x3,%esi
  mov    $0x0,%edi
  call   <FS460_image_request_freeze@plt>
  jmp    L130
L94:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void read_write_test(void) {
  static int mode = 0;
  switch (mode++) {
  default:
    mode = 1;
  case 0:
    FS460_image_request_freeze(0x0002 | 0x0001, 0x0002 | 0x0001, 0);
    break;
  case 1: {
    char buf[720 * 2];
    int i, j, field;
    int err, completed;
    for (i = 0; i < sizeof(buf); i++) {
      buf[i] = (char)i;
    }
    for (field = 0; field < 2; field++) {
      err = FS460_image_set_begin_field(field);
      if (!err) {
        for (j = 0; j < 240; j++) {
          err = FS460_image_set_start_write(buf, sizeof(buf));
          if (!err) {
            completed = 0;
            while (!completed && !err)
              err = FS460_image_is_transfer_completed(&completed);
          }
        }
      }
    }
    err = FS460_image_get_begin_field(0);
    if (!err) {
      err = FS460_image_get_start_read(sizeof(buf));
      if (!err) {
        completed = 0;
        while (!completed && !err)
          err = FS460_image_is_transfer_completed(&completed);
        if (!err) {
          err = FS460_image_get_finish_read(buf, sizeof(buf));
          if (!err) {
            {} {}
          }
        }
      }
    }
  } break;
  case 2:
    FS460_image_request_freeze(0, 0x0002 | 0x0001, 0);
    break;
  }
}
```