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

```asm
<write_result_vtk>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbx
  mov    %esi,%r14d
  mov    %edx,0x4(%rsp)
  mov    %ecx,%r15d
  mov    %r8,%r13
  mov    %r9,%rbp
  mov    %edx,%eax
  sub    %esi,%eax
  add    $0x1,%eax
  mov    %eax,(%rsp)
  lea    D154(%rip),%rsi
  call   <fopen@plt>
  test   %rax,%rax
  je     L19
  mov    %rax,%r12
  mov    %rax,%rcx
  mov    $0x1b,%edx
  mov    $0x1,%esi
  lea    D89(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0xb,%edx
  mov    $0x1,%esi
  lea    D150(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x6,%edx
  mov    $0x1,%esi
  lea    D4(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x1a,%edx
  mov    $0x1,%esi
  lea    D141(%rip),%rdi
  call   <fwrite@plt>
  mov    %r15d,%edx
  lea    D178(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    (%rsp),%r8d
  mov    0x4(%rsp),%ecx
  mov    %r14d,%edx
  mov    %r15d,%esi
  lea    D45(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    %r15d,%eax
  test   %r15d,%r15d
  jle    L39
  mov    $0x4,%ebx
  mov    $0x1,%r15d
  mov    %r14d,0x8(%rsp)
  mov    %eax,%r14d
L18:
  mov    0x10(%r13),%rax
  mov    0x8(%r13),%rdx
  mov    (%rdx,%rbx,1),%ecx
  mov    0x0(%r13),%rdx
  mov    (%rdx,%rbx,1),%edx
  mov    (%rax,%rbx,1),%r8d
  lea    D149(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  add    $0x1,%r15d
  add    $0x4,%rbx
  cmp    %r15d,%r14d
  jge    L18
  mov    0x8(%rsp),%r14d
L39:
  mov    (%rsp),%edx
  lea    (%rdx,%rdx,8),%ecx
  lea    D129(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    0x4(%rsp),%eax
  cmp    %r14d,%eax
  jl     L57
  movslq %r14d,%r13
  lea    0x0(,%r13,4),%rbx
  mov    %r14d,%r15d
  mov    %r13,0x8(%rsp)
  mov    %eax,%r13d
L84:
  mov    0x10(%rbp),%rax
  mov    (%rax,%rbx,1),%edi
  mov    0x18(%rbp),%rax
  mov    (%rax,%rbx,1),%esi
  mov    0x8(%rbp),%rax
  mov    (%rax,%rbx,1),%ecx
  sub    $0x1,%ecx
  mov    0x0(%rbp),%rax
  mov    (%rax,%rbx,1),%edx
  sub    $0x1,%edx
  mov    0x30(%rbp),%rax
  mov    (%rax,%rbx,1),%eax
  sub    $0x1,%eax
  push   %rax
  mov    0x38(%rbp),%rax
  mov    (%rax,%rbx,1),%eax
  sub    $0x1,%eax
  push   %rax
  mov    0x28(%rbp),%rax
  mov    (%rax,%rbx,1),%eax
  sub    $0x1,%eax
  push   %rax
  mov    0x20(%rbp),%rax
  mov    (%rax,%rbx,1),%eax
  sub    $0x1,%eax
  push   %rax
  lea    -0x1(%rdi),%r9d
  lea    -0x1(%rsi),%r8d
  lea    D169(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  add    $0x1,%r15d
  add    $0x4,%rbx
  add    $0x20,%rsp
  cmp    %r15d,%r13d
  jge    L84
  mov    0x8(%rsp),%r13
  mov    (%rsp),%edx
  lea    D38(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  lea    D107(%rip),%rbx
  mov    0x4(%rsp),%ebp
L29:
  mov    %r12,%rcx
  mov    $0x3,%edx
  mov    $0x1,%esi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  add    $0x1,%r14d
  cmp    %r14d,%ebp
  jge    L29
  mov    (%rsp),%edx
  lea    D120(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %r12,%rcx
  mov    $0x2b,%edx
  mov    $0x1,%esi
  lea    D36(%rip),%rdi
  call   <fwrite@plt>
  lea    D146(%rip),%rbx
  mov    0x4(%rsp),%ebp
  mov    0x50(%rsp),%r14
L26:
  movsd  (%r14,%r13,8),%xmm0
  mov    %rbx,%rsi
  mov    %r12,%rdi
  mov    $0x1,%eax
  call   <fprintf@plt>
  add    $0x1,%r13
  cmp    %r13d,%ebp
  jge    L26
L20:
  mov    %r12,%rdi
  call   <fclose@plt>
  mov    $0x0,%eax
L79:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L19:
  mov    %rbx,%rsi
  lea    D97(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0xffffffff,%eax
  jmp    L79
L57:
  mov    (%rsp),%ebx
  mov    %ebx,%edx
  lea    D38(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %ebx,%edx
  lea    D120(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %r12,%rcx
  mov    $0x2b,%edx
  mov    $0x1,%esi
  lea    D36(%rip),%rdi
  call   <fwrite@plt>
  jmp    L20
```

tool_calls: name: unpack_data
arguments: data_tag: D154
type_guessed: string
name: unpack_data
arguments: data_tag: D89
type_guessed: string
name: unpack_data
arguments: data_tag: D150
type_guessed: string
name: unpack_data
arguments: data_tag: D4
type_guessed: string
name: unpack_data
arguments: data_tag: D141
type_guessed: string
name: unpack_data
arguments: data_tag: D178
type_guessed: string
name: unpack_data
arguments: data_tag: D45
type_guessed: string
name: unpack_data
arguments: data_tag: D149
type_guessed: string
name: unpack_data
arguments: data_tag: D129
type_guessed: string
name: unpack_data
arguments: data_tag: D169
type_guessed: string
name: unpack_data
arguments: data_tag: D38
type_guessed: string
name: unpack_data
arguments: data_tag: D107
type_guessed: string
name: unpack_data
arguments: data_tag: D120
type_guessed: string
name: unpack_data
arguments: data_tag: D36
type_guessed: string
name: unpack_data
arguments: data_tag: D146
type_guessed: string
name: unpack_data
arguments: data_tag: D97
type_guessed: string

tool: D154: w

tool: D89: # vtk DataFile Version 3.0


tool: D150: vtk output


tool: D4: ASCII


tool: D141: DATASET UNSTRUCTURED_GRID


tool: D178: POINTS %d float


tool: D45: nodeCnt = %d, startInd= %d, endInd = %d, cellCnt=%d


tool: D149: %d %d %d


tool: D129: 
CELLS %d %d


tool: D169: 8 %d %d %d %d %d %d %d %d


tool: D38: 
CELL_TYPES %d


tool: D107: 11


tool: D120: 
CELL_DATA %d


tool: D36: SCALARS scalars float
LOOKUP_TABLE default


tool: D146: %f 

tool: D97: Error opening file %s for writing


assistant: ```c
int write_result_vtk(char *outFileName, int startIdx, int endIdx, int nodeCnt, int **points, int **elems, double *vector) {
  int i, j;
  int cellCnt = endIdx - startIdx + 1;
  FILE *fp = fopen(outFileName, "w");
  if (fp == NULL) {
    printf("Error opening file %s for writing\n", outFileName);
    return -1;
  }
  fprintf(fp, "# vtk DataFile Version 3.0\n");
  fprintf(fp, "vtk output\n");
  fprintf(fp, "ASCII\n");
  fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");
  fprintf(fp, "POINTS %d float\n", nodeCnt);
  printf("nodeCnt = %d, startInd= %d, endInd = %d, cellCnt=%d\n", nodeCnt, startIdx, endIdx, cellCnt);
  for (i = 1; i <= nodeCnt; i++) {
    fprintf(fp, "%d %d %d\n", points[0][i], points[1][i], points[2][i]);
  }
  fprintf(fp, "\nCELLS %d %d\n", cellCnt, 9 * cellCnt);
  for (i = startIdx; i <= endIdx; i++) {
    fprintf(fp, "8 %d %d %d %d %d %d %d %d\n", elems[0][i] - 1, elems[1][i] - 1, elems[3][i] - 1, elems[2][i] - 1, elems[4][i] - 1, elems[5][i] - 1, elems[7][i] - 1, elems[6][i] - 1);
  }
  fprintf(fp, "\nCELL_TYPES %d\n", cellCnt);
  for (i = startIdx; i <= endIdx; i++) {
    fprintf(fp, "11\n");
  }
  fprintf(fp, "\nCELL_DATA %d\n", cellCnt);
  fprintf(fp, "SCALARS scalars float\nLOOKUP_TABLE default\n");
  for (i = startIdx; i <= endIdx; i++) {
    fprintf(fp, "%f ", vector[i]);
  }
  fclose(fp);
  return 0;
}
```