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

```asm
<def_hat>:
  endbr64
  push   %rbp
  movslq %edi,%r10
  mov    %edx,%r11d
  mov    %r9,%rax
  mov    %rsp,%rbp
  push   %r15
  mov    %r10,%r15
  push   %r14
  push   %r13
  push   %r12
  mov    %r8,%r12
  push   %rbx
  mov    %rcx,%rbx
  sub    $0xa8,%rsp
  mov    0x20(%rbp),%rdi
  mov    %esi,-0xb8(%rbp)
  mov    %edx,-0x44(%rbp)
  mov    %rsp,%r8
  mov    0x10(%rbp),%rdx
  mov    %rdi,-0xc0(%rbp)
  mov    0x28(%rbp),%rdi
  movsd  %xmm0,-0xc8(%rbp)
  mov    0x18(%rbp),%r13
  mov    %rdi,-0x98(%rbp)
  mov    0x30(%rbp),%rdi
  mov    %rdi,-0xa8(%rbp)
  mov    %esi,%edi
  imul   %r10d,%esi
  add    %edi,%edi
  mov    %fs:0x28,%rcx
  mov    %rcx,-0x38(%rbp)
  xor    %ecx,%ecx
  mov    %edi,-0x58(%rbp)
  lea    0x1(%r11),%edi
  mov    %edi,-0x50(%rbp)
  lea    0x0(,%r10,8),%rdi
  lea    0xf(%rdi),%rcx
  mov    %rdi,-0x90(%rbp)
  mov    %rcx,%rdi
  mov    %rcx,%r9
  and    $0xfffffffffffff000,%rdi
  and    $0xfffffffffffffff0,%r9
  sub    %rdi,%r8
  cmp    %r8,%rsp
  je     L171
L281:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %r8,%rsp
  jne    L281
L171:
  and    $0xfff,%r9d
  sub    %r9,%rsp
  test   %r9,%r9
  jne    L356
L159:
  mov    %rcx,%r8
  mov    %rsp,%rdi
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,-0x80(%rbp)
  sub    %rcx,%rdi
  and    $0xfffffffffffffff0,%r8
  cmp    %rdi,%rsp
  je     L360
L100:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rdi,%rsp
  jne    L100
L360:
  and    $0xfff,%r8d
  sub    %r8,%rsp
  test   %r8,%r8
  jne    L256
L205:
  mov    %rsp,-0x88(%rbp)
  test   %r15d,%r15d
  jle    L354
  lea    0xf(%rbx),%rdi
  lea    0x8(%rax),%r11
  movslq %esi,%rcx
  mov    %rdi,%r8
  lea    0x0(,%rcx,8),%r9
  sub    %rdx,%r8
  lea    (%rbx,%r9,1),%rcx
  cmp    $0x1e,%r8
  seta   %r8b
  sub    %r13,%rdi
  cmp    $0x1e,%rdi
  seta   %dil
  and    %edi,%r8d
  cmp    %r11,%rbx
  setne  %dil
  and    %r8d,%edi
  cmp    $0x1,%r15d
  setne  %r8b
  and    %edi,%r8d
  cmp    $0x8,%r9
  setne  %dil
  and    %r8d,%edi
  cmp    %rcx,%r11
  setne  %r8b
  and    %r8d,%edi
  lea    0x8(%rdx),%r8
  cmp    %r8,%rcx
  setne  %r8b
  test   %r8b,%dil
  je     L417
  lea    0x10(%rbx,%r9,1),%rdi
  cmp    %rdi,%r13
  lea    0x10(%r13),%rdi
  setae  %r8b
  cmp    %rdi,%rcx
  setae  %dil
  or     %r8b,%dil
  je     L417
  mov    %r15d,%r8d
  mov    -0x80(%rbp),%r9
  mov    %rsp,%r10
  xor    %edi,%edi
  shr    %r8d
  shl    $0x4,%r8
L319:
  movupd (%rax,%rdi,1),%xmm0
  movups %xmm0,(%rbx,%rdi,1)
  movupd 0x0(%r13,%rdi,1),%xmm3
  divpd  %xmm3,%xmm0
  movups %xmm0,(%r9,%rdi,1)
  movupd (%rdx,%rdi,1),%xmm0
  movups %xmm0,(%rcx,%rdi,1)
  movupd 0x0(%r13,%rdi,1),%xmm5
  divpd  %xmm5,%xmm0
  movups %xmm0,(%r10,%rdi,1)
  add    $0x10,%rdi
  cmp    %r8,%rdi
  jne    L319
  mov    %r15d,%ecx
  and    $0xfffffffe,%ecx
  test   $0x1,%r15b
  je     L354
  mov    %ecx,%edi
  mov    -0x80(%rbp),%r11
  movsd  (%rax,%rdi,8),%xmm0
  lea    0x0(%r13,%rdi,8),%r8
  movslq %ecx,%rax
  movsd  %xmm0,(%rbx,%rdi,8)
  divsd  (%r8),%xmm0
  movsd  %xmm0,(%r11,%rax,8)
  movsd  (%rdx,%rdi,8),%xmm0
  lea    (%rcx,%rsi,1),%edx
  mov    -0x88(%rbp),%rdi
  movslq %edx,%rdx
  movsd  %xmm0,(%rbx,%rdx,8)
  divsd  (%r8),%xmm0
  movsd  %xmm0,(%rdi,%rax,8)
L354:
  mov    -0xb8(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x48(%rbp)
  test   %eax,%eax
  jle    L86
L89:
  movslq %esi,%rsi
  movl   $0x0,-0x78(%rbp)
  mov    %rbx,%r14
  lea    0x0(,%rsi,8),%rax
  movl   $0x0,-0x70(%rbp)
  mov    %rax,-0xa0(%rbp)
  mov    -0xb8(%rbp),%eax
  imul   -0x50(%rbp),%eax
  mov    %rbx,-0xd0(%rbp)
  mov    %r12,-0xb0(%rbp)
  mov    %r13,-0x68(%rbp)
  mov    %r15d,%r13d
  mov    %eax,-0xb4(%rbp)
  nopl   0x0(%rax)
L390:
  mov    -0xa0(%rbp),%rax
  mov    %r13d,%r9d
  mov    %r14,%rcx
  mov    %r13d,%edi
  mov    -0x88(%rbp),%rdx
  mov    -0x80(%rbp),%rsi
  lea    (%r14,%rax,1),%r15
  mov    %r15,%r8
  call   <update_sincos@plt>
  mov    -0x44(%rbp),%r10d
  test   %r10d,%r10d
  js     L76
  movslq -0x78(%rbp),%rax
  mov    -0xb0(%rbp),%rdi
  xor    %ebx,%ebx
  mov    %rax,%rsi
  add    -0xb4(%rbp),%esi
  lea    (%rdi,%rax,8),%r9
  movslq %esi,%r12
  sub    %rax,%r12
  shl    $0x3,%r12
  mov    %r12,-0x60(%rbp)
  mov    %ebx,%r12d
  mov    %r9,%rbx
  xchg   %ax,%ax
L54:
  mov    -0x60(%rbp),%rax
  sub    $0x8,%rsp
  mov    -0x68(%rbp),%rcx
  mov    %rbx,%r9
  mov    %r12d,%r8d
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %r13d,%edi
  add    %rbx,%rax
  add    $0x1,%r12d
  add    $0x8,%rbx
  push   %rax
  call   <calc_dotprod@plt>
  pop    %r8
  pop    %r9
  cmp    %r12d,-0x44(%rbp)
  jge    L54
L76:
  addl   $0x1,-0x70(%rbp)
  mov    -0x50(%rbp),%esi
  mov    -0x70(%rbp),%eax
  add    %esi,-0x78(%rbp)
  add    -0x90(%rbp),%r14
  cmp    -0x48(%rbp),%eax
  jne    L390
  mov    %r13d,%r15d
  mov    -0xd0(%rbp),%rbx
  mov    -0x68(%rbp),%r13
  mov    -0xb0(%rbp),%r12
L188:
  mov    -0x44(%rbp),%edi
  test   %edi,%edi
  js     L199
  mov    -0x48(%rbp),%edi
  mov    -0xb8(%rbp),%edx
  xor    %r8d,%r8d
  mov    %rbx,-0x70(%rbp)
  mov    -0x50(%rbp),%esi
  mov    %r12,-0x78(%rbp)
  add    %edi,%edx
  mov    %edx,%eax
  imul   %esi,%edx
  imul   %r15d,%eax
  movslq %edx,%rdx
  cltq
  lea    (%rbx,%rax,8),%rax
  mov    %rax,-0x60(%rbp)
  mov    %edi,%eax
  imul   %esi,%edi
  imul   %r15d,%eax
  cltq
  lea    (%rbx,%rax,8),%r14
  movslq %edi,%rax
  sub    %rax,%rdx
  lea    (%r12,%rax,8),%r9
  mov    %r8d,%r12d
  lea    0x0(,%rdx,8),%rax
  mov    %r9,%rbx
  mov    %rax,-0x68(%rbp)
  nopl   (%rax)
L224:
  mov    -0x68(%rbp),%rax
  sub    $0x8,%rsp
  mov    -0x60(%rbp),%rdx
  mov    %rbx,%r9
  mov    %r12d,%r8d
  mov    %r13,%rcx
  mov    %r14,%rsi
  mov    %r15d,%edi
  add    %rbx,%rax
  add    $0x1,%r12d
  add    $0x8,%rbx
  push   %rax
  call   <calc_dotprod@plt>
  pop    %rdx
  pop    %rcx
  cmp    %r12d,-0x44(%rbp)
  jge    L224
  mov    -0x70(%rbp),%rbx
  mov    -0x78(%rbp),%r12
L199:
  mov    -0x58(%rbp),%esi
  test   %esi,%esi
  jle    L93
  movslq -0x58(%rbp),%rax
  mov    -0x50(%rbp),%edi
  xor    %r8d,%r8d
  pxor   %xmm3,%xmm3
  movl   $0x0,-0x88(%rbp)
  mov    %rax,-0x80(%rbp)
  mov    %r15d,%eax
  shr    %eax
  movl   $0x0,-0x48(%rbp)
  lea    -0x1(%rax),%r9d
  mov    %r15d,%eax
  movl   $0x0,-0x90(%rbp)
  and    $0xfffffffe,%eax
  movq   $0x0,-0x78(%rbp)
  add    $0x1,%r9
  mov    %eax,-0x68(%rbp)
  mov    %edi,%eax
  and    $0xfffffffe,%edi
  shl    $0x4,%r9
  shr    %eax
  mov    %edi,-0x70(%rbp)
  xor    %edi,%edi
  lea    -0x1(%rax),%r13d
  add    $0x1,%r13
  shl    $0x4,%r13
  xchg   %ax,%ax
L106:
  movslq %edi,%rax
  mov    -0x98(%rbp),%rsi
  mov    -0x90(%rbp),%ecx
  lea    (%rbx,%rax,8),%r11
  movslq %r8d,%rax
  mov    -0x78(%rbp),%r14
  lea    (%r12,%rax,8),%r10
  movslq -0x48(%rbp),%rax
  lea    (%rsi,%rax,8),%rax
  mov    -0x88(%rbp),%esi
  mov    %rax,-0x60(%rbp)
  nopl   0x0(%rax)
L184:
  movapd %xmm3,%xmm0
  test   %r15d,%r15d
  jle    L45
  cmp    $0x1,%r15d
  je     L139
  movslq %ecx,%rax
  movapd %xmm3,%xmm0
  lea    (%rbx,%rax,8),%rdx
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L29:
  movupd (%rdx,%rax,1),%xmm2
  movupd (%r11,%rax,1),%xmm7
  add    $0x10,%rax
  mulpd  %xmm7,%xmm2
  addsd  %xmm2,%xmm0
  unpckhpd %xmm2,%xmm2
  addsd  %xmm2,%xmm0
  cmp    %r9,%rax
  jne    L29
  mov    -0x68(%rbp),%eax
  cmp    %r15d,%eax
  je     L45
L33:
  lea    (%rcx,%rax,1),%edx
  add    %edi,%eax
  movslq %edx,%rdx
  cltq
  movsd  (%rbx,%rdx,8),%xmm1
  mulsd  (%rbx,%rax,8),%xmm1
  addsd  %xmm1,%xmm0
L45:
  mov    -0x44(%rbp),%eax
  test   %eax,%eax
  js     L59
  je     L193
  movslq %esi,%rax
  lea    (%r12,%rax,8),%rdx
  xor    %eax,%eax
  nopw   0x0(%rax,%rax,1)
L361:
  movupd (%rdx,%rax,1),%xmm1
  movupd (%r10,%rax,1),%xmm6
  add    $0x10,%rax
  mulpd  %xmm6,%xmm1
  subsd  %xmm1,%xmm0
  unpckhpd %xmm1,%xmm1
  subsd  %xmm1,%xmm0
  cmp    %r13,%rax
  jne    L361
  mov    -0x70(%rbp),%eax
  mov    -0x50(%rbp),%edx
  cmp    %edx,%eax
  je     L59
L30:
  lea    (%rsi,%rax,1),%edx
  add    %r8d,%eax
  movslq %edx,%rdx
  cltq
  movsd  (%r12,%rdx,8),%xmm1
  mulsd  (%r12,%rax,8),%xmm1
  subsd  %xmm1,%xmm0
L59:
  mov    -0x60(%rbp),%rax
  add    %r15d,%ecx
  add    -0x50(%rbp),%esi
  movsd  %xmm0,(%rax,%r14,8)
  add    $0x1,%r14
  cmp    %r14d,-0x58(%rbp)
  jg     L184
  mov    -0x58(%rbp),%ecx
  add    %ecx,-0x48(%rbp)
  add    %r15d,%edi
  mov    -0x50(%rbp),%ecx
  addq   $0x1,-0x78(%rbp)
  add    %r15d,-0x90(%rbp)
  mov    -0x78(%rbp),%rax
  add    %ecx,-0x88(%rbp)
  add    %ecx,%r8d
  cmp    -0x80(%rbp),%rax
  jne    L106
  mov    -0x58(%rbp),%esi
  pxor   %xmm6,%xmm6
  mov    %r15d,-0x44(%rbp)
  xor    %r10d,%r10d
  cvtsi2sd %r15d,%xmm6
  mov    -0x98(%rbp),%r12
  mulsd  -0xc8(%rbp),%xmm6
  xor    %r11d,%r11d
  lea    0x1(%rsi),%eax
  movsd  D4(%rip),%xmm5
  mov    -0xb8(%rbp),%r13d
  mov    %esi,%r15d
  cltq
  mov    %r12,-0x50(%rbp)
  mov    %r12,%rdi
  shl    $0x3,%rax
  mov    %rax,-0x58(%rbp)
  mov    -0x80(%rbp),%rax
  lea    0x8(,%rax,8),%r14
  lea    0x0(,%rax,8),%r8
  mov    %r14,-0x60(%rbp)
  mov    -0xc0(%rbp),%r14
L149:
  mov    %r11d,%eax
  pxor   %xmm4,%xmm4
  cltd
  idiv   %r13d
  mov    -0x44(%rbp),%eax
  cvtsi2sd %edx,%xmm4
  addsd  %xmm5,%xmm4
  mulsd  %xmm4,%xmm4
  test   %eax,%eax
  jle    L254
  cmp    $0x1,%eax
  je     L207
  movslq %r10d,%rax
  movapd %xmm3,%xmm0
  lea    (%rbx,%rax,8),%rdx
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L185:
  movupd (%r14,%rax,1),%xmm2
  movupd (%rdx,%rax,1),%xmm7
  add    $0x10,%rax
  mulpd  %xmm7,%xmm2
  addsd  %xmm2,%xmm0
  unpckhpd %xmm2,%xmm2
  addsd  %xmm2,%xmm0
  cmp    %rax,%r9
  jne    L185
  movslq -0x68(%rbp),%rax
  mov    -0x44(%rbp),%esi
  cmp    %esi,%eax
  je     L398
L266:
  lea    (%r10,%rax,1),%edx
  movslq %edx,%rdx
  movsd  (%rbx,%rdx,8),%xmm1
  mulsd  (%r14,%rax,8),%xmm1
  addsd  %xmm1,%xmm0
L398:
  divsd  %xmm4,%xmm0
  mov    -0xa8(%rbp),%rax
  mov    -0x50(%rbp),%rsi
  mov    %r11,%rcx
  movsd  %xmm0,(%rax,%r11,8)
  nopl   (%rax)
L413:
  mov    %ecx,%eax
  pxor   %xmm0,%xmm0
  movsd  (%rdi,%rcx,8),%xmm1
  cltd
  idiv   %r13d
  cvtsi2sd %edx,%xmm0
  addsd  %xmm5,%xmm0
  mulsd  %xmm0,%xmm0
  mulsd  %xmm4,%xmm0
  divsd  %xmm0,%xmm1
  movsd  %xmm1,(%rdi,%rcx,8)
  add    $0x1,%rcx
  movsd  %xmm1,(%rsi)
  add    %r8,%rsi
  cmp    %ecx,%r15d
  jg     L413
  mov    -0x60(%rbp),%rsi
  add    $0x1,%r11
  add    %rsi,-0x50(%rbp)
  add    %r8,%rdi
  movsd  (%r12),%xmm0
  add    -0x44(%rbp),%r10d
  addsd  %xmm6,%xmm0
  movsd  %xmm0,(%r12)
  add    -0x58(%rbp),%r12
  cmp    -0x80(%rbp),%r11
  jne    L149
L93:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L376
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L356:
  orq    $0x0,-0x8(%rsp,%r9,1)
  jmp    L159
  cs nopw 0x0(%rax,%rax,1)
L139:
  movapd %xmm3,%xmm0
  xor    %eax,%eax
  jmp    L33
L193:
  xor    %eax,%eax
  jmp    L30
L254:
  movapd %xmm3,%xmm0
  jmp    L398
L207:
  movapd %xmm3,%xmm0
  xor    %eax,%eax
  jmp    L266
L417:
  mov    -0x80(%rbp),%r8
  mov    -0x88(%rbp),%r9
  xor    %edi,%edi
L351:
  movsd  (%rax,%rdi,8),%xmm0
  movsd  %xmm0,(%rbx,%rdi,8)
  divsd  0x0(%r13,%rdi,8),%xmm0
  movsd  %xmm0,(%r8,%rdi,8)
  movsd  (%rdx,%rdi,8),%xmm0
  movsd  %xmm0,(%rcx,%rdi,8)
  divsd  0x0(%r13,%rdi,8),%xmm0
  movsd  %xmm0,(%r9,%rdi,8)
  add    $0x1,%rdi
  cmp    %r10,%rdi
  jne    L351
  mov    -0xb8(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x48(%rbp)
  test   %eax,%eax
  jg     L89
L86:
  movl   $0x0,-0x48(%rbp)
  jmp    L188
L256:
  orq    $0x0,-0x8(%rsp,%r8,1)
  jmp    L205
L376:
  call   <__stack_chk_fail@plt>
```

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

tool: D4: 1

assistant: ```c
void def_hat(int numt, int nharm, int detrend_order, double hat_matr[], double hat0[], double sinx[], double cosx[], double wt[], double cn[], double hat_hat[], double vec[], double lambda0) {
  int i, j = numt * nharm, k, j1, npar = 2 * nharm, dord1 = detrend_order + 1;
  double sx0[numt], cx0[numt], ct, st, sum;
  for (i = 0; i < numt; i++) {
    sx0[i] = (hat_matr[i] = sinx[i]) / wt[i];
    cx0[i] = (hat_matr[i + j] = cosx[i]) / wt[i];
  }
  for (j = 0; j < nharm - 1; j++) {
    update_sincos(numt, sx0, cx0, hat_matr + j * numt, hat_matr + (j + nharm) * numt, numt);
    for (i = 0; i <= detrend_order; i++)
      calc_dotprod(numt, hat_matr + j * numt, hat_matr + (j + nharm) * numt, wt, i, &hat0[i + j * dord1], &hat0[i + (j + nharm) * dord1]);
  }
  for (i = 0; i <= detrend_order; i++)
    calc_dotprod(numt, hat_matr + j * numt, hat_matr + (j + nharm) * numt, wt, i, &hat0[i + j * dord1], &hat0[i + (j + nharm) * dord1]);
  for (j = 0; j < npar; j++) {
    for (k = j; k < npar; k++) {
      for (sum = 0, i = 0; i < numt; i++)
        sum += hat_matr[i + j * numt] * hat_matr[i + k * numt];
      for (i = 0; i <= detrend_order; i++)
        sum -= hat0[i + j * dord1] * hat0[i + k * dord1];
      hat_hat[k + j * npar] = sum;
    }
  }
  for (j = 0; j < npar; j++) {
    ct = (1. + (j % nharm));
    ct *= ct;
    for (sum = 0, i = 0; i < numt; i++)
      sum += hat_matr[i + j * numt] * cn[i];
    vec[j] = sum / ct;
    for (k = j; k < npar; k++) {
      st = (1. + (k % nharm));
      st *= st;
      hat_hat[k + j * npar] /= (ct * st);
      hat_hat[j + k * npar] = hat_hat[k + j * npar];
    }
    hat_hat[j + j * npar] += numt * lambda0;
  }
}
```