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

```asm
<write_matrix2>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xd8,%rsp
  mov    %rdx,%r14
  mov    %ecx,0x10(%rsp)
  mov    %r8d,%r15d
  mov    %r9d,0x14(%rsp)
  mov    %fs:0x28,%rdx
  mov    %rdx,0xc8(%rsp)
  xor    %edx,%edx
  lea    0x20(%rsp),%rbx
  mov    %rdi,%rcx
  mov    %esi,%edx
  lea    D34(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  lea    D4(%rip),%rsi
  mov    %rbx,%rdi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L60
L39:
  mov    0x120(%rsp),%eax
  cmp    %eax,0x118(%rsp)
  jg     L9
  movslq 0x118(%rsp),%r13
  shl    $0x3,%r13
  movslq 0x14(%rsp),%rax
  shl    $0x3,%rax
  mov    %rax,0x18(%rsp)
  jmp    L120
L60:
  mov    %rbx,%rdx
  lea    0x70(%rsp),%rbx
  lea    D75(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    %rbx,%rdx
  lea    D61(%rip),%rsi
  mov    $0x13a,%edi
  call   <errhandler@plt>
  jmp    L39
L92:
  mov    (%r14,%rbx,8),%rax
  mov    (%rax,%rbp,1),%rax
  movsd  (%rax,%r13,1),%xmm0
  lea    D57(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x1,%eax
  call   <fprintf@plt>
  add    $0x1,%rbx
  cmp    %ebx,%r15d
  jge    L92
L38:
  mov    %r12,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  addl   $0x1,0xc(%rsp)
  mov    0xc(%rsp),%eax
  add    $0x8,%rbp
  cmp    %eax,0x110(%rsp)
  jl     L53
L24:
  mov    0x10(%rsp),%eax
  movslq %eax,%rbx
  cmp    %r15d,%eax
  jle    L92
  jmp    L38
L53:
  mov    %r12,%rcx
  mov    $0x3c,%edx
  mov    $0x1,%esi
  lea    D43(%rip),%rdi
  call   <fwrite@plt>
  addl   $0x1,0x118(%rsp)
  add    $0x8,%r13
  mov    0x118(%rsp),%eax
  cmp    %eax,0x120(%rsp)
  jl     L9
L120:
  mov    0x18(%rsp),%rbp
  mov    0x14(%rsp),%eax
  mov    %eax,0xc(%rsp)
  cmp    0x110(%rsp),%eax
  jle    L24
  jmp    L53
L9:
  mov    %r12,%rdi
  call   <fclose@plt>
  test   %rax,%rax
  jne    L116
L59:
  mov    0xc8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L95
  add    $0xd8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L116:
  lea    0x20(%rsp),%rdx
  lea    0x70(%rsp),%rbx
  lea    D50(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    %rbx,%rdx
  lea    D61(%rip),%rsi
  mov    $0x14d,%edi
  call   <errhandler@plt>
  jmp    L59
L95:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: label: D34
type: string
name: parse_data
arguments: label: D4
type: string
name: parse_data
arguments: label: D75
type: string
name: parse_data
arguments: label: D61
type: string
name: parse_data
arguments: label: D57
type: string
name: parse_data
arguments: label: D43
type: string
name: parse_data
arguments: label: D50
type: string

tool: D34: debug/d%i_%s

tool: D4: w

tool: D75: Outputfile %s cannot be created

tool: D61: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Backup/FinalProjectPresentation/helper.c

tool: D57: %f 

tool: D43: -----------------------------------------------------------


tool: D50: Outputfile %s cannot be closed

assistant: ```c
void write_matrix2(const char *szDebug, int timeStepNumber, double ***m, int nrl, int nrh, int ncl, int nch, int nll, int nlh) {
  int i, j, k;
  FILE *fh = 0;
  char szFileName[80];
  sprintf(szFileName, "debug/d%i_%s", timeStepNumber, szDebug);
  fh = fopen(szFileName, "w");
  if (fh == NULL) {
    char szBuff[80];
    sprintf(szBuff, "Outputfile %s cannot be created", szFileName);
    errhandler(314, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Backup/FinalProjectPresentation/helper.c", szBuff);
  }
  for (k = nll; k <= nlh; k++) {
    for (j = ncl; j <= nch; j++) {
      for (i = nrl; i <= nrh; i++) {
        fprintf(fh, "%f ", m[i][j][k]);
      }
      fprintf(fh, "\n");
    }
    fprintf(fh, "-----------------------------------------------------------\n");
  }
  if (fclose(fh)) {
    char szBuff[80];
    sprintf(szBuff, "Outputfile %s cannot be closed", szFileName);
    errhandler(333, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Backup/FinalProjectPresentation/helper.c", szBuff);
  };
}
```