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

```asm
<ess>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%r12
  mov    %rdx,0x8(%rsp)
  lea    -0x1(%rsi),%r13
  mov    %r13,%rdi
  call   <dvector@plt>
  mov    %rax,%r14
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <dmean@plt>
  test   %r13,%r13
  je     L147
  mov    %r14,%rdx
  lea    0x0(%rbp,%r12,8),%rcx
  mov    %r12,%rsi
  mov    $0x0,%ebx
  mov    D2(%rip),%r15
  movq   %r15,%xmm3
  jmp    L258
L55:
  mov    %rax,%r8
  shr    %r8
  and    $0x1,%eax
  or     %rax,%r8
  pxor   %xmm2,%xmm2
  cvtsi2sd %r8,%xmm2
  addsd  %xmm2,%xmm2
  jmp    L89
L165:
  test   $0x1,%bl
  jne    L276
  addsd  -0x8(%rdi),%xmm1
  comisd %xmm3,%xmm1
  jbe    L24
  addsd  %xmm1,%xmm1
  movq   %r15,%xmm4
  addsd  %xmm1,%xmm4
  movq   %xmm4,%r15
L276:
  add    $0x1,%rbx
  sub    $0x1,%rsi
  add    $0x8,%rdx
  sub    $0x8,%rcx
  cmp    %rbx,%r13
  je     L24
L258:
  mov    %rbp,%rax
  test   %rsi,%rsi
  je     L152
L279:
  movsd  (%rax),%xmm1
  subsd  %xmm0,%xmm1
  movsd  (%rax,%rbx,8),%xmm2
  subsd  %xmm0,%xmm2
  mulsd  %xmm2,%xmm1
  addsd  (%rdx),%xmm1
  movsd  %xmm1,(%rdx)
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L279
  mov    %rsi,%rax
L58:
  mov    %rdx,%rdi
  test   %rax,%rax
  js     L55
  pxor   %xmm2,%xmm2
  cvtsi2sd %rax,%xmm2
L89:
  movsd  (%rdi),%xmm1
  divsd  %xmm2,%xmm1
  movsd  %xmm1,(%rdi)
  test   %rbx,%rbx
  jne    L165
  mov    (%r14),%r15
  jmp    L276
L152:
  mov    %rsi,%rax
  jmp    L58
L24:
  test   %r12,%r12
  js     L90
  pxor   %xmm7,%xmm7
  cvtsi2sd %r12,%xmm7
  movsd  %xmm7,(%rsp)
L287:
  movq   %r15,%xmm0
  divsd  (%rsp),%xmm0
  pxor   %xmm1,%xmm1
  ucomisd %xmm0,%xmm1
  ja     L83
L215:
  movsd  (%r14),%xmm1
  ucomisd D2(%rip),%xmm1
  jp     L45
  mov    D88(%rip),%rbp
  je     L19
L45:
  mov    0x8(%rsp),%rax
  test   %rax,%rax
  js     L85
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
L111:
  movq   %r15,%xmm7
  mulsd  %xmm7,%xmm0
  divsd  %xmm1,%xmm0
  ucomisd D2(%rip),%xmm0
  jp     L283
  je     L201
L283:
  imul   0x8(%rsp),%r12
  test   %r12,%r12
  js     L275
  pxor   %xmm1,%xmm1
  cvtsi2sd %r12,%xmm1
L196:
  divsd  %xmm0,%xmm1
  movq   %xmm1,%rbp
L19:
  add    $0x1,%rbx
  js     L46
  pxor   %xmm0,%xmm0
  cvtsi2sd %rbx,%xmm0
L298:
  addsd  %xmm0,%xmm0
  addsd  %xmm0,%xmm0
  divsd  (%rsp),%xmm0
  pxor   %xmm1,%xmm1
  ucomisd %xmm0,%xmm1
  ja     L6
L7:
  movq   %rbp,%xmm0
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L90:
  mov    %r12,%rax
  shr    %rax
  mov    %r12,%rdx
  and    $0x1,%edx
  or     %rdx,%rax
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  addsd  %xmm0,%xmm0
  movsd  %xmm0,(%rsp)
  jmp    L287
L83:
  call   <sqrt@plt>
  jmp    L215
L85:
  mov    0x8(%rsp),%rsi
  mov    %rsi,%rax
  shr    %rax
  and    $0x1,%esi
  or     %rsi,%rax
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  addsd  %xmm0,%xmm0
  jmp    L111
L275:
  mov    %r12,%rax
  shr    %rax
  and    $0x1,%r12d
  or     %r12,%rax
  pxor   %xmm1,%xmm1
  cvtsi2sd %rax,%xmm1
  addsd  %xmm1,%xmm1
  jmp    L196
L201:
  mov    D88(%rip),%rbp
  jmp    L19
L46:
  mov    %rbx,%rax
  shr    %rax
  and    $0x1,%ebx
  or     %rbx,%rax
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  addsd  %xmm0,%xmm0
  jmp    L298
L6:
  call   <sqrt@plt>
  jmp    L7
L147:
  movsd  (%r14),%xmm1
  ucomisd D2(%rip),%xmm1
  jp     L118
  mov    D88(%rip),%rbp
  je     L7
L118:
  mov    %r13,%rbx
  mov    D2(%rip),%r15
  movsd  D88(%rip),%xmm5
  movsd  %xmm5,(%rsp)
  jmp    L45
```

tool_calls: name: parse_data
arguments: tag: D2
type: f64
name: parse_data
arguments: tag: D88
type: f64

tool: D2: 0

tool: D88: 1

assistant: ```c
double ess(double *values, size_t samples, size_t stepSize) {
  size_t maxLag = samples - 1;
  double *gammaStat = dvector(maxLag);
  double varStat = 0.0;
  double mean = dmean(values, samples);
  for (size_t lag = 0; lag < maxLag; lag++) {
    for (size_t j = 0; j < samples - lag; j++) {
      double del1 = values[j] - mean;
      double del2 = values[j + lag] - mean;
      gammaStat[lag] += (del1 * del2);
    }
    gammaStat[lag] /= ((double)(samples - lag));
    if (lag == 0) {
      varStat = gammaStat[0];
    } else if (lag % 2 == 0) {
      if (gammaStat[lag - 1] + gammaStat[lag] > 0) {
        varStat += 2.0 * (gammaStat[lag - 1] + gammaStat[lag]);
      } else
        maxLag = lag;
    }
  }
  double stdErrorOfMean = sqrt(varStat / samples);
  double ACT;
  double ESS;
  if (gammaStat[0] == 0)
    ACT = 0;
  else
    ACT = stepSize * varStat / gammaStat[0];
  if (ACT == 0)
    ESS = 1;
  else
    ESS = (stepSize * samples) / ACT;
  double stdErrOfACT = (2.0 * sqrt(2.0 * (2.0 * (double)(maxLag + 1)) / samples) * (varStat / gammaStat[0]) * stepSize);
  return ESS;
}
```