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

```asm
<write_matrix>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0xb0,%rsp
  mov    %rdi,-0x88(%rbp)
  mov    %rsi,-0x90(%rbp)
  mov    %edx,-0x94(%rbp)
  mov    %ecx,-0x98(%rbp)
  mov    %r8d,-0x9c(%rbp)
  mov    %r9d,-0xa0(%rbp)
  movsd  %xmm0,-0xa8(%rbp)
  movsd  %xmm1,-0xb0(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x70(%rbp)
  mov    -0x98(%rbp),%eax
  sub    -0x94(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    -0xa0(%rbp),%eax
  sub    -0x9c(%rbp),%eax
  add    $0x1,%eax
  imul   %edx,%eax
  mov    %eax,-0x74(%rbp)
  mov    -0x74(%rbp),%eax
  cltq
  shl    $0x2,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x68(%rbp)
  movl   $0x0,-0x78(%rbp)
  cmpl   $0x0,0x10(%rbp)
  je     L81
  mov    -0x88(%rbp),%rax
  lea    D15(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x70(%rbp)
  cmpq   $0x0,-0x70(%rbp)
  jne    L60
  mov    -0x88(%rbp),%rdx
  lea    -0x60(%rbp),%rax
  lea    D33(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  lea    -0x60(%rbp),%rax
  mov    %rax,%rdx
  lea    D76(%rip),%rax
  mov    %rax,%rsi
  mov    $0x10a,%edi
  call   <errhandler@plt>
  jmp    L60
L81:
  mov    -0x88(%rbp),%rax
  lea    D14(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x70(%rbp)
  cmpq   $0x0,-0x70(%rbp)
  jne    L60
  mov    -0x88(%rbp),%rdx
  lea    -0x60(%rbp),%rax
  lea    D39(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  lea    -0x60(%rbp),%rax
  mov    %rax,%rdx
  lea    D76(%rip),%rax
  mov    %rax,%rsi
  mov    $0x116,%edi
  call   <errhandler@plt>
L60:
  mov    -0x9c(%rbp),%eax
  mov    %eax,-0x7c(%rbp)
  jmp    L21
L48:
  mov    -0x94(%rbp),%eax
  mov    %eax,-0x80(%rbp)
  jmp    L20
L49:
  mov    -0x80(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x90(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x7c(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x78(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x78(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x68(%rbp),%rax
  add    %rdx,%rax
  cvtsd2ss %xmm0,%xmm0
  movss  %xmm0,(%rax)
  addl   $0x1,-0x80(%rbp)
L20:
  mov    -0x80(%rbp),%eax
  cmp    -0x98(%rbp),%eax
  jle    L49
  addl   $0x1,-0x7c(%rbp)
L21:
  mov    -0x7c(%rbp),%eax
  cmp    -0xa0(%rbp),%eax
  jle    L48
  mov    -0x70(%rbp),%rcx
  mov    -0x74(%rbp),%edx
  mov    -0x68(%rbp),%rax
  mov    $0x4,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  mov    -0x70(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  test   %rax,%rax
  je     L85
  mov    -0x88(%rbp),%rdx
  lea    -0x60(%rbp),%rax
  lea    D0(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  lea    -0x60(%rbp),%rax
  mov    %rax,%rdx
  lea    D76(%rip),%rax
  mov    %rax,%rsi
  mov    $0x124,%edi
  call   <errhandler@plt>
L85:
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L6
  call   <__stack_chk_fail@plt>
L6:
  leave
  ret
```

tool_calls: name: parse_data
arguments: tag: D15
data_type: string
name: parse_data
arguments: tag: D33
data_type: string
name: parse_data
arguments: tag: D76
data_type: string
name: parse_data
arguments: tag: D14
data_type: string
name: parse_data
arguments: tag: D39
data_type: string
name: parse_data
arguments: tag: D0
data_type: string

tool: D15: w

tool: D33: Outputfile %s cannot be created

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

tool: D14: a

tool: D39: Outputfile %s cannot be opened

tool: D0: Outputfile %s cannot be closed

assistant: ```c
void write_matrix(const char *szFileName, double **m, int nrl, int nrh, int ncl, int nch, double xlength, double ylength, int fFirst) {
  int i, j;
  FILE *fh = 0;
  int nSize = (nrh - nrl + 1) * (nch - ncl + 1);
  float *tmp = (float *)malloc((size_t)(nSize * sizeof(float)));
  int k = 0;
  if (fFirst) {
    fh = fopen(szFileName, "w");
    if (fh == NULL) {
      char szBuff[80];
      sprintf(szBuff, "Outputfile %s cannot be created", szFileName);
      errhandler(266, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Worksheet1/helper.c", szBuff);
    }
  } else {
    fh = fopen(szFileName, "a");
    if (fh == NULL) {
      char szBuff[80];
      sprintf(szBuff, "Outputfile %s cannot be opened", szFileName);
      errhandler(278, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Worksheet1/helper.c", szBuff);
    }
  }
  for (j = ncl; j <= nch; j++)
    for (i = nrl; i <= nrh; i++)
      tmp[k++] = (float)m[i][j];
  fwrite(tmp, sizeof(float), nSize, fh);
  if (fclose(fh)) {
    char szBuff[80];
    sprintf(szBuff, "Outputfile %s cannot be closed", szFileName);
    errhandler(292, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Worksheet1/helper.c", szBuff);
  };
  free(tmp);
}
```