user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<WriteBMP32>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rsi,(%rsp)
  mov    %edx,%r15d
  mov    %edx,0x8(%rsp)
  mov    %ecx,%r14d
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  lea    D9(%rip),%rsi
  call   <fopen@plt>
  test   %rax,%rax
  je     L24
  mov    %rax,%rbp
  mov    %r15d,%r12d
  imul   %r14d,%r12d
  shl    $0x2,%r12d
  lea    0x10(%rsp),%rbx
  mov    $0xe,%edx
  mov    $0x0,%esi
  mov    %rbx,%rdi
  call   <memset@plt>
  movb   $0x42,0x10(%rsp)
  movb   $0x4d,0x11(%rsp)
  lea    0x12(%rsp),%rdx
  lea    0x36(%r12),%edi
  mov    $0x1,%ecx
  mov    $0x4,%esi
  call   <bwrite_endian@plt>
  lea    0x16(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x0,%edi
  call   <bwrite_endian@plt>
  lea    0x1a(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x36,%edi
  call   <bwrite_endian@plt>
  mov    %rbp,%rcx
  mov    $0xe,%edx
  mov    $0x1,%esi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  mov    $0x28,%edx
  mov    $0x0,%esi
  mov    %rbx,%rdi
  call   <memset@plt>
  mov    $0x1,%ecx
  mov    %rbx,%rdx
  mov    $0x4,%esi
  mov    $0x28,%edi
  call   <bwrite_endian@plt>
  lea    0x14(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    %r15d,%edi
  call   <bwrite_endian@plt>
  lea    0x18(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    %r14d,%edi
  call   <bwrite_endian@plt>
  lea    0x1c(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x2,%esi
  mov    $0x1,%edi
  call   <bwrite_endian@plt>
  lea    0x1e(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x2,%esi
  mov    $0x20,%edi
  call   <bwrite_endian@plt>
  lea    0x20(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x0,%edi
  call   <bwrite_endian@plt>
  lea    0x24(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    %r12d,%edi
  call   <bwrite_endian@plt>
  lea    0x28(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x10000,%edi
  call   <bwrite_endian@plt>
  lea    0x2c(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x10000,%edi
  call   <bwrite_endian@plt>
  lea    0x30(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x1000000,%edi
  call   <bwrite_endian@plt>
  lea    0x34(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x0,%edi
  call   <bwrite_endian@plt>
  mov    %rbp,%rcx
  mov    $0x28,%edx
  mov    $0x1,%esi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  movb   $0x0,0x10(%rsp)
  sub    $0x1,%r14d
  js     L5
  mov    %r15d,%eax
  imul   %r14d,%r15d
  sub    $0x1,%eax
  mov    %eax,0xc(%rsp)
  jmp    L35
L80:
  movslq %r15d,%rdx
  lea    0x2(%rdx,%rdx,2),%rbx
  mov    (%rsp),%rcx
  add    %rcx,%rbx
  mov    0xc(%rsp),%eax
  add    %rdx,%rax
  lea    (%rax,%rax,2),%rax
  lea    0x5(%rcx,%rax,1),%r13
  lea    0x10(%rsp),%r12
L60:
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  lea    -0x1(%rbx),%rdi
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  lea    -0x2(%rbx),%rdi
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %r12,%rdi
  call   <fwrite@plt>
  add    $0x3,%rbx
  cmp    %r13,%rbx
  jne    L60
L33:
  sub    $0x1,%r14d
  sub    0x8(%rsp),%r15d
  cmp    $0xffffffff,%r14d
  je     L5
L35:
  cmpl   $0x0,0x8(%rsp)
  jg     L80
  jmp    L33
L5:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    $0x0,%eax
L58:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L3
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L24:
  mov    $0xffffffff,%eax
  jmp    L58
L3:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D9
type_infered: string

tool: D9: wb

assistant: ```c
int WriteBMP32(const char *fname, unsigned char (*data)[3], int w, int h) {
  FILE *fp = fopen(fname, "wb");
  int Endian = 1;
  unsigned char buffer[40];
  ulong fileSize;
  ulong imageSize;
  int x, y;
  if (!fp)
    return -1;
  imageSize = 4 * w * h;
  fileSize = 14 + 40 + imageSize;
  memset(buffer, 0x00, 14);
  buffer[0] = 66;
  buffer[1] = 77;
  bwrite_endian(fileSize, 4, buffer + 2, Endian);
  bwrite_endian(0, 4, buffer + 6, Endian);
  bwrite_endian(54, 4, buffer + 10, Endian);
  fwrite(buffer, 1, 14, fp);
  memset(buffer, 0x00, 40);
  bwrite_endian(40, 4, buffer + 0, Endian);
  bwrite_endian(w, 4, buffer + 4, Endian);
  bwrite_endian(h, 4, buffer + 8, Endian);
  bwrite_endian(1, 2, buffer + 12, Endian);
  bwrite_endian(32, 2, buffer + 14, Endian);
  bwrite_endian(0, 4, buffer + 16, Endian);
  bwrite_endian(imageSize, 4, buffer + 20, Endian);
  bwrite_endian(0x10000, 4, buffer + 24, Endian);
  bwrite_endian(0x10000, 4, buffer + 28, Endian);
  bwrite_endian(0x1000000, 4, buffer + 32, Endian);
  bwrite_endian(0, 4, buffer + 36, Endian);
  fwrite(buffer, 1, 40, fp);
  buffer[0] = 0;
  for (y = h - 1; y >= 0; --y) {
    for (x = 0; x < w; ++x) {
      fwrite(&data[x + y * w][2], 1, 1, fp);
      fwrite(&data[x + y * w][1], 1, 1, fp);
      fwrite(&data[x + y * w][0], 1, 1, fp);
      fwrite(buffer, 1, 1, fp);
    }
  }
  fclose(fp);
  return 0;
}
```