user: Converte this assembly snippet into its equivalent C code:

```asm
<pgmyuv_save>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %esi,-0x4c(%rbp)
  mov    %edx,-0x50(%rbp)
  mov    %rcx,-0x58(%rbp)
  mov    -0x4c(%rbp),%eax
  imul   -0x50(%rbp),%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  mov    -0x4c(%rbp),%eax
  imul   -0x50(%rbp),%eax
  lea    0x3(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  mov    -0x4c(%rbp),%eax
  imul   -0x50(%rbp),%eax
  lea    0x3(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x50(%rbp),%r8d
  mov    -0x4c(%rbp),%edi
  mov    -0x58(%rbp),%rcx
  mov    -0x10(%rbp),%rdx
  mov    -0x18(%rbp),%rsi
  mov    -0x20(%rbp),%rax
  mov    %r8d,%r9d
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <rgb24_to_yuv420p@plt>
  mov    -0x48(%rbp),%rax
  lea    D5(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x8(%rbp)
  mov    -0x50(%rbp),%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,%ecx
  mov    -0x4c(%rbp),%edx
  mov    -0x8(%rbp),%rax
  mov    $0xff,%r8d
  lea    D13(%rip),%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
  mov    -0x4c(%rbp),%eax
  imul   -0x50(%rbp),%eax
  mov    %eax,%edx
  mov    -0x8(%rbp),%rcx
  mov    -0x20(%rbp),%rax
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x50(%rbp),%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,-0x38(%rbp)
  mov    -0x4c(%rbp),%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,-0x34(%rbp)
  mov    -0x18(%rbp),%rax
  mov    %rax,-0x30(%rbp)
  mov    -0x10(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  movl   $0x0,-0x3c(%rbp)
  jmp    L17
L19:
  mov    -0x8(%rbp),%rcx
  mov    -0x34(%rbp),%edx
  mov    -0x30(%rbp),%rax
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x8(%rbp),%rcx
  mov    -0x34(%rbp),%edx
  mov    -0x28(%rbp),%rax
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x34(%rbp),%eax
  cltq
  add    %rax,-0x30(%rbp)
  mov    -0x34(%rbp),%eax
  cltq
  add    %rax,-0x28(%rbp)
  addl   $0x1,-0x3c(%rbp)
L17:
  mov    -0x3c(%rbp),%eax
  cmp    -0x38(%rbp),%eax
  jl     L19
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  nop
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D5
datatype: string
name: extract_symbolic_data
arguments: data_tag: D13
datatype: string

tool: D5: wb

tool: D13: P5
%d %d
%d


assistant: ```c
void pgmyuv_save(const char *filename, int w, int h, unsigned char *rgb_tab) {
  FILE *f;
  int i, h2, w2;
  unsigned char *cb, *cr;
  unsigned char *lum_tab, *cb_tab, *cr_tab;
  lum_tab = malloc(w * h);
  cb_tab = malloc((w * h) / 4);
  cr_tab = malloc((w * h) / 4);
  rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
  f = fopen(filename, "wb");
  fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255);
  fwrite(lum_tab, 1, w * h, f);
  h2 = h / 2;
  w2 = w / 2;
  cb = cb_tab;
  cr = cr_tab;
  for (i = 0; i < h2; i++) {
    fwrite(cb, 1, w2, f);
    fwrite(cr, 1, w2, f);
    cb += w2;
    cr += w2;
  }
  fclose(f);
  free(lum_tab);
  free(cb_tab);
  free(cr_tab);
}
```