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

```asm
<core_site_likelihood_derivatives>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    0x48(%rsp),%r10
  mov    0x38(%rsp),%r11
  mov    0x40(%rsp),%rax
  movq   $0x0,0x10(%r10)
  movq   $0x0,0x8(%r10)
  movq   $0x0,(%r10)
  test   %edx,%edx
  je     L40
  mov    %edi,%ebx
  mov    %esi,%edi
  mov    %r8,%r13
  sub    $0x1,%edx
  lea    0x0(,%rdi,8),%r8
  lea    -0x1(%rbx),%ebp
  pxor   %xmm5,%xmm5
  mov    0x30(%rsp),%rdi
  add    $0x1,%rbp
  movapd %xmm5,%xmm8
  movapd %xmm5,%xmm7
  mov    %rcx,%rsi
  lea    0x8(%rdi,%rdx,8),%r14
  shl    $0x5,%rbp
  movapd %xmm5,%xmm6
  movsd  D4(%rip),%xmm9
  xchg   %ax,%ax
L49:
  mov    (%rdi),%r12
  test   %ebx,%ebx
  je     L59
  lea    (%rax,%rbp,1),%rcx
  movapd %xmm5,%xmm3
  movapd %xmm5,%xmm2
  mov    %r11,%rdx
  movapd %xmm5,%xmm1
  xchg   %ax,%ax
L10:
  movsd  (%rdx),%xmm0
  movsd  (%rax),%xmm4
  add    $0x20,%rax
  add    $0x8,%rdx
  mulsd  %xmm0,%xmm4
  addsd  %xmm4,%xmm1
  movsd  -0x18(%rax),%xmm4
  mulsd  %xmm0,%xmm4
  mulsd  -0x10(%rax),%xmm0
  addsd  %xmm4,%xmm3
  addsd  %xmm0,%xmm2
  cmp    %rax,%rcx
  jne    L10
L42:
  movsd  (%r9),%xmm0
  comisd %xmm5,%xmm0
  jbe    L29
  movslq 0x0(%r13),%rdx
  movapd %xmm5,%xmm10
  cmp    $0xffffffff,%edx
  je     L61
  movsd  (%r12,%rdx,8),%xmm10
  mulsd  %xmm0,%xmm10
L61:
  movapd %xmm9,%xmm4
  subsd  %xmm0,%xmm4
  mulsd  %xmm4,%xmm1
  mulsd  %xmm4,%xmm3
  mulsd  %xmm4,%xmm2
  addsd  %xmm10,%xmm1
L29:
  mulsd  (%rsi),%xmm1
  add    $0x8,%rdi
  add    %r8,%r11
  add    $0x8,%rsi
  add    $0x8,%r9
  addsd  %xmm1,%xmm6
  movsd  %xmm6,(%r10)
  mulsd  -0x8(%rsi),%xmm3
  addsd  %xmm3,%xmm7
  movsd  %xmm7,0x8(%r10)
  mulsd  -0x8(%rsi),%xmm2
  addsd  %xmm2,%xmm8
  movsd  %xmm8,0x10(%r10)
  cmp    %r14,%rdi
  jne    L49
L40:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  xchg   %ax,%ax
L59:
  movapd %xmm5,%xmm3
  movapd %xmm5,%xmm2
  movapd %xmm5,%xmm1
  jmp    L42
```

tool_calls: name: extract_symbolic_data
arguments: tag: D4
type_guessed: f64

tool: D4: 1

assistant: ```c
void core_site_likelihood_derivatives(unsigned int states, unsigned int states_padded, unsigned int rate_cats, const double *rate_weights, const int *invariant, const double *prop_invar, double *const *freqs, const double *sumtable, const double *diagptable, double *site_lk) {
  unsigned int i, j;
  double inv_site_lk = 0.0;
  double cat_sitelk[3];
  const double *sum = sumtable;
  const double *diagp = diagptable;
  const double *t_freqs;
  double t_prop_invar;
  site_lk[0] = site_lk[1] = site_lk[2] = 0;
  for (i = 0; i < rate_cats; ++i) {
    t_freqs = freqs[i];
    cat_sitelk[0] = cat_sitelk[1] = cat_sitelk[2] = 0;
    for (j = 0; j < states; ++j) {
      cat_sitelk[0] += sum[j] * diagp[0];
      cat_sitelk[1] += sum[j] * diagp[1];
      cat_sitelk[2] += sum[j] * diagp[2];
      diagp += 4;
    }
    t_prop_invar = prop_invar[i];
    if (t_prop_invar > 0) {
      inv_site_lk = (invariant[0] == -1) ? 0 : t_freqs[invariant[0]] * t_prop_invar;
      cat_sitelk[0] = cat_sitelk[0] * (1. - t_prop_invar) + inv_site_lk;
      cat_sitelk[1] = cat_sitelk[1] * (1. - t_prop_invar);
      cat_sitelk[2] = cat_sitelk[2] * (1. - t_prop_invar);
    }
    site_lk[0] += cat_sitelk[0] * rate_weights[i];
    site_lk[1] += cat_sitelk[1] * rate_weights[i];
    site_lk[2] += cat_sitelk[2] * rate_weights[i];
    sum += states_padded;
  }
}
```