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

```asm
<cg_update_2>:
  endbr64
  mov    %rdx,%r8
  movabs $0x6666666666666667,%rdx
  mov    %rcx,%rax
  imul   %rdx
  sar    %rdx
  mov    %rcx,%rax
  sar    $0x3f,%rax
  sub    %rax,%rdx
  lea    (%rdx,%rdx,4),%rax
  mov    %rcx,%rdx
  sub    %rax,%rdx
  test   %r8,%r8
  je     L57
  test   %rdi,%rdi
  je     L78
  test   %rdx,%rdx
  jle    L92
  pxor   %xmm0,%xmm0
  mov    $0x0,%eax
  movq   D12(%rip),%xmm3
L96:
  movsd  (%rsi,%rax,8),%xmm1
  movapd %xmm1,%xmm2
  mulsd  %xmm1,%xmm2
  addsd  %xmm2,%xmm0
  movsd  %xmm1,(%rdi,%rax,8)
  xorpd  %xmm3,%xmm1
  movsd  %xmm1,(%r8,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rdx
  jne    L96
L115:
  cmp    %rdx,%rcx
  jle    L94
  movq   D12(%rip),%xmm2
L18:
  movsd  (%rsi,%rdx,8),%xmm1
  movapd %xmm1,%xmm3
  mulsd  %xmm1,%xmm3
  movapd %xmm3,%xmm4
  addsd  %xmm0,%xmm4
  movsd  %xmm1,(%rdi,%rdx,8)
  xorpd  %xmm2,%xmm1
  movsd  %xmm1,(%r8,%rdx,8)
  movsd  0x8(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm3
  mulsd  %xmm0,%xmm3
  addsd  %xmm4,%xmm3
  movsd  %xmm0,0x8(%rdi,%rdx,8)
  xorpd  %xmm2,%xmm0
  movsd  %xmm0,0x8(%r8,%rdx,8)
  movsd  0x10(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm1
  mulsd  %xmm0,%xmm1
  addsd  %xmm3,%xmm1
  movsd  %xmm0,0x10(%rdi,%rdx,8)
  xorpd  %xmm2,%xmm0
  movsd  %xmm0,0x10(%r8,%rdx,8)
  movsd  0x18(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm3
  mulsd  %xmm0,%xmm3
  addsd  %xmm1,%xmm3
  movsd  %xmm0,0x18(%rdi,%rdx,8)
  xorpd  %xmm2,%xmm0
  movsd  %xmm0,0x18(%r8,%rdx,8)
  movsd  0x20(%rsi,%rdx,8),%xmm1
  movapd %xmm1,%xmm0
  mulsd  %xmm1,%xmm0
  addsd  %xmm3,%xmm0
  movsd  %xmm1,0x20(%rdi,%rdx,8)
  xorpd  %xmm2,%xmm1
  movsd  %xmm1,0x20(%r8,%rdx,8)
  add    $0x5,%rdx
  cmp    %rdx,%rcx
  jg     L18
  ret
L57:
  test   %rdx,%rdx
  jle    L23
  pxor   %xmm0,%xmm0
  mov    $0x0,%eax
L124:
  movsd  (%rsi,%rax,8),%xmm1
  movapd %xmm1,%xmm2
  mulsd  %xmm1,%xmm2
  addsd  %xmm2,%xmm0
  movsd  %xmm1,(%rdi,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rdx
  jne    L124
L10:
  cmp    %rdx,%rcx
  jle    L94
L123:
  movsd  (%rsi,%rdx,8),%xmm2
  movapd %xmm2,%xmm1
  mulsd  %xmm2,%xmm1
  addsd  %xmm0,%xmm1
  movsd  %xmm2,(%rdi,%rdx,8)
  movsd  0x8(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm2
  mulsd  %xmm0,%xmm2
  addsd  %xmm1,%xmm2
  movsd  %xmm0,0x8(%rdi,%rdx,8)
  movsd  0x10(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm1
  mulsd  %xmm0,%xmm1
  addsd  %xmm2,%xmm1
  movsd  %xmm0,0x10(%rdi,%rdx,8)
  movsd  0x18(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm2
  mulsd  %xmm0,%xmm2
  addsd  %xmm1,%xmm2
  movsd  %xmm0,0x18(%rdi,%rdx,8)
  movsd  0x20(%rsi,%rdx,8),%xmm1
  movapd %xmm1,%xmm0
  mulsd  %xmm1,%xmm0
  addsd  %xmm2,%xmm0
  movsd  %xmm1,0x20(%rdi,%rdx,8)
  add    $0x5,%rdx
  cmp    %rdx,%rcx
  jg     L123
  ret
L23:
  pxor   %xmm0,%xmm0
  mov    $0x0,%edx
  jmp    L10
L78:
  pxor   %xmm0,%xmm0
  mov    $0x0,%eax
  movq   D12(%rip),%xmm3
  test   %rdx,%rdx
  jle    L120
L64:
  movsd  (%rsi,%rax,8),%xmm1
  movapd %xmm1,%xmm2
  mulsd  %xmm1,%xmm2
  addsd  %xmm2,%xmm0
  xorpd  %xmm3,%xmm1
  movsd  %xmm1,(%r8,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rdx
  jne    L64
L52:
  cmp    %rdx,%rcx
  jle    L94
  movq   D12(%rip),%xmm2
L99:
  movsd  (%rsi,%rdx,8),%xmm1
  movapd %xmm1,%xmm3
  mulsd  %xmm1,%xmm3
  movapd %xmm3,%xmm4
  addsd  %xmm0,%xmm4
  xorpd  %xmm2,%xmm1
  movsd  %xmm1,(%r8,%rdx,8)
  movsd  0x8(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm3
  mulsd  %xmm0,%xmm3
  addsd  %xmm4,%xmm3
  xorpd  %xmm2,%xmm0
  movsd  %xmm0,0x8(%r8,%rdx,8)
  movsd  0x10(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm1
  mulsd  %xmm0,%xmm1
  addsd  %xmm3,%xmm1
  xorpd  %xmm2,%xmm0
  movsd  %xmm0,0x10(%r8,%rdx,8)
  movsd  0x18(%rsi,%rdx,8),%xmm0
  movapd %xmm0,%xmm3
  mulsd  %xmm0,%xmm3
  addsd  %xmm1,%xmm3
  xorpd  %xmm2,%xmm0
  movsd  %xmm0,0x18(%r8,%rdx,8)
  movsd  0x20(%rsi,%rdx,8),%xmm1
  movapd %xmm1,%xmm0
  mulsd  %xmm1,%xmm0
  addsd  %xmm3,%xmm0
  xorpd  %xmm2,%xmm1
  movsd  %xmm1,0x20(%r8,%rdx,8)
  add    $0x5,%rdx
  cmp    %rdx,%rcx
  jg     L99
L94:
  ret
L120:
  mov    $0x0,%edx
  jmp    L52
L92:
  pxor   %xmm0,%xmm0
  mov    $0x0,%edx
  jmp    L115
```

tool_calls: name: unpack_data
arguments: data_tag: D12
type_guessed: byte[8]

tool: {"D12": [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80]}

assistant: ```c
double cg_update_2(double *gold, double *gnew, double *d, long int n) {
  long int i, n5;
  double s, t;
  t = ((double)0);
  n5 = n % 5;
  if (d == 0) {
    for (i = 0; i < n5; i++) {
      s = gnew[i];
      t += s * s;
      gold[i] = s;
    }
    for (; i < n;) {
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      i++;
    }
  } else if (gold != 0) {
    for (i = 0; i < n5; i++) {
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      d[i] = -s;
    }
    for (; i < n;) {
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      gold[i] = s;
      d[i] = -s;
      i++;
    }
  } else {
    for (i = 0; i < n5; i++) {
      s = gnew[i];
      t += s * s;
      d[i] = -s;
    }
    for (; i < n;) {
      s = gnew[i];
      t += s * s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      d[i] = -s;
      i++;
      s = gnew[i];
      t += s * s;
      d[i] = -s;
      i++;
    }
  }
  return (t);
}
```