user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<writeMainPvd>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x10,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  lea    D79(%rip),%rdi
  call   <opendir@plt>
  mov    %rax,%rbp
  mov    $0x0,%ebx
  lea    D22(%rip),%r12
  test   %rax,%rax
  jne    L82
  jmp    L78
L104:
  lea    0x4(%rsp),%rdx
  mov    %r12,%rsi
  mov    (%rax),%edi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  sbb    $0xffffffff,%ebx
L82:
  mov    %rbp,%rdi
  call   <readdir@plt>
  test   %rax,%rax
  jne    L104
L78:
  lea    0x0(,%rbx,4),%edi
  call   <malloc@plt>
  mov    %rax,%rbx
  lea    D79(%rip),%rdi
  call   <opendir@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L61
  mov    %rbx,%r14
  mov    $0x0,%ebp
  lea    D22(%rip),%r13
L153:
  mov    %r12,%rdi
  call   <readdir@plt>
  test   %rax,%rax
  je     L139
  lea    0x4(%rsp),%rdx
  mov    %r13,%rsi
  mov    (%rax),%edi
  call   <sscanf@plt>
  test   %eax,%eax
  je     L153
  mov    0x4(%rsp),%eax
  mov    %eax,(%r14)
  add    $0x1,%ebp
  add    $0x4,%r14
  jmp    L153
L139:
  lea    -0x1(%rbp),%r8d
  test   %r8d,%r8d
  jle    L69
  lea    0x4(%rbx),%r9
  jmp    L121
L31:
  cmp    %rdi,%rax
  je     L93
L65:
  mov    %rax,%rsi
  mov    (%rax),%ecx
  add    $0x4,%rax
  mov    (%rax),%edx
  cmp    %edx,%ecx
  jle    L31
  mov    %ecx,(%rax)
  mov    %edx,(%rsi)
  jmp    L31
L93:
  sub    $0x1,%r8d
  je     L69
L121:
  test   %r8d,%r8d
  jle    L93
  lea    -0x1(%r8),%eax
  lea    (%r9,%rax,4),%rdi
  mov    %rbx,%rax
  jmp    L65
L69:
  lea    D57(%rip),%rsi
  lea    D121(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  mov    %rax,%rcx
  mov    $0x44,%edx
  mov    $0x1,%esi
  lea    D0(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0xf,%edx
  mov    $0x1,%esi
  lea    D34(%rip),%rdi
  call   <fwrite@plt>
  test   %ebp,%ebp
  jle    L178
  mov    %rbx,%r12
  lea    -0x1(%rbp),%eax
  lea    0x4(%rbx,%rax,4),%rbp
  lea    D29(%rip),%rbx
L89:
  mov    (%r12),%edx
  mov    %edx,%ecx
  mov    %rbx,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  add    $0x4,%r12
  cmp    %r12,%rbp
  jne    L89
L178:
  mov    %r13,%rcx
  mov    $0x10,%edx
  mov    $0x1,%esi
  lea    D67(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0xb,%edx
  mov    $0x1,%esi
  lea    D63(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rdi
  call   <fclose@plt>
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L106
  add    $0x10,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L61:
  lea    D57(%rip),%rsi
  lea    D121(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  mov    %rax,%rcx
  mov    $0x44,%edx
  mov    $0x1,%esi
  lea    D0(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0xf,%edx
  mov    $0x1,%esi
  lea    D34(%rip),%rdi
  call   <fwrite@plt>
  jmp    L178
L106:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_tag: D79
data_type: string
name: unpack_data
arguments: data_tag: D22
data_type: string
name: unpack_data
arguments: data_tag: D57
data_type: string
name: unpack_data
arguments: data_tag: D121
data_type: string
name: unpack_data
arguments: data_tag: D0
data_type: string
name: unpack_data
arguments: data_tag: D34
data_type: string
name: unpack_data
arguments: data_tag: D29
data_type: string
name: unpack_data
arguments: data_tag: D67
data_type: string
name: unpack_data
arguments: data_tag: D63
data_type: string

tool: D79: .

tool: D22: %d

tool: D57: w

tool: D121: case.pvd

tool: D0: <VTKFile type="Collection" version="0.1" byte_order="LittleEndian">


tool: D34:   <Collection>


tool: D29:     <DataSet part="0"  timestep="%d" file="%d/fields.pvtu" />


tool: D67:   </Collection>


tool: D63: </VTKFile>


assistant: ```c
void writeMainPvd() {
  uint *tSteps;
  int status, aux;
  uint nt = 0;
  DIR *d;
  struct dirent *dir;
  d = opendir(".");
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      status = sscanf(dir->d_name, "%d", &aux);
      if (status != 0) {
        nt++;
      }
    }
  }
  tSteps = (uint *)malloc(nt * sizeof(uint));
  nt = 0;
  d = opendir(".");
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      status = sscanf(dir->d_name, "%d", &aux);
      if (status != 0) {
        tSteps[nt] = aux;
        nt++;
      }
    }
  }
  {
    int i, j, temp;
    for (i = 0; i < (nt - 1); ++i) {
      for (j = 0; j < (nt - 1) - i; ++j) {
        if (tSteps[j] > tSteps[j + 1]) {
          temp = tSteps[j + 1];
          tSteps[j + 1] = tSteps[j];
          tSteps[j] = temp;
        }
      }
    }
  }
  FILE *file = fopen("case.pvd", "w");
  fprintf(file, "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">\n");
  fprintf(file, "  <Collection>\n");
  uint i;
  for (i = 0; i < nt; i++) {
    fprintf(file, "    <DataSet part=\"0\"  timestep=\"%d\" file=\"%d/fields.pvtu\" />\n", tSteps[i], tSteps[i]);
  }
  fprintf(file, "  </Collection>\n");
  fprintf(file, "</VTKFile>\n");
  fclose(file);
}
```