user: 请从给定的汇编指令推导出C源代码：

```asm
<write_matrix>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x88,%rsp
  mov    %rdi,0x8(%rsp)
  mov    %rsi,(%rsp)
  mov    %edx,%ebp
  mov    %ecx,%r12d
  mov    %r8d,%r14d
  mov    %r9d,%r13d
  mov    %fs:0x28,%rax
  mov    %rax,0x78(%rsp)
  xor    %eax,%eax
  mov    %ecx,%edx
  sub    %ebp,%edx
  add    $0x1,%edx
  mov    %r9d,%eax
  sub    %r8d,%eax
  add    $0x1,%eax
  imul   %eax,%edx
  mov    %edx,%r15d
  movslq %edx,%rdi
  shl    $0x2,%rdi
  call   <malloc@plt>
  mov    %rax,%rbx
  cmpl   $0x0,0xc0(%rsp)
  je     L82
  lea    D67(%rip),%rsi
  mov    0x8(%rsp),%rdi
  call   <fopen@plt>
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  je     L61
L39:
  cmp    %r14d,%r13d
  jl     L56
  movslq %r14d,%rax
  lea    0x0(,%rax,8),%rcx
  sub    %r14d,%r13d
  lea    0x1(%rax,%r13,1),%r9
  shl    $0x3,%r9
  mov    %rbx,%rdx
  neg    %rdx
  movslq %ebp,%rax
  shl    $0x3,%rax
  lea    (%rax,%rdx,2),%r13
  mov    $0x0,%r8d
  mov    %r12d,%eax
  sub    %ebp,%eax
  mov    %eax,%r11d
  lea    0x4(%rbx),%r10
  lea    0x1(%rax),%r14d
  jmp    L26
L61:
  lea    0x20(%rsp),%rax
  mov    0x8(%rsp),%rdx
  lea    D38(%rip),%rsi
  mov    %rax,0x18(%rsp)
  mov    %rax,%rdi
  call   <sprintf@plt>
  mov    0x18(%rsp),%rdx
  lea    D1(%rip),%rsi
  mov    $0xfb,%edi
  call   <errhandler@plt>
  jmp    L39
L82:
  lea    D39(%rip),%rsi
  mov    0x8(%rsp),%rdi
  call   <fopen@plt>
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  jne    L39
  lea    0x20(%rsp),%rax
  mov    0x8(%rsp),%rdx
  lea    D43(%rip),%rsi
  mov    %rax,0x18(%rsp)
  mov    %rax,%rdi
  call   <sprintf@plt>
  mov    0x18(%rsp),%rdx
  lea    D1(%rip),%rsi
  mov    $0x107,%edi
  call   <errhandler@plt>
  jmp    L39
L25:
  movslq %r8d,%rdx
  lea    (%rbx,%rdx,4),%rax
  lea    (%r11,%rdx,1),%rsi
  lea    (%r10,%rsi,4),%rdi
  neg    %rdx
  lea    0x0(%r13,%rdx,8),%rsi
  add    (%rsp),%rsi
L69:
  mov    (%rsi,%rax,2),%rdx
  pxor   %xmm0,%xmm0
  cvtsd2ss (%rdx,%rcx,1),%xmm0
  movss  %xmm0,(%rax)
  add    $0x4,%rax
  cmp    %rdi,%rax
  jne    L69
  add    %r14d,%r8d
L7:
  add    $0x8,%rcx
  cmp    %r9,%rcx
  je     L56
L26:
  cmp    %ebp,%r12d
  jge    L25
  jmp    L7
L56:
  mov    0x10(%rsp),%r14
  mov    %r14,%rcx
  mov    %r15d,%edx
  mov    $0x4,%esi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  mov    %r14,%rdi
  call   <fclose@plt>
  test   %rax,%rax
  jne    L57
L30:
  mov    %rbx,%rdi
  call   <free@plt>
  mov    0x78(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L62
  add    $0x88,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L57:
  lea    0x20(%rsp),%rbp
  mov    0x8(%rsp),%rdx
  lea    D26(%rip),%rsi
  mov    %rbp,%rdi
  call   <sprintf@plt>
  mov    %rbp,%rdx
  lea    D1(%rip),%rsi
  mov    $0x115,%edi
  call   <errhandler@plt>
  jmp    L30
L62:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: tag: D67
type_infered: string
name: read_data
arguments: tag: D38
type_infered: string
name: read_data
arguments: tag: D1
type_infered: string
name: read_data
arguments: tag: D39
type_infered: string
name: read_data
arguments: tag: D43
type_infered: string
name: read_data
arguments: tag: D26
type_infered: string

tool: D67: w

tool: D38: Outputfile %s cannot be created

tool: D1: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/refs/heads/master/01_assignment/helper.c

tool: D39: a

tool: D43: Outputfile %s cannot be opened

tool: D26: 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(251, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/refs/heads/master/01_assignment/helper.c", szBuff);
    }
  } else {
    fh = fopen(szFileName, "a");
    if (fh == NULL) {
      char szBuff[80];
      sprintf(szBuff, "Outputfile %s cannot be opened", szFileName);
      errhandler(263, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/refs/heads/master/01_assignment/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(277, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/refs/heads/master/01_assignment/helper.c", szBuff);
  };
  free(tmp);
}
```