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

```asm
<writePgmPictureBinary>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %rsi,-0x60(%rbp)
  mov    %rdx,-0x68(%rbp)
  mov    %rcx,-0x70(%rbp)
  mov    %r8,-0x78(%rbp)
  mov    %r9d,-0x7c(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x28(%rbp)
  xor    %eax,%eax
  mov    %rsp,%rax
  mov    %rax,%rbx
  movl   $0x0,-0x48(%rbp)
  movl   $0x0,-0x44(%rbp)
  mov    0x10(%rbp),%eax
  movslq %eax,%rdx
  sub    $0x1,%rdx
  mov    %rdx,-0x40(%rbp)
  movslq %eax,%rdx
  mov    %rdx,%r12
  mov    $0x0,%r13d
  movslq %eax,%rdx
  mov    %rdx,%r10
  mov    $0x0,%r11d
  cltq
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%edi
  mov    $0x0,%edx
  div    %rdi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L80:
  cmp    %rdx,%rsp
  je     L58
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L80
L58:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L60
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L60:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x68(%rbp),%rdx
  mov    -0x60(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  je     L53
  mov    -0x78(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  lea    D10(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  lea    D26(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    -0x30(%rbp),%rax
  mov    %rax,%rcx
  mov    $0x41,%edx
  mov    $0x1,%esi
  lea    D46(%rip),%rax
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x7c(%rbp),%edx
  mov    -0x30(%rbp),%rax
  mov    0x10(%rbp),%ecx
  lea    D6(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    0x18(%rbp),%edx
  mov    -0x30(%rbp),%rax
  lea    D9(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  movl   $0x0,-0x48(%rbp)
  jmp    L45
L9:
  movl   $0x0,-0x44(%rbp)
  jmp    L78
L23:
  mov    -0x48(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x70(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x44(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,%ecx
  mov    -0x38(%rbp),%rdx
  mov    -0x44(%rbp),%eax
  cltq
  mov    %cl,(%rdx,%rax,1)
  addl   $0x1,-0x44(%rbp)
L78:
  mov    -0x44(%rbp),%eax
  cmp    0x10(%rbp),%eax
  jl     L23
  mov    -0x30(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rcx
  mov    0x10(%rbp),%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  addl   $0x1,-0x48(%rbp)
L45:
  mov    -0x48(%rbp),%eax
  cmp    -0x7c(%rbp),%eax
  jl     L9
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
L53:
  mov    %rbx,%rsp
  nop
  mov    -0x28(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L67
  call   <__stack_chk_fail@plt>
L67:
  lea    -0x18(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %rbp
  ret
```

tool_calls: name: read_data
arguments: label: D10
type_guessed: string
name: read_data
arguments: label: D26
type_guessed: string
name: read_data
arguments: label: D46
type_guessed: string
name: read_data
arguments: label: D6
type_guessed: string
name: read_data
arguments: label: D9
type_guessed: string

tool: D10: %s@n

tool: D26: # This a binary image from %s@n

tool: D46: # It is automatic created by Delmas Pierre Binarisation Program@n

tool: D6: %d %d@n

tool: D9: %d@n

assistant: ```c
void writePgmPictureBinary(char *fileNameBase, char *nameFile, char *mode, int **imageMatrix, char *magicNumber, int idim, int jdim, int dynamic) {
  int row = 0;
  int column = 0;
  unsigned char line[jdim];
  FILE *file;
  file = fopen(nameFile, mode);
  if (file != NULL) {
    fprintf(file, "%s@n", magicNumber);
    fprintf(file, "# This a binary image from %s@n", fileNameBase);
    fprintf(file, "# It is automatic created by Delmas Pierre Binarisation Program@n");
    fprintf(file, "%d %d@n", idim, jdim);
    fprintf(file, "%d@n", dynamic);
    for (row = 0; row < idim; row++) {
      for (column = 0; column < jdim; column++) {
        line[column] = (unsigned char)imageMatrix[row][column];
      }
      fwrite(line, sizeof(unsigned char), jdim, file);
    }
    fclose(file);
  }
}
```