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

```asm
<write_result>:
  endbr64
  push   %r15
  mov    %ecx,%r15d
  push   %r14
  push   %r13
  lea    0x1(%rcx),%r13d
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  push   %rbx
  mov    %r8,%rbx
  sub    $0x38,%rsp
  mov    %rdi,0x18(%rsp)
  lea    0x0(,%r13,8),%edi
  mov    %rsi,0x10(%rsp)
  mov    %ecx,0x20(%rsp)
  mov    %r9d,0x24(%rsp)
  movsd  %xmm0,0x28(%rsp)
  call   <malloc@plt>
  mov    %rax,%rbp
  cmp    %r12d,%r15d
  jl     L51
  sub    %r12d,%r15d
  lea    0x1(%r15),%ecx
  cmp    $0x2,%r15d
  jbe    L102
  mov    %ecx,%edx
  movd   %r12d,%xmm4
  movslq %r12d,%rax
  movdqa D180(%rip),%xmm3
  shr    $0x2,%edx
  pshufd $0x0,%xmm4,%xmm1
  lea    0x0(%rbp,%rax,8),%rax
  shl    $0x5,%rdx
  paddd  D200(%rip),%xmm1
  add    %rax,%rdx
L3:
  movdqa %xmm1,%xmm0
  add    $0x20,%rax
  paddd  %xmm3,%xmm1
  cvtdq2pd %xmm0,%xmm2
  pshufd $0xee,%xmm0,%xmm0
  movups %xmm2,-0x20(%rax)
  cvtdq2pd %xmm0,%xmm0
  movups %xmm0,-0x10(%rax)
  cmp    %rdx,%rax
  jne    L3
  mov    %ecx,%eax
  and    $0xfffffffc,%eax
  add    %eax,%r12d
  cmp    %ecx,%eax
  je     L51
L102:
  pxor   %xmm0,%xmm0
  movslq %r12d,%rdx
  mov    0x20(%rsp),%edi
  cvtsi2sd %r12d,%xmm0
  lea    0x0(,%rdx,8),%rax
  movsd  %xmm0,0x0(%rbp,%rdx,8)
  lea    0x1(%r12),%edx
  cmp    %edx,%edi
  jl     L51
  pxor   %xmm0,%xmm0
  add    $0x2,%r12d
  cvtsi2sd %edx,%xmm0
  movsd  %xmm0,0x8(%rbp,%rax,1)
  cmp    %r12d,%edi
  jl     L51
  pxor   %xmm0,%xmm0
  cvtsi2sd %r12d,%xmm0
  movsd  %xmm0,0x10(%rbp,%rax,1)
L51:
  cmpl   $0x1,0x20(%rsp)
  jle    L36
  lea    0x8(%rbp),%rax
  mov    %r13d,%r12d
  mov    %rax,0x8(%rsp)
  test   %r13d,%r13d
  je     L136
  nopl   0x0(%rax,%rax,1)
L109:
  mov    %r12d,%r15d
  mov    %r13d,%r14d
  mov    0x8(%rsp),%r11
  mov    $0x1,%r10d
  shr    $0x1f,%r15d
  add    %r12d,%r15d
  sar    %r15d
  movslq %r15d,%rdi
  mov    %edi,%r8d
  mov    %rdi,%r12
  sub    %edi,%r14d
  shl    $0x3,%rdi
  neg    %r8d
  mov    %rdi,%rsi
  movslq %r8d,%r8
  sub    %rbp,%rsi
  lea    0x0(,%r8,8),%r9
  add    %rbx,%rsi
  nopw   0x0(%rax,%rax,1)
L143:
  mov    %r11,%rax
  mov    %r10,%rdx
  jmp    L99
L95:
  lea    (%rax,%rdi,1),%rcx
  movsd  (%rax),%xmm2
  movsd  %xmm1,(%rbx,%rdx,8)
  add    %r8,%rdx
  movsd  (%rcx),%xmm1
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rsi,%rax,1)
  add    %r9,%rax
  movsd  %xmm2,(%rcx)
  test   %edx,%edx
  jle    L19
L99:
  movsd  (%rbx,%rdx,8),%xmm0
  movsd  (%rsi,%rax,1),%xmm1
  comisd %xmm0,%xmm1
  jb     L95
L19:
  add    $0x1,%r10
  add    $0x8,%r11
  cmp    %r10d,%r14d
  jg     L143
  test   %r15d,%r15d
  jne    L109
L136:
  mov    0x10(%rsp),%rdi
  lea    D216(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L141
  mov    0x10(%rsp),%r14
  xor    %eax,%eax
  sub    %rbp,%rbx
  lea    0x8(%rbp),%r15
  lea    D117(%rip),%r13
  lea    D221(%rip),%rdi
  mov    %r14,%rsi
  call   <printf@plt>
  mov    %r13,%rdi
  mov    %r12,%rcx
  mov    $0x38,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x38,%edx
  mov    $0x1,%esi
  lea    D18(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rdi
  mov    %r12,%rcx
  mov    $0x38,%edx
  mov    $0x1,%esi
  lea    D202(%rip),%r13
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x26,%edx
  mov    $0x1,%esi
  lea    D9(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  lea    D124(%rip),%rdi
  call   <fwrite@plt>
  mov    0x18(%rsp),%rdx
  mov    %r12,%rdi
  xor    %eax,%eax
  lea    D171(%rip),%rsi
  call   <fprintf@plt>
  mov    %r12,%rcx
  mov    $0x12,%edx
  mov    $0x1,%esi
  lea    D190(%rip),%rdi
  call   <fwrite@plt>
  mov    %r14,%rdx
  mov    %r12,%rdi
  xor    %eax,%eax
  lea    D154(%rip),%rsi
  call   <fprintf@plt>
  mov    %r12,%rcx
  mov    $0x13,%edx
  mov    $0x1,%esi
  lea    D48(%rip),%rdi
  call   <fwrite@plt>
  mov    0x20(%rsp),%r14d
  mov    %r12,%rdi
  xor    %eax,%eax
  lea    D136(%rip),%rsi
  mov    %r14d,%edx
  call   <fprintf@plt>
  mov    %r12,%rcx
  mov    $0x1b,%edx
  mov    $0x1,%esi
  lea    D132(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x26,%edx
  mov    $0x1,%esi
  lea    D78(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x27,%edx
  mov    $0x1,%esi
  lea    D59(%rip),%rdi
  call   <fwrite@plt>
  movsd  0x28(%rsp),%xmm0
  mov    0x24(%rsp),%edx
  mov    %r12,%rdi
  lea    D129(%rip),%rsi
  mov    $0x1,%eax
  call   <fprintf@plt>
  mov    %r12,%rcx
  mov    $0x47,%edx
  mov    $0x1,%esi
  lea    D116(%rip),%rdi
  call   <fwrite@plt>
  mov    %r12,%rcx
  mov    $0x48,%edx
  mov    $0x1,%esi
  lea    D91(%rip),%rdi
  call   <fwrite@plt>
  movslq %r14d,%rax
  mov    %rbp,0x8(%rsp)
  lea    0x0(%rbp,%rax,8),%r14
  lea    0x58(%rbp),%rax
  mov    %rbx,%rbp
  mov    %rax,%rbx
  nopw   0x0(%rax,%rax,1)
L104:
  movsd  (%r14),%xmm2
  movsd  (%r15),%xmm0
  mov    %r13,%rsi
  mov    %r12,%rdi
  movsd  0x0(%rbp,%r14,1),%xmm3
  movsd  0x0(%rbp,%r15,1),%xmm1
  mov    $0x4,%eax
  add    $0x8,%r15
  sub    $0x8,%r14
  call   <fprintf@plt>
  cmp    %r15,%rbx
  jne    L104
  mov    0x8(%rsp),%rbp
  mov    %r12,%rdi
  call   <fclose@plt>
  lea    D53(%rip),%rdi
  call   <puts@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  xor    %eax,%eax
L34:
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L36:
  lea    D107(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L34
L141:
  mov    0x10(%rsp),%rsi
  lea    D149(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0xffffffff,%eax
  jmp    L34
```

tool_calls: name: retrieve_data
arguments: label: D180
data_type: byte[16]
name: retrieve_data
arguments: label: D200
data_type: byte[16]
name: retrieve_data
arguments: label: D216
data_type: string
name: retrieve_data
arguments: label: D117
data_type: string
name: retrieve_data
arguments: label: D221
data_type: string
name: retrieve_data
arguments: label: D18
data_type: string
name: retrieve_data
arguments: label: D202
data_type: string
name: retrieve_data
arguments: label: D9
data_type: string
name: retrieve_data
arguments: label: D124
data_type: string
name: retrieve_data
arguments: label: D171
data_type: string
name: retrieve_data
arguments: label: D190
data_type: string
name: retrieve_data
arguments: label: D154
data_type: string
name: retrieve_data
arguments: label: D48
data_type: string
name: retrieve_data
arguments: label: D136
data_type: string
name: retrieve_data
arguments: label: D132
data_type: string
name: retrieve_data
arguments: label: D78
data_type: string
name: retrieve_data
arguments: label: D59
data_type: string
name: retrieve_data
arguments: label: D129
data_type: string
name: retrieve_data
arguments: label: D116
data_type: string
name: retrieve_data
arguments: label: D91
data_type: string
name: retrieve_data
arguments: label: D53
data_type: string
name: retrieve_data
arguments: label: D107
data_type: string
name: retrieve_data
arguments: label: D149
data_type: string

tool: {"D180": [0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00]}

tool: {"D200": [0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00]}

tool: D216: w

tool: D117:                ----------------------------------------


tool: D221: Writing data to %s: 

tool: D18:                - AVL -  Linear Equation Solver - GCCG -


tool: D202: %lf %lf %lf %lf


tool: D9:                      diagonal scaling


tool: D124: 



tool: D171:      Input File:  %s


tool: D190:      ===========



tool: D154:      Output File:  %s


tool: D48:      ============



tool: D136:      No. of Active Cells:  %d


tool: D132:      ====================



tool: D78:      Iteration Count - Residual Ratio


tool: D59:      ================================



tool: D129: %d %e


tool: D116:      Addresses Solution (Minima)           Addresses Solution (Maxima)


tool: D91:      ===========================           ===========================



tool: D53: done!

tool: D107: error: nintcf <= 1

tool: D149: error opening file %s for writing


assistant: ```c
int write_result(char *infilename, char *outfilename, int nintci, int nintcf, double *var, int iter, double ratio) {
  double *ipoint = (double *)malloc((nintcf + 1) * sizeof(double));
  int i1, i2, i3, i4, i5;
  int nc;
  for (nc = nintci; nc <= nintcf; nc++)
    ipoint[nc] = nc;
  if (nintcf <= 1) {
    printf("error: nintcf <= 1\n");
    return -1;
  }
  i1 = nintcf + 1;
  while (i1 != 0) {
    i1 = i1 / 2;
    i2 = nintcf + 1 - i1;
    i4 = 1;
    do {
      i3 = i4;
      do {
        i5 = i3 + i1;
        if (var[i3] <= var[i5])
          break;
        double zdum = var[i3], idum = ipoint[i3];
        var[i3] = var[i5];
        ipoint[i3] = ipoint[i5];
        var[i5] = zdum;
        ipoint[i5] = idum;
        i3 = i3 - i1;
      } while (i3 >= 1);
      i4++;
    } while (i4 < i2);
  }
  FILE *fp = fopen(outfilename, "w");
  if (fp == NULL) {
    printf("error opening file %s for writing\n", outfilename);
    return -1;
  }
  printf("Writing data to %s: ", outfilename);
  fprintf(fp, "               ----------------------------------------\n");
  fprintf(fp, "               - AVL -  Linear Equation Solver - GCCG -\n");
  fprintf(fp, "               ----------------------------------------\n");
  fprintf(fp, "                     diagonal scaling\n");
  fprintf(fp, "\n\n");
  fprintf(fp, "     Input File:  %s\n", infilename);
  fprintf(fp, "     ===========\n\n");
  fprintf(fp, "     Output File:  %s\n", outfilename);
  fprintf(fp, "     ============\n\n");
  fprintf(fp, "     No. of Active Cells:  %d\n", nintcf);
  fprintf(fp, "     ====================\n\n");
  fprintf(fp, "     Iteration Count - Residual Ratio\n");
  fprintf(fp, "     ================================\n\n");
  fprintf(fp, "%d %e\n", iter, ratio);
  fprintf(fp, "     Addresses Solution (Minima)           Addresses Solution (Maxima)\n");
  fprintf(fp, "     ===========================           ===========================\n\n");
  int n;
  for (n = 1; n <= 10; n++)
    fprintf(fp, "%lf %lf %lf %lf\n", ipoint[n], var[n], ipoint[nintcf - n + 1], var[nintcf - n + 1]);
  fclose(fp);
  printf("done!\n");
  free(ipoint);
  return 0;
}
```