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

```asm
<writebmp>:
  endbr64
  test   %rcx,%rcx
  je     L74
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %esi,%ebx
  mov    %edx,%r14d
  mov    %rcx,%r12
  lea    D5(%rip),%rsi
  mov    $0x0,%eax
  call   <fopen@plt>
  test   %eax,%eax
  jne    L4
L37:
  mov    $0x0,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L4:
  movslq %eax,%r13
  lea    0x3(%rbx,%rbx,2),%eax
  mov    %eax,0x8(%rsp)
  mov    %eax,%ebp
  and    $0xfffffffc,%ebp
  mov    %ebp,%r15d
  imul   %r14d,%r15d
  mov    %r13,%rsi
  mov    $0x42,%edi
  call   <fputc@plt>
  mov    %r13,%rsi
  mov    $0x4d,%edi
  call   <fputc@plt>
  lea    0x36(%r15),%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x0,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int16@plt>
  mov    $0x0,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int16@plt>
  mov    $0x36,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x28,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    %ebx,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    %r14d,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x1,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int16@plt>
  mov    $0x18,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int16@plt>
  mov    $0x0,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    %r15d,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x2e23,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x2e23,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x0,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  mov    $0x0,%esi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <write_le_int32@plt>
  movslq %ebp,%r15
  mov    %r15,(%rsp)
  mov    %r15,%rdi
  call   <malloc@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L18
  mov    %r15,%rdx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  test   %r14d,%r14d
  jle    L44
  mov    0x8(%rsp),%eax
  sub    $0x3,%eax
  cltq
  mov    %rax,0x8(%rsp)
  mov    $0x0,%r15d
L68:
  test   %ebp,%ebp
  jle    L79
  mov    %r12,%rdx
  mov    $0x0,%eax
L1:
  movzbl 0x2(%rdx),%ecx
  mov    %cl,(%rbx,%rax,1)
  movzbl 0x1(%rdx),%ecx
  mov    %cl,0x1(%rbx,%rax,1)
  movzbl (%rdx),%ecx
  mov    %cl,0x2(%rbx,%rax,1)
  add    $0x3,%rax
  add    $0x3,%rdx
  cmp    %eax,%ebp
  jg     L1
L79:
  mov    %r13,%rcx
  mov    $0x1,%edx
  mov    (%rsp),%rsi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  add    $0x1,%r15d
  add    0x8(%rsp),%r12
  cmp    %r15d,%r14d
  jne    L68
L44:
  mov    %rbx,%rdi
  call   <free@plt>
L18:
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <fclose@plt>
  jmp    L37
L74:
  mov    $0x0,%eax
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D5
type_guessed: string

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