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

```asm
<writeIntArrtoFile>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %rdx,-0x38(%rbp)
  mov    %rcx,-0x40(%rbp)
  mov    %r8d,-0x44(%rbp)
  mov    %r9d,-0x48(%rbp)
  mov    0x10(%rbp),%rax
  mov    %rax,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x28(%rbp),%rax
  lea    D20(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  mov    %rax,%rcx
  mov    $0x4,%edx
  mov    $0x1,%esi
  lea    D0(%rip),%rax
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rcx
  mov    $0x11,%edx
  mov    $0x1,%esi
  lea    D38(%rip),%rax
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x50(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  lea    D16(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    -0x48(%rbp),%ecx
  mov    -0x44(%rbp),%edx
  mov    -0x10(%rbp),%rax
  lea    D42(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  movl   $0x0,-0x14(%rbp)
  jmp    L27
L17:
  movl   $0x0,-0x18(%rbp)
  jmp    L16
L47:
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  shl    $0x5,%rax
  mov    %rax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rax,%rdx
  mov    -0x14(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  mov    %al,-0x19(%rbp)
  mov    -0x10(%rbp),%rdx
  lea    -0x19(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  shl    $0x5,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x14(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  mov    %al,-0x19(%rbp)
  mov    -0x10(%rbp),%rdx
  lea    -0x19(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  shl    $0x5,%rax
  mov    %rax,%rdx
  mov    -0x40(%rbp),%rax
  add    %rax,%rdx
  mov    -0x14(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  mov    %al,-0x19(%rbp)
  mov    -0x10(%rbp),%rdx
  lea    -0x19(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  addl   $0x1,-0x18(%rbp)
L16:
  mov    -0x18(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L47
  addl   $0x1,-0x14(%rbp)
L27:
  mov    -0x14(%rbp),%eax
  cmp    -0x48(%rbp),%eax
  jl     L17
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D47(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L35
  call   <__stack_chk_fail@plt>
L35:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_tag: D20
type_guessed: string
name: retrieve_data
arguments: data_tag: D0
type_guessed: string
name: retrieve_data
arguments: data_tag: D38
type_guessed: string
name: retrieve_data
arguments: data_tag: D16
type_guessed: string
name: retrieve_data
arguments: data_tag: D42
type_guessed: string
name: retrieve_data
arguments: data_tag: D47
type_guessed: string

tool: D20: w

tool: D0: P6 


tool: D38: # Filtered Image


tool: D16: # initial image:  %s


tool: D42: %ld %ld 
255


tool: D47: output image %s successfully written



assistant: ```c
void writeIntArrtoFile(char *outfilename, int C1[80][120], int C2[80][120], int C3[80][120], int nx, int ny, char *in) {
  int i, j;
  unsigned char byte;
  FILE *outimage = fopen(outfilename, "w");
  fprintf(outimage, "P6 \n");
  fprintf(outimage, "# Filtered Image\n");
  fprintf(outimage, "# initial image:  %s\n", in);
  fprintf(outimage, "%ld %ld \n255\n", nx, ny);
  for (j = 0; j < ny; j++)
    for (i = 0; i < nx; i++) {
      byte = (unsigned char)(C1[i][j]);
      fwrite(&byte, sizeof(unsigned char), 1, outimage);
      byte = (unsigned char)(C2[i][j]);
      fwrite(&byte, sizeof(unsigned char), 1, outimage);
      byte = (unsigned char)(C3[i][j]);
      fwrite(&byte, sizeof(unsigned char), 1, outimage);
    }
  fclose(outimage);
  printf("output image %s successfully written\n\n", outfilename);
}
```