user: Converte this assembly snippet into its equivalent C code:

```asm
<chi2>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,-0x34(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %r8,-0x58(%rbp)
  mov    %r9,-0x60(%rbp)
  mov    -0x58(%rbp),%rax
  movsd  D27(%rip),%xmm0
  movsd  %xmm0,(%rax)
  mov    -0x60(%rbp),%rax
  movl   $0x0,(%rax)
  cmpl   $0x0,-0x34(%rbp)
  jle    L61
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x28(%rbp)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  movl   $0x0,-0x2c(%rbp)
  jmp    L14
L4:
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  ucomisd %xmm0,%xmm0
  jp     L41
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L41
  mov    -0x60(%rbp),%rax
  mov    (%rax),%eax
  lea    0x1(%rax),%edx
  mov    -0x60(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbp)
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  divsd  -0x8(%rbp),%xmm0
  movsd  -0x28(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x28(%rbp)
  movsd  D8(%rip),%xmm0
  divsd  -0x8(%rbp),%xmm0
  movsd  -0x20(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x20(%rbp)
L41:
  addl   $0x1,-0x2c(%rbp)
L14:
  mov    -0x2c(%rbp),%eax
  cmp    -0x34(%rbp),%eax
  jl     L4
  movsd  -0x20(%rbp),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L97
  movsd  -0x28(%rbp),%xmm0
  divsd  -0x20(%rbp),%xmm0
  movsd  %xmm0,-0x10(%rbp)
  mov    -0x58(%rbp),%rax
  movsd  -0x10(%rbp),%xmm0
  movsd  %xmm0,(%rax)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  movl   $0x0,-0x2c(%rbp)
  jmp    L21
L47:
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  ucomisd %xmm0,%xmm0
  jp     L54
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L54
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  subsd  -0x10(%rbp),%xmm0
  movsd  %xmm0,-0x8(%rbp)
  movsd  -0x8(%rbp),%xmm0
  mulsd  %xmm0,%xmm0
  movsd  %xmm0,-0x8(%rbp)
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mulsd  %xmm0,%xmm1
  movsd  -0x8(%rbp),%xmm0
  divsd  %xmm1,%xmm0
  movsd  -0x18(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
L54:
  addl   $0x1,-0x2c(%rbp)
L21:
  mov    -0x2c(%rbp),%eax
  cmp    -0x34(%rbp),%eax
  jl     L47
  jmp    L9
L97:
  movsd  D27(%rip),%xmm0
  movsd  %xmm0,-0x18(%rbp)
  jmp    L9
L61:
  movsd  D27(%rip),%xmm0
  movsd  %xmm0,-0x18(%rbp)
L9:
  movsd  -0x18(%rbp),%xmm0
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  pop    %rbp
  ret
```

tool_calls: name: extract_symbolic_data
arguments: label: D27
data_type: f32[2]
name: extract_symbolic_data
arguments: label: D8
data_type: f64

tool: {"D27": [0.0,-1.875]}

tool: D8: 1

assistant: ```c
double chi2(int N, double *t, double *mag, double *sig, double *aveval, int *ngood) {
  double avesum1, avesum2, ave, chi2val, v;
  int i;
  *aveval = -1.;
  *ngood = 0;
  if (N > 0) {
    avesum1 = 0.;
    avesum2 = 0.;
    for (i = 0; i < N; i++) {
      if (!isnan(mag[i]) && sig[i] > 0.) {
        (*ngood)++;
        v = sig[i] * sig[i];
        avesum1 += mag[i] / v;
        avesum2 += 1. / v;
      }
    }
    if (avesum2 > 0.) {
      ave = (avesum1 / avesum2);
      *aveval = ave;
      chi2val = 0.;
      for (i = 0; i < N; i++) {
        if (!isnan(mag[i]) && sig[i] > 0.) {
          v = (mag[i] - ave);
          v = v * v;
          chi2val += v / (sig[i] * sig[i]);
        }
      }
    } else
      chi2val = -1.;
  } else
    chi2val = -1.;
  return (chi2val);
}
```