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

```asm
<write_fram>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x5e0,%rsp
  mov    %edi,-0x5d4(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0x5c0(%rbp),%rax
  mov    %rax,%rdi
  call   <FS460_get_tv_active_lines@plt>
  movl   $0x0,-0x5b4(%rbp)
  jmp    L53
L168:
  movl   $0x0,-0x5bc(%rbp)
  jmp    L18
L30:
  mov    -0x5bc(%rbp),%eax
  cltq
  movb   $0x80,-0x5b0(%rbp,%rax,1)
  mov    -0x5b4(%rbp),%eax
  cmp    -0x5d4(%rbp),%eax
  je     L144
  mov    $0xffffff80,%edx
  jmp    L95
L144:
  mov    $0x10,%edx
L95:
  mov    -0x5bc(%rbp),%eax
  add    $0x1,%eax
  cltq
  mov    %dl,-0x5b0(%rbp,%rax,1)
  addl   $0x2,-0x5bc(%rbp)
L18:
  mov    -0x5bc(%rbp),%eax
  cmp    $0x59f,%eax
  jbe    L30
  mov    -0x5b4(%rbp),%eax
  mov    %eax,%edi
  call   <FS460_image_set_begin_field@plt>
  movl   $0x0,-0x5b8(%rbp)
  jmp    L169
L92:
  lea    -0x5b0(%rbp),%rax
  mov    $0x5a0,%esi
  mov    %rax,%rdi
  call   <FS460_image_set_start_write@plt>
  movl   $0x0,-0x5c4(%rbp)
  jmp    L51
L117:
  lea    -0x5c4(%rbp),%rax
  mov    %rax,%rdi
  call   <FS460_image_is_transfer_completed@plt>
L51:
  mov    -0x5c4(%rbp),%eax
  test   %eax,%eax
  je     L117
  addl   $0x1,-0x5b8(%rbp)
L169:
  mov    -0x5c0(%rbp),%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  cmp    %eax,-0x5b8(%rbp)
  jl     L92
  jmp    L64
L135:
  movl   $0x0,-0x5bc(%rbp)
  jmp    L127
L58:
  mov    -0x5bc(%rbp),%eax
  cltq
  movb   $0x80,-0x5b0(%rbp,%rax,1)
  mov    -0x5bc(%rbp),%eax
  add    $0x1,%eax
  cltq
  movb   $0x10,-0x5b0(%rbp,%rax,1)
  addl   $0x2,-0x5bc(%rbp)
L127:
  mov    -0x5bc(%rbp),%eax
  cmp    $0x59f,%eax
  jbe    L58
  lea    -0x5b0(%rbp),%rax
  mov    $0x5a0,%esi
  mov    %rax,%rdi
  call   <FS460_image_set_start_write@plt>
  movl   $0x0,-0x5c4(%rbp)
  jmp    L42
L65:
  lea    -0x5c4(%rbp),%rax
  mov    %rax,%rdi
  call   <FS460_image_is_transfer_completed@plt>
L42:
  mov    -0x5c4(%rbp),%eax
  test   %eax,%eax
  je     L65
  addl   $0x1,-0x5b8(%rbp)
L64:
  mov    -0x5c0(%rbp),%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  cmp    %eax,-0x5b8(%rbp)
  jl     L135
  addl   $0x1,-0x5b4(%rbp)
L53:
  cmpl   $0x1,-0x5b4(%rbp)
  jle    L168
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L27
  call   <__stack_chk_fail@plt>
L27:
  leave
  ret
```

assistant: ```c
void write_fram(int toggle) {
  char buf[720 * 2];
  int i, j, field;
  int completed;
  int full_height;
  FS460_get_tv_active_lines(&full_height);
  for (field = 0; field < 2; field++) {
    for (i = 0; i < sizeof(buf); i += 2) {
      buf[i] = (char)0x80;
      buf[i + 1] = ((field ^ toggle) ? (char)0x80 : (char)0x10);
    }
    FS460_image_set_begin_field(field);
    for (j = 0; j < full_height / 2; j++) {
      FS460_image_set_start_write(buf, sizeof(buf));
      completed = 0;
      while (!completed)
        FS460_image_is_transfer_completed(&completed);
    }
    for (; j < full_height / 2; j++) {
      for (i = 0; i < sizeof(buf); i += 2) {
        buf[i] = (char)0x80;
        buf[i + 1] = (char)0x10;
      }
      FS460_image_set_start_write(buf, sizeof(buf));
      completed = 0;
      while (!completed)
        FS460_image_is_transfer_completed(&completed);
    }
  }
}
```