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

```asm
<get_derivative_nac>:
  endbr64
  push   %r15
  mov    %rcx,%rax
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xd8,%rsp
  movsd  0x20(%rax),%xmm10
  movsd  0x28(%rax),%xmm7
  movsd  0x40(%rax),%xmm13
  movsd  0x38(%rax),%xmm1
  mov    %rdi,0x78(%rsp)
  movapd %xmm10,%xmm3
  movapd %xmm7,%xmm5
  movsd  (%rax),%xmm9
  movsd  0x30(%rax),%xmm11
  mulsd  %xmm1,%xmm5
  movsd  0x18(%rax),%xmm14
  movapd %xmm13,%xmm15
  movsd  0x8(%rax),%xmm8
  mulsd  %xmm13,%xmm3
  movupd 0x10(%rax),%xmm2
  movsd  %xmm0,0x50(%rsp)
  movapd %xmm13,%xmm6
  mulsd  %xmm14,%xmm15
  movupd 0x30(%rax),%xmm0
  movupd 0x20(%rax),%xmm4
  unpcklpd %xmm11,%xmm6
  mulsd  %xmm14,%xmm1
  movupd (%rax),%xmm12
  mov    0x118(%rsp),%rcx
  mov    %rsi,0x70(%rsp)
  movapd %xmm0,%xmm14
  mov    %edx,0xac(%rsp)
  mov    0x110(%rsp),%r14
  unpckhpd %xmm2,%xmm14
  mov    %rcx,0x48(%rsp)
  mov    0x120(%rsp),%rcx
  subsd  %xmm5,%xmm3
  movapd %xmm7,%xmm5
  unpcklpd %xmm13,%xmm7
  mov    %r8,0xa0(%rsp)
  mulsd  %xmm11,%xmm5
  mulpd  %xmm7,%xmm14
  mov    %fs:0x28,%rsi
  mov    %rsi,0xc8(%rsp)
  xor    %esi,%esi
  mulsd  %xmm9,%xmm3
  subsd  %xmm15,%xmm5
  movapd %xmm10,%xmm15
  unpcklpd %xmm13,%xmm15
  mulsd  %xmm8,%xmm5
  addsd  %xmm5,%xmm3
  movapd %xmm10,%xmm5
  unpcklpd %xmm9,%xmm10
  mulsd  %xmm11,%xmm5
  unpcklpd %xmm9,%xmm11
  subsd  %xmm5,%xmm1
  mulsd  %xmm2,%xmm1
  addsd  %xmm1,%xmm3
  movapd %xmm6,%xmm1
  mulpd  %xmm4,%xmm1
  mulpd  %xmm12,%xmm6
  movapd %xmm3,%xmm5
  unpcklpd %xmm5,%xmm5
  movapd %xmm1,%xmm7
  movapd %xmm2,%xmm1
  subpd  %xmm14,%xmm7
  movapd %xmm0,%xmm14
  shufpd $0x1,%xmm2,%xmm1
  unpckhpd %xmm0,%xmm14
  mulpd  %xmm14,%xmm1
  movapd %xmm12,%xmm14
  divpd  %xmm5,%xmm7
  movsd  %xmm0,%xmm14
  movsd  %xmm2,%xmm0
  mulpd  %xmm11,%xmm0
  movapd %xmm8,%xmm11
  movapd %xmm14,%xmm13
  mulpd  %xmm15,%xmm13
  unpcklpd %xmm11,%xmm11
  unpcklpd %xmm2,%xmm11
  subpd  %xmm0,%xmm6
  movapd %xmm4,%xmm0
  unpckhpd %xmm2,%xmm0
  subpd  %xmm13,%xmm1
  mulpd  %xmm11,%xmm0
  movapd %xmm4,%xmm11
  mulsd  %xmm9,%xmm4
  movsd  %xmm2,%xmm11
  unpckhpd %xmm2,%xmm2
  mulpd  %xmm11,%xmm10
  mulsd  %xmm8,%xmm2
  subpd  %xmm10,%xmm0
  subsd  %xmm2,%xmm4
  divpd  %xmm5,%xmm0
  divpd  %xmm5,%xmm1
  divpd  %xmm5,%xmm6
  movapd %xmm0,%xmm5
  unpckhpd %xmm5,%xmm5
  divsd  %xmm3,%xmm4
  test   %rcx,%rcx
  je     L80
  movsd  (%rcx),%xmm9
  movapd %xmm1,%xmm2
  movsd  0x8(%rcx),%xmm8
  unpcklpd %xmm7,%xmm1
  movsd  %xmm7,%xmm2
  movsd  0x10(%rcx),%xmm3
  shufpd $0x2,%xmm6,%xmm1
  mulsd  %xmm9,%xmm0
  movapd %xmm9,%xmm10
  movapd %xmm8,%xmm11
  mulsd  %xmm8,%xmm5
  unpcklpd %xmm10,%xmm10
  unpcklpd %xmm11,%xmm11
  mulpd  %xmm10,%xmm2
  pxor   %xmm10,%xmm10
  mulsd  %xmm3,%xmm4
  addpd  %xmm10,%xmm2
  movapd %xmm7,%xmm10
  shufpd $0x1,%xmm7,%xmm10
  unpcklpd %xmm6,%xmm10
  pxor   %xmm7,%xmm7
  movapd %xmm3,%xmm6
  mulpd  %xmm11,%xmm10
  addsd  %xmm7,%xmm0
  unpcklpd %xmm6,%xmm6
  movsd  %xmm7,0x98(%rsp)
  mulpd  %xmm6,%xmm1
  addsd  %xmm5,%xmm0
  addpd  %xmm10,%xmm2
  addsd  %xmm4,%xmm0
  addpd  %xmm2,%xmm1
  movsd  %xmm0,0xc0(%rsp)
  movaps %xmm1,0xb0(%rsp)
L114:
  mov    0x48(%rsp),%rsi
  lea    0xb0(%rsp),%r13
  mov    %r13,%rdi
  call   <get_C@plt>
  mov    0xac(%rsp),%eax
  movsd  %xmm0,0x38(%rsp)
  test   %eax,%eax
  jle    L63
  movl   $0x0,0xa8(%rsp)
  movslq %eax,%rcx
  imul   %eax,%eax
  mov    %rcx,0x90(%rsp)
  movq   $0x0,0x88(%rsp)
  lea    (%rax,%rax,8),%eax
  mov    %eax,0x84(%rsp)
L92:
  movq   $0x0,0x68(%rsp)
  mov    0x88(%rsp),%eax
  mov    %eax,0x5c(%rsp)
  mov    0xa8(%rsp),%eax
  lea    (%rax,%rax,8),%eax
  mov    %eax,0x80(%rsp)
  nopl   0x0(%rax,%rax,1)
L112:
  mov    0x68(%rsp),%rdx
  mov    0xa0(%rsp),%rax
  mov    0x88(%rsp),%rsi
  movsd  0x98(%rsp),%xmm3
  mov    %edx,%ebp
  movsd  (%rax,%rsi,8),%xmm0
  mulsd  (%rax,%rdx,8),%xmm0
  ucomisd %xmm0,%xmm3
  ja     L42
  sqrtsd %xmm0,%xmm0
L39:
  mulsd  0x38(%rsp),%xmm0
  movl   $0x0,0x60(%rsp)
  xor    %r12d,%r12d
  movsd  %xmm0,0x40(%rsp)
L58:
  mov    0x80(%rsp),%edi
  mov    0x60(%rsp),%eax
  xor    %ebx,%ebx
  mov    0x78(%rsp),%rcx
  add    %edi,%eax
  mov    %edi,0x58(%rsp)
  cltq
  lea    (%rcx,%rax,8),%rax
  mov    %rax,0x8(%rsp)
L123:
  mov    0x5c(%rsp),%r15d
  mov    %r14,%rcx
  mov    %r13,%rdx
  mov    %ebx,%esi
  mov    %r15d,%edi
  call   <get_A@plt>
  mov    %r14,%rcx
  mov    %r12d,%edx
  mov    %ebx,%esi
  mov    %r15d,%edi
  movsd  %xmm0,0x10(%rsp)
  call   <get_dA@plt>
  movsd  %xmm0,0x18(%rsp)
  test   %r12d,%r12d
  je     L134
  mov    %ebx,0x30(%rsp)
  xor    %r15d,%r15d
  mov    %r13,%rax
  mov    %r15,%r13
  mov    %r14,%r15
  mov    %ebp,%r14d
  mov    %rax,%rbp
L14:
  mov    %r13d,%esi
  mov    %r15,%rcx
  mov    %rbp,%rdx
  mov    %r14d,%edi
  call   <get_A@plt>
  mov    %r13d,%esi
  mov    %r15,%rcx
  mov    %r12d,%edx
  mov    %r14d,%edi
  movsd  %xmm0,0x28(%rsp)
  call   <get_dA@plt>
  mov    0x48(%rsp),%r8
  mov    %r13d,%esi
  mov    %rbp,%rcx
  mov    0x30(%rsp),%edi
  mov    %r12d,%edx
  movsd  %xmm0,0x20(%rsp)
  call   <get_dC@plt>
  movsd  0x28(%rsp),%xmm1
  movsd  0x10(%rsp),%xmm4
  movapd %xmm0,%xmm3
  movsd  0x20(%rsp),%xmm2
  movsd  0x18(%rsp),%xmm0
  mov    0x8(%rsp),%rax
  mulsd  %xmm1,%xmm0
  mulsd  %xmm4,%xmm2
  mulsd  %xmm4,%xmm1
  addsd  %xmm2,%xmm0
  mulsd  %xmm3,%xmm1
  divsd  0x38(%rsp),%xmm1
  subsd  %xmm1,%xmm0
  divsd  0x40(%rsp),%xmm0
  mulsd  0x50(%rsp),%xmm0
  movsd  %xmm0,(%rax,%r13,8)
  add    $0x1,%r13
  cmp    $0x3,%r13
  jne    L14
  mov    0x30(%rsp),%ebx
  mov    %rbp,%r13
  mov    %r14d,%ebp
  mov    %r15,%r14
L50:
  add    $0x1,%ebx
  addq   $0x18,0x8(%rsp)
  addl   $0x3,0x58(%rsp)
  cmp    $0x3,%ebx
  jne    L123
  add    $0x1,%r12d
  mov    0x84(%rsp),%edx
  add    %edx,0x60(%rsp)
  cmp    $0x3,%r12d
  jne    L58
  addq   $0x1,0x68(%rsp)
  mov    0x68(%rsp),%rax
  addl   $0x9,0x80(%rsp)
  cmp    0x90(%rsp),%rax
  jne    L112
  addq   $0x1,0x88(%rsp)
  mov    0xac(%rsp),%esi
  mov    0x88(%rsp),%rax
  add    %esi,0xa8(%rsp)
  cmp    0x90(%rsp),%rax
  jne    L92
L63:
  mov    0xc8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L10
  add    $0xd8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L134:
  movslq 0x58(%rsp),%rax
  mov    0x70(%rsp),%rsi
  mov    %r12d,0x64(%rsp)
  xor    %r15d,%r15d
  lea    (%rsi,%rax,8),%rax
  mov    %rax,0x30(%rsp)
  mov    %r14,%rax
  mov    %r15,%r14
  mov    %ebp,%r15d
  mov    %rax,%rbp
L57:
  mov    %r14d,%esi
  mov    %rbp,%rcx
  mov    %r13,%rdx
  mov    %r15d,%edi
  call   <get_A@plt>
  mov    %r14d,%esi
  mov    %rbp,%rcx
  xor    %edx,%edx
  mov    %r15d,%edi
  movsd  %xmm0,0x28(%rsp)
  call   <get_dA@plt>
  mov    0x48(%rsp),%r8
  mov    %r14d,%esi
  mov    %r13,%rcx
  xor    %edx,%edx
  mov    %ebx,%edi
  movsd  %xmm0,0x20(%rsp)
  call   <get_dC@plt>
  movsd  0x10(%rsp),%xmm6
  mov    0x8(%rsp),%rax
  movsd  0x28(%rsp),%xmm1
  movsd  0x20(%rsp),%xmm3
  movapd %xmm0,%xmm2
  movapd %xmm6,%xmm0
  movsd  0x40(%rsp),%xmm5
  mulsd  %xmm1,%xmm0
  mulsd  %xmm6,%xmm3
  movsd  0x50(%rsp),%xmm6
  mulsd  0x18(%rsp),%xmm1
  mulsd  %xmm0,%xmm2
  divsd  0x38(%rsp),%xmm2
  divsd  %xmm5,%xmm0
  addsd  %xmm3,%xmm1
  subsd  %xmm2,%xmm1
  divsd  %xmm5,%xmm1
  mulsd  %xmm6,%xmm0
  mulsd  %xmm6,%xmm1
  movsd  %xmm1,(%rax,%r14,8)
  mov    0x30(%rsp),%rax
  movsd  %xmm0,(%rax,%r14,8)
  add    $0x1,%r14
  cmp    $0x3,%r14
  jne    L57
  mov    %rbp,%r14
  mov    0x64(%rsp),%r12d
  mov    %r15d,%ebp
  jmp    L50
L80:
  movsd  (%r9),%xmm2
  movapd %xmm1,%xmm3
  unpcklpd %xmm7,%xmm1
  movsd  0x8(%r9),%xmm9
  movsd  %xmm7,%xmm3
  movsd  0x10(%r9),%xmm8
  shufpd $0x2,%xmm6,%xmm1
  mulsd  %xmm2,%xmm0
  movapd %xmm2,%xmm10
  movapd %xmm9,%xmm11
  mulsd  %xmm5,%xmm9
  unpcklpd %xmm10,%xmm10
  unpcklpd %xmm11,%xmm11
  mulpd  %xmm10,%xmm3
  pxor   %xmm10,%xmm10
  addpd  %xmm10,%xmm3
  movapd %xmm7,%xmm10
  shufpd $0x1,%xmm7,%xmm10
  unpcklpd %xmm6,%xmm10
  movapd %xmm8,%xmm6
  mulpd  %xmm11,%xmm10
  unpcklpd %xmm6,%xmm6
  mulpd  %xmm6,%xmm1
  mulsd  %xmm4,%xmm8
  addpd  %xmm10,%xmm3
  addpd  %xmm3,%xmm1
  pxor   %xmm3,%xmm3
  movsd  %xmm3,0x98(%rsp)
  addsd  %xmm3,%xmm0
  movaps %xmm1,0xb0(%rsp)
  addsd  %xmm9,%xmm0
  addsd  %xmm8,%xmm0
  movsd  %xmm0,0xc0(%rsp)
  jmp    L114
L42:
  call   <sqrt@plt>
  jmp    L39
L10:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void get_derivative_nac(double *ddnac, double *dnac, const int num_patom, const double *lattice, const double *mass, const double *q, const double *born, const double *dielectric, const double *q_direction, const double factor) {
  int i, j, k, l, m;
  double a, b, c, da, db, dc, volume, mass_sqrt;
  double q_cart[3], rec_lat[9];
  volume = lattice[0] * (lattice[4] * lattice[8] - lattice[5] * lattice[7]) + lattice[1] * (lattice[5] * lattice[6] - lattice[3] * lattice[8]) + lattice[2] * (lattice[3] * lattice[7] - lattice[4] * lattice[6]);
  rec_lat[0] = (lattice[4] * lattice[8] - lattice[5] * lattice[7]) / volume;
  rec_lat[1] = (lattice[5] * lattice[6] - lattice[3] * lattice[8]) / volume;
  rec_lat[2] = (lattice[3] * lattice[7] - lattice[4] * lattice[6]) / volume;
  rec_lat[3] = (lattice[7] * lattice[2] - lattice[8] * lattice[1]) / volume;
  rec_lat[4] = (lattice[8] * lattice[0] - lattice[6] * lattice[2]) / volume;
  rec_lat[5] = (lattice[6] * lattice[1] - lattice[7] * lattice[0]) / volume;
  rec_lat[6] = (lattice[1] * lattice[5] - lattice[2] * lattice[4]) / volume;
  rec_lat[7] = (lattice[2] * lattice[3] - lattice[0] * lattice[5]) / volume;
  rec_lat[8] = (lattice[0] * lattice[4] - lattice[1] * lattice[3]) / volume;
  for (i = 0; i < 3; i++) {
    q_cart[i] = 0;
    for (j = 0; j < 3; j++) {
      if (q_direction) {
        q_cart[i] += rec_lat[i * 3 + j] * q_direction[j];
      } else {
        q_cart[i] += rec_lat[i * 3 + j] * q[j];
      }
    }
  }
  c = get_C(q_cart, dielectric);
  for (i = 0; i < num_patom; i++) {
    for (j = 0; j < num_patom; j++) {
      mass_sqrt = sqrt(mass[i] * mass[j]);
      for (k = 0; k < 3; k++) {
        for (l = 0; l < 3; l++) {
          a = get_A(i, l, q_cart, born);
          da = get_dA(i, l, k, born);
          for (m = 0; m < 3; m++) {
            b = get_A(j, m, q_cart, born);
            db = get_dA(j, m, k, born);
            dc = get_dC(l, m, k, q_cart, dielectric);
            ddnac[k * num_patom * num_patom * 9 + i * 9 * num_patom + j * 9 + l * 3 + m] = (da * b + db * a - a * b * dc / c) / (c * mass_sqrt) * factor;
            if (k == 0) {
              dnac[i * 9 * num_patom + j * 9 + l * 3 + m] = a * b / (c * mass_sqrt) * factor;
            }
          }
        }
      }
    }
  }
}
```