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

```asm
<writebmp>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %edx,0x4(%rsp)
  test   %rcx,%rcx
  je     L13
  mov    %esi,%r12d
  xor    %eax,%eax
  lea    D8(%rip),%rsi
  mov    %rcx,%rbx
  call   <fopen@plt>
  test   %eax,%eax
  jne    L75
L13:
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L75:
  lea    0x3(%r12,%r12,2),%edx
  mov    0x4(%rsp),%r14d
  movslq %eax,%rbp
  mov    $0x42,%edi
  mov    %edx,%r15d
  mov    %rbp,%rsi
  mov    %edx,0x8(%rsp)
  call   <fputc@plt>
  and    $0xfffffffc,%r15d
  mov    %r14d,%r13d
  mov    %rbp,%rsi
  imul   %r15d,%r13d
  mov    $0x4d,%edi
  call   <fputc@plt>
  mov    %rbp,%rdi
  xor    %eax,%eax
  lea    0x36(%r13),%esi
  call   <write_le_int32@plt>
  xor    %esi,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int16@plt>
  xor    %esi,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int16@plt>
  mov    $0x36,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    $0x28,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    %r12d,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    %r14d,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    $0x1,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int16@plt>
  mov    $0x18,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int16@plt>
  xor    %esi,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    %r13d,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    $0x2e23,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  mov    $0x2e23,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  xor    %esi,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <write_le_int32@plt>
  movslq %r15d,%r13
  xor    %esi,%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  mov    %r14d,%r12d
  call   <write_le_int32@plt>
  mov    $0x1,%esi
  mov    %r13,%rdi
  call   <calloc@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L54
  test   %r12d,%r12d
  jle    L42
  mov    0x8(%rsp),%edx
  xor    %r12d,%r12d
  sub    $0x3,%edx
  movslq %edx,%rax
  mov    %rax,0x8(%rsp)
  xchg   %ax,%ax
L45:
  test   %r15d,%r15d
  jle    L52
  mov    %rbx,%rdx
  xor    %eax,%eax
  nopw   0x0(%rax,%rax,1)
L1:
  movzbl 0x2(%rdx),%ecx
  add    $0x3,%rdx
  mov    %cl,(%r14,%rax,1)
  movzbl -0x2(%rdx),%ecx
  mov    %cl,0x1(%r14,%rax,1)
  movzbl -0x3(%rdx),%ecx
  mov    %cl,0x2(%r14,%rax,1)
  add    $0x3,%rax
  cmp    %eax,%r15d
  jg     L1
L52:
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <fwrite@plt>
  add    $0x1,%r12d
  add    0x8(%rsp),%rbx
  cmp    %r12d,0x4(%rsp)
  jne    L45
L42:
  mov    %r14,%rdi
  call   <free@plt>
L54:
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fclose@plt>
  jmp    L13
```

tool_calls: name: parse_data
arguments: data_tag: D8
data_type: string

tool: D8: wb

assistant: ```c
signed int writebmp(char *filename, signed int xs, signed int ys, unsigned char *img) {
  if (!(img == ((unsigned char *)((void *)0)))) {
    struct _IO_FILE$link44 *dfile;
    dfile = fopen(filename, "wb");
    if (!(dfile == ((struct _IO_FILE$link44 *)((void *)0)))) {
      signed int i;
      signed int y;
      signed int imgdataoffset = 14 + 40;
      signed int rowsz = xs * 3 + 3 & -4;
      signed int imgdatasize = rowsz * ys;
      signed int filesize = imgdataoffset + imgdatasize;
      unsigned char *rowbuf = (unsigned char *)((void *)0);
      fputc(66, dfile);
      fputc(77, dfile);
      write_le_int32(dfile, filesize);
      write_le_int16(dfile, 0);
      write_le_int16(dfile, 0);
      write_le_int32(dfile, imgdataoffset);
      write_le_int32(dfile, 40);
      write_le_int32(dfile, xs);
      write_le_int32(dfile, ys);
      write_le_int16(dfile, 1);
      write_le_int16(dfile, 24);
      write_le_int32(dfile, 0);
      write_le_int32(dfile, imgdatasize);
      write_le_int32(dfile, 11811);
      write_le_int32(dfile, 11811);
      write_le_int32(dfile, 0);
      write_le_int32(dfile, 0);
      void *return_value_malloc$1;
      return_value_malloc$1 = malloc((unsigned long int)rowsz);
      rowbuf = (unsigned char *)return_value_malloc$1;
      if (!(rowbuf == ((unsigned char *)((void *)0)))) {
        memset((void *)rowbuf, 0, (unsigned long int)rowsz);
        y = 0;
        while (!(y >= ys)) {
          signed int addr = xs * 3 * y;
          i = 0;
          while (!(i >= rowsz)) {
            rowbuf[(signed long int)i] = img[(signed long int)(addr + i + 2)];
            rowbuf[(signed long int)(i + 1)] = img[(signed long int)(addr + i + 1)];
            rowbuf[(signed long int)(i + 2)] = img[(signed long int)(addr + i)];
            i = i + 3;
          }
          fwrite((const void *)rowbuf, (unsigned long int)rowsz, (unsigned long int)1, dfile);
          y = y + 1;
        }
        free((void *)rowbuf);
      }
      fclose(dfile);
    }
  }
  return 0;
}
```