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

```asm
<flash_ext4_kernel>:
  endbr64
  push   %r15
  mov    %rdi,%r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rsi,%r12
  lea    D31(%rip),%rsi
  push   %rbp
  mov    %r12,%rdi
  push   %rbx
  sub    $0x238,%rsp
  mov    %rdx,0x8(%rsp)
  mov    %r8d,0x14(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x228(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  test   %rax,%rax
  je     L23
  lea    D15(%rip),%rsi
  mov    %r15,%rdi
  mov    %rax,%rbp
  call   <fopen@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L128
  lea    D49(%rip),%rdi
  xor    %r15d,%r15d
  lea    0x20(%rsp),%r12
  xor    %ebx,%ebx
  call   <set_step@plt>
  nopl   0x0(%rax)
L46:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L0
  mov    %rbp,%rcx
  mov    $0x200,%edx
  mov    $0x1,%esi
  mov    %r12,%rdi
  call   <fread@plt>
  mov    %eax,%r13d
  test   %eax,%eax
  je     L115
  cltq
  add    %rax,%rbx
  lea    (%rbx,%rbx,4),%rax
  lea    (%rax,%rax,4),%rax
  shl    $0x2,%rax
  cqto
  idivq  0x8(%rsp)
  mov    %eax,%edi
  cmp    %eax,%r15d
  jl     L9
L87:
  mov    0x14(%rsp),%eax
  test   %eax,%eax
  jne    L46
  mov    %r14,%rcx
  mov    $0x1,%edx
  mov    %r13d,%esi
  mov    %r12,%rdi
  call   <fwrite@plt>
  cmp    $0x1,%eax
  je     L46
  lea    D41(%rip),%rdi
  xor    %eax,%eax
  xor    %r13d,%r13d
  call   <my_printf@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r14,%rdi
  call   <fclose@plt>
  jmp    L35
  nopl   0x0(%rax,%rax,1)
L115:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L46
  lea    D19(%rip),%rdi
  call   <my_printf@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r14,%rdi
  call   <fclose@plt>
L35:
  mov    0x228(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L97
  add    $0x238,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L9:
  mov    %rax,0x18(%rsp)
  call   <set_step_progress@plt>
  mov    0x18(%rsp),%rcx
  mov    %ecx,%r15d
  jmp    L87
  nopw   0x0(%rax,%rax,1)
L23:
  mov    %r12,%rsi
  lea    D48(%rip),%rdi
  xor    %eax,%eax
  xor    %r13d,%r13d
  call   <my_printf@plt>
  jmp    L35
  cs nopw 0x0(%rax,%rax,1)
L0:
  mov    %rbp,%rdi
  mov    $0x1,%r13d
  call   <fclose@plt>
  mov    %r14,%rdi
  call   <fclose@plt>
  jmp    L35
  nopl   0x0(%rax,%rax,1)
L128:
  mov    %r15,%rsi
  lea    D24(%rip),%rdi
  xor    %eax,%eax
  xor    %r13d,%r13d
  call   <my_printf@plt>
  jmp    L35
L97:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D31
datatype: string
name: extract_symbolic_data
arguments: label: D15
datatype: string
name: extract_symbolic_data
arguments: label: D49
datatype: string
name: extract_symbolic_data
arguments: label: D41
datatype: string
name: extract_symbolic_data
arguments: label: D19
datatype: string
name: extract_symbolic_data
arguments: label: D48
datatype: string
name: extract_symbolic_data
arguments: label: D24
datatype: string

tool: D31: rb

tool: D15: wb

tool: D49: Writing ext4 kernel

tool: D41: Error writing kernel file to kernel device.


tool: D19: Error reading kernel file.


tool: D48: Error while opening kernel file %s


tool: D24: Error while opening kernel device %s


assistant: ```c
int flash_ext4_kernel(char *device, char *filename, off_t kernel_file_size, int quiet, int no_write) {
  char buffer[512];
  FILE *kernel_file;
  kernel_file = fopen(filename, "rb");
  if (kernel_file == NULL) {
    my_printf("Error while opening kernel file %s\n", filename);
    return 0;
  }
  FILE *kernel_dev;
  kernel_dev = fopen(device, "wb");
  if (kernel_dev == NULL) {
    my_printf("Error while opening kernel device %s\n", device);
    return 0;
  }
  set_step("Writing ext4 kernel");
  int ret;
  long long readBytes = 0;
  int current_percent = 0;
  int new_percent = 0;
  while (!feof(kernel_file)) {
    ret = fread(buffer, 1, sizeof(buffer), kernel_file);
    if (ret == 0) {
      if (feof(kernel_file))
        continue;
      my_printf("Error reading kernel file.\n");
      fclose(kernel_file);
      fclose(kernel_dev);
      return 0;
    }
    readBytes += ret;
    new_percent = readBytes * 100 / kernel_file_size;
    if (current_percent < new_percent) {
      set_step_progress(new_percent);
      current_percent = new_percent;
    }
    if (!no_write) {
      ret = fwrite(buffer, ret, 1, kernel_dev);
      if (ret != 1) {
        my_printf("Error writing kernel file to kernel device.\n");
        fclose(kernel_file);
        fclose(kernel_dev);
        return 0;
      }
    }
  }
  fclose(kernel_file);
  fclose(kernel_dev);
  return 1;
}
```