user: Please show me the C implementation that matches the assembly code listed below:

```asm
<saveppm>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %edx,-0x24(%rbp)
  mov    %ecx,-0x28(%rbp)
  mov    -0x18(%rbp),%rax
  lea    D3(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x8(%rbp)
  mov    -0x28(%rbp),%ecx
  mov    -0x24(%rbp),%edx
  mov    -0x8(%rbp),%rax
  lea    D24(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  movl   $0x0,-0x10(%rbp)
  jmp    L52
L32:
  movl   $0x0,-0xc(%rbp)
  jmp    L27
L34:
  mov    -0x10(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  je     L37
  mov    -0x10(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltd
  shr    $0x18,%edx
  add    %edx,%eax
  movzbl %al,%eax
  sub    %edx,%eax
  mov    %eax,%esi
  mov    -0x10(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltd
  shr    $0x18,%edx
  add    %edx,%eax
  movzbl %al,%eax
  sub    %edx,%eax
  mov    %eax,%ecx
  mov    -0x10(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltd
  shr    $0x18,%edx
  add    %edx,%eax
  movzbl %al,%eax
  sub    %edx,%eax
  mov    %eax,%edx
  mov    -0x8(%rbp),%rax
  mov    %esi,%r8d
  lea    D36(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  jmp    L39
L37:
  mov    -0x8(%rbp),%rax
  mov    %rax,%rcx
  mov    $0x6,%edx
  mov    $0x1,%esi
  lea    D7(%rip),%rax
  mov    %rax,%rdi
  call   <fwrite@plt>
L39:
  addl   $0x1,-0xc(%rbp)
L27:
  mov    -0xc(%rbp),%eax
  cmp    -0x28(%rbp),%eax
  jl     L34
  addl   $0x1,-0x10(%rbp)
  mov    -0x8(%rbp),%rax
  mov    %rax,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
L52:
  mov    -0x10(%rbp),%eax
  cmp    -0x24(%rbp),%eax
  jl     L32
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  nop
  leave
  ret
```

tool_calls: name: parse_data
arguments: label: D3
type: string
name: parse_data
arguments: label: D24
type: string
name: parse_data
arguments: label: D36
type: string
name: parse_data
arguments: label: D7
type: string

tool: D3: w

tool: D24: P3
%d %d
255


tool: D36: %d %d %d


tool: D7: 0 0 0


assistant: ```c
void saveppm(char *fname, int **img, int x, int y) {
  int i, j;
  FILE *fp = fopen(fname, "w");
  fprintf(fp, "P3\n%d %d\n255\n", x, y);
  for (i = 0; i < x; i++, fprintf(fp, "\n"))
    for (j = 0; j < y; j++)
      if (img[i][j])
        fprintf(fp, "%d %d %d\n", img[i][j] % 256, img[i][j] % 256, img[i][j] % 256);
      else
        fprintf(fp, "0 0 0\n");
  fclose(fp);
  return;
}
```