user: Translate the below assembly code into C programming language:

```asm
<WriteBMP32>:
  endbr64
  push   %r15
  push   %r14
  mov    %edx,%r14d
  push   %r13
  push   %r12
  mov    %ecx,%r12d
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rsi,(%rsp)
  lea    D6(%rip),%rsi
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  test   %rax,%rax
  je     L65
  mov    %r14d,%r13d
  lea    0x10(%rsp),%rbp
  mov    $0xe,%edx
  xor    %esi,%esi
  imul   %r12d,%r13d
  mov    %rbp,%rdi
  mov    %rax,%r15
  call   <memset@plt>
  mov    $0x4d42,%eax
  lea    0x12(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    %ax,0x10(%rsp)
  shl    $0x2,%r13d
  lea    0x36(%r13),%edi
  call   <bwrite_endian@plt>
  lea    0x16(%rsp),%rdx
  mov    $0x1,%ecx
  xor    %edi,%edi
  mov    $0x4,%esi
  call   <bwrite_endian@plt>
  lea    0x1a(%rsp),%rdx
  mov    $0x1,%ecx
  mov    $0x4,%esi
  mov    $0x36,%edi
  call   <bwrite_endian@plt>
  mov    %r15,%rcx
  mov    $0xe,%edx
  mov    %rbp,%rdi
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    $0x28,%edx
  xor    %esi,%esi
  mov    %rbp,%rdi
  call   <memset@plt>
  mov    $0x1,%ecx
  mov    %rbp,%rdx
  mov    $0x4,%esi
  mov    $0x28,%edi
  call   <bwrite_endian@plt>
  lea    0x14(%rsp),%rdx
  mov    $0x1,%ecx
  mov    %r14d,%edi
  mov    $0x4,%esi
  call   <bwrite_endian@plt>
  lea    0x18(%rsp),%rdx
  mov    $0x1,%ecx
  mov    %r12d,%edi
  mov    $0x4,%esi
  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
  xor    %edi,%edi
  mov    $0x4,%esi
  call   <bwrite_endian@plt>
  lea    0x24(%rsp),%rdx
  mov    $0x1,%ecx
  mov    %r13d,%edi
  mov    $0x4,%esi
  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
  xor    %edi,%edi
  mov    $0x4,%esi
  call   <bwrite_endian@plt>
  mov    %r15,%rcx
  mov    $0x28,%edx
  mov    %rbp,%rdi
  mov    $0x1,%esi
  call   <fwrite@plt>
  movb   $0x0,0x10(%rsp)
  sub    $0x1,%r12d
  js     L16
  mov    %r12d,%eax
  imul   %r14d,%eax
  mov    %eax,0x8(%rsp)
  lea    -0x1(%r14),%eax
  mov    %eax,0xc(%rsp)
  nopl   0x0(%rax)
L36:
  test   %r14d,%r14d
  jle    L48
  movslq 0x8(%rsp),%rdx
  mov    0xc(%rsp),%eax
  mov    (%rsp),%rbx
  add    %rdx,%rax
  lea    0x2(%rdx,%rdx,2),%r8
  lea    (%rax,%rax,2),%rax
  lea    (%rbx,%r8,1),%r13
  lea    0x5(%rbx,%rax,1),%rbx
  nopl   0x0(%rax,%rax,1)
L0:
  mov    %r13,%rdi
  mov    %r15,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  lea    -0x1(%r13),%rdi
  mov    %r15,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  lea    -0x2(%r13),%rdi
  mov    %r15,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  add    $0x3,%r13
  call   <fwrite@plt>
  mov    %r15,%rcx
  mov    $0x1,%edx
  mov    %rbp,%rdi
  mov    $0x1,%esi
  call   <fwrite@plt>
  cmp    %rbx,%r13
  jne    L0
L48:
  sub    $0x1,%r12d
  sub    %r14d,0x8(%rsp)
  cmp    $0xffffffff,%r12d
  jne    L36
L16:
  mov    %r15,%rdi
  call   <fclose@plt>
  xor    %eax,%eax
L60:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L31
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L65:
  mov    $0xffffffff,%eax
  jmp    L60
L31:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D6
type_infered: string

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