user: What is the c source code of the assembly code below?

```asm
<flash_ext4_kernel>:
  endbr64
  push   %r15
  mov    %r8d,%r15d
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  mov    %rsi,%r12
  lea    D2(%rip),%rsi
  push   %rbp
  mov    %r12,%rdi
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x228,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x218(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  test   %rax,%rax
  je     L136
  lea    D30(%rip),%rsi
  mov    %r14,%rdi
  mov    %rax,%rbp
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L48
  lea    D20(%rip),%rdi
  mov    $0x0,%r12d
  lea    0x10(%rsp),%r14
  call   <set_step@plt>
  test   %r15d,%r15d
  mov    $0x0,%r15d
  je     L57
L91:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L8
L154:
  mov    %rbp,%rcx
  mov    $0x200,%edx
  mov    $0x1,%esi
  mov    %r14,%rdi
  call   <fread@plt>
  test   %eax,%eax
  je     L124
  cltq
  add    %rax,%r12
  lea    (%r12,%r12,4),%rax
  lea    (%rax,%rax,4),%rax
  shl    $0x2,%rax
  cqto
  idiv   %rbx
  mov    %eax,%edi
  cmp    %eax,%r15d
  jge    L91
  mov    %rax,(%rsp)
  call   <set_step_progress@plt>
  mov    (%rsp),%rcx
  mov    %rbp,%rdi
  mov    %ecx,%r15d
  call   <feof@plt>
  test   %rax,%rax
  je     L154
  nopl   0x0(%rax)
L8:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r13,%rdi
  call   <fclose@plt>
  mov    $0x1,%eax
  jmp    L173
  nopw   0x0(%rax,%rax,1)
L126:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  je     L13
L57:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L8
  mov    $0x1,%esi
  mov    %rbp,%rcx
  mov    $0x200,%edx
  mov    %r14,%rdi
  call   <fread@plt>
  mov    %eax,%esi
  test   %eax,%eax
  je     L126
  cltq
  add    %rax,%r12
  lea    (%r12,%r12,4),%rax
  lea    (%rax,%rax,4),%rax
  shl    $0x2,%rax
  cqto
  idiv   %rbx
  mov    %eax,%edi
  cmp    %eax,%r15d
  jl     L157
L149:
  mov    %r13,%rcx
  mov    $0x1,%edx
  mov    %r14,%rdi
  call   <fwrite@plt>
  cmp    $0x1,%eax
  je     L57
  lea    D61(%rip),%rdi
  jmp    L11
  nopl   0x0(%rax)
L124:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L91
L13:
  lea    D28(%rip),%rdi
L11:
  xor    %eax,%eax
  call   <my_printf@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r13,%rdi
  call   <fclose@plt>
  xor    %eax,%eax
L173:
  mov    0x218(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L66
  add    $0x228,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L157:
  mov    %esi,(%rsp)
  mov    %rax,0x8(%rsp)
  call   <set_step_progress@plt>
  mov    0x8(%rsp),%rcx
  mov    (%rsp),%esi
  mov    %ecx,%r15d
  jmp    L149
  nopl   (%rax)
L136:
  mov    %r12,%rsi
  lea    D56(%rip),%rdi
  xor    %eax,%eax
  call   <my_printf@plt>
  xor    %eax,%eax
  jmp    L173
  nopl   (%rax)
L48:
  mov    %r14,%rsi
  lea    D47(%rip),%rdi
  xor    %eax,%eax
  call   <my_printf@plt>
  xor    %eax,%eax
  jmp    L173
L66:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: tag: D2
data_type: string
name: retrieve_data
arguments: tag: D30
data_type: string
name: retrieve_data
arguments: tag: D20
data_type: string
name: retrieve_data
arguments: tag: D61
data_type: string
name: retrieve_data
arguments: tag: D28
data_type: string
name: retrieve_data
arguments: tag: D56
data_type: string
name: retrieve_data
arguments: tag: D47
data_type: string

tool: D2: rb

tool: D30: wb

tool: D20: Writing ext4 kernel

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


tool: D28: Error reading kernel file.


tool: D56: Error while opening kernel file %s


tool: D47: 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;
}
```