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

```asm
<write_result>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,0x8(%rsp)
  mov    %rsi,(%rsp)
  mov    %edx,%r12d
  mov    %ecx,%r14d
  mov    %ecx,0x10(%rsp)
  mov    %r8,%rbx
  mov    %r9d,0x14(%rsp)
  movsd  %xmm0,0x18(%rsp)
  lea    0x1(%rcx),%ebp
  lea    0x0(,%rbp,8),%edi
  call   <malloc@plt>
  mov    %rax,%r15
  cmp    %r12d,%r14d
  jl     L19
  movslq %r12d,%rax
  lea    (%r15,%rax,8),%rax
  mov    %ebp,%edx
L51:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r12d,%xmm0
  movsd  %xmm0,(%rax)
  add    $0x1,%r12d
  add    $0x8,%rax
  cmp    %edx,%r12d
  jne    L51
L19:
  cmpl   $0x1,0x10(%rsp)
  jle    L25
  mov    %ebp,%r13d
  test   %ebp,%ebp
  jne    L53
L58:
  lea    D132(%rip),%rsi
  mov    (%rsp),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L45
  mov    (%rsp),%r14
  mov    %r14,%rsi
  lea    D177(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    %r13,%rcx
  mov    $0x38,%edx
  mov    $0x1,%esi
  lea    D207(%rip),%rbp
  mov    %rbp,%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x38,%edx
  mov    $0x1,%esi
  lea    D185(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x38,%edx
  mov    $0x1,%esi
  mov    %rbp,%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x26,%edx
  mov    $0x1,%esi
  lea    D127(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  lea    D202(%rip),%rdi
  call   <fwrite@plt>
  mov    0x8(%rsp),%rdx
  lea    D153(%rip),%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %r13,%rcx
  mov    $0x12,%edx
  mov    $0x1,%esi
  lea    D48(%rip),%rdi
  call   <fwrite@plt>
  mov    %r14,%rdx
  lea    D115(%rip),%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %r13,%rcx
  mov    $0x13,%edx
  mov    $0x1,%esi
  lea    D103(%rip),%rdi
  call   <fwrite@plt>
  mov    0x10(%rsp),%r14d
  mov    %r14d,%edx
  lea    D137(%rip),%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %r13,%rcx
  mov    $0x1b,%edx
  mov    $0x1,%esi
  lea    D1(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x26,%edx
  mov    $0x1,%esi
  lea    D62(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x27,%edx
  mov    $0x1,%esi
  lea    D55(%rip),%rdi
  call   <fwrite@plt>
  movsd  0x18(%rsp),%xmm0
  mov    0x14(%rsp),%edx
  lea    D54(%rip),%rsi
  mov    %r13,%rdi
  mov    $0x1,%eax
  call   <fprintf@plt>
  mov    %r13,%rcx
  mov    $0x47,%edx
  mov    $0x1,%esi
  lea    D44(%rip),%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x48,%edx
  mov    $0x1,%esi
  lea    D28(%rip),%rdi
  call   <fwrite@plt>
  movslq %r14d,%rax
  lea    (%r15,%rax,8),%r12
  lea    0x8(%r15),%rbp
  lea    0x58(%r15),%r14
L112:
  mov    %rbx,%rax
  sub    %r15,%rax
  movsd  (%rax,%r12,1),%xmm3
  movsd  (%r12),%xmm2
  movsd  (%rax,%rbp,1),%xmm1
  movsd  0x0(%rbp),%xmm0
  lea    D90(%rip),%rsi
  mov    %r13,%rdi
  mov    $0x4,%eax
  call   <fprintf@plt>
  sub    $0x8,%r12
  add    $0x8,%rbp
  cmp    %r14,%rbp
  jne    L112
  mov    %r13,%rdi
  call   <fclose@plt>
  lea    D46(%rip),%rdi
  call   <puts@plt>
  mov    %r15,%rdi
  call   <free@plt>
  mov    $0x0,%eax
L117:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L25:
  lea    D25(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L117
L61:
  add    $0x1,%r10
  add    $0x8,%r11
  cmp    %r10d,%r12d
  jle    L14
L93:
  mov    %r11,%rax
  mov    %r10,%rdx
L7:
  movsd  (%rbx,%rdx,8),%xmm0
  movsd  (%rsi,%rax,1),%xmm1
  comisd %xmm0,%xmm1
  jae    L61
  movsd  (%rax),%xmm2
  movsd  %xmm1,(%rbx,%rdx,8)
  lea    (%rax,%rdi,1),%rcx
  movsd  (%rcx),%xmm1
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rsi,%rax,1)
  movsd  %xmm2,(%rcx)
  add    %r8,%rdx
  add    %r9,%rax
  test   %edx,%edx
  jg     L7
  jmp    L61
L14:
  test   %r14d,%r14d
  je     L58
L53:
  mov    %r13d,%r14d
  shr    $0x1f,%r14d
  add    %r13d,%r14d
  sar    %r14d
  mov    %r14d,%r13d
  mov    %ebp,%r12d
  sub    %r14d,%r12d
  lea    0x8(%r15),%r11
  mov    %r14d,%r8d
  neg    %r8d
  movslq %r8d,%r8
  lea    0x0(,%r8,8),%r9
  movslq %r14d,%rdi
  shl    $0x3,%rdi
  mov    %rdi,%rsi
  sub    %r15,%rsi
  add    %rbx,%rsi
  mov    $0x1,%r10d
  jmp    L93
L45:
  mov    (%rsp),%rsi
  lea    D167(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0xffffffff,%eax
  jmp    L117
```

tool_calls: name: unpack_data
arguments: label: D132
data_type: string
name: unpack_data
arguments: label: D177
data_type: string
name: unpack_data
arguments: label: D207
data_type: string
name: unpack_data
arguments: label: D185
data_type: string
name: unpack_data
arguments: label: D127
data_type: string
name: unpack_data
arguments: label: D202
data_type: string
name: unpack_data
arguments: label: D153
data_type: string
name: unpack_data
arguments: label: D48
data_type: string
name: unpack_data
arguments: label: D115
data_type: string
name: unpack_data
arguments: label: D103
data_type: string
name: unpack_data
arguments: label: D137
data_type: string
name: unpack_data
arguments: label: D1
data_type: string
name: unpack_data
arguments: label: D62
data_type: string
name: unpack_data
arguments: label: D55
data_type: string
name: unpack_data
arguments: label: D54
data_type: string
name: unpack_data
arguments: label: D44
data_type: string
name: unpack_data
arguments: label: D28
data_type: string
name: unpack_data
arguments: label: D90
data_type: string
name: unpack_data
arguments: label: D46
data_type: string
name: unpack_data
arguments: label: D25
data_type: string
name: unpack_data
arguments: label: D167
data_type: string

tool: D132: w

tool: D177: Writing data to %s: 

tool: D207:                ----------------------------------------


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


tool: D127:                      diagonal scaling


tool: D202: 



tool: D153:      Input File:  %s


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



tool: D115:      Output File:  %s


tool: D103:      ============



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


tool: D1:      ====================



tool: D62:      Iteration Count - Residual Ratio


tool: D55:      ================================



tool: D54: %d %e


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


tool: D28:      ===========================           ===========================



tool: D90: %lf %lf %lf %lf


tool: D46: done!

tool: D25: error: nintcf <= 1

tool: D167: 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;
}
```