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

```asm
<gint1_fn_dmat>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x98,%rsp
  mov    %rdi,0x78(%rsp)
  mov    $0x50,%edi
  movslq 0xf0(%rsp),%rbx
  mov    %rsi,0x50(%rsp)
  mov    %rdx,0x10(%rsp)
  mov    %rcx,0x40(%rsp)
  mov    %r8,0x80(%rsp)
  mov    %r9,0x60(%rsp)
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L4
  pxor   %xmm0,%xmm0
  pxor   %xmm6,%xmm6
  cvtsi2sdl 0xe8(%rsp),%xmm0
  mulsd  D19(%rip),%xmm0
  addsd  D5(%rip),%xmm0
  ucomisd %xmm0,%xmm6
  ja     L97
  sqrtsd %xmm0,%xmm0
L118:
  subsd  D5(%rip),%xmm0
  cvttsd2si %xmm0,%edi
  mov    %edi,%eax
  mov    %edi,0x88(%rsp)
  mov    %edi,%r15d
  shr    $0x1f,%eax
  add    %edi,%eax
  sar    %eax
  lea    0x0(,%rax,8),%edi
  mov    %eax,0x8c(%rsp)
  mov    %eax,%r14d
  call   <malloc@plt>
  mov    %rax,0x58(%rsp)
  test   %rax,%rax
  je     L4
  test   %ebx,%ebx
  jle    L291
  mov    0x50(%rsp),%rax
  cmp    $0x1,%r15d
  mov    0x60(%rsp),%rdi
  lea    (%rax,%rbx,8),%rax
  mov    %rax,0x70(%rsp)
  lea    -0x1(%r14),%eax
  lea    0x8(,%rax,8),%rdx
  mov    $0x8,%eax
  cmovg  %rdx,%rax
  mov    %rax,0x68(%rsp)
  mov    0x100(%rsp),%eax
  sub    $0x1,%eax
  lea    0x4(%rdi,%rax,4),%rax
  mov    %rax,0x48(%rsp)
  lea    0x8(%r12),%rax
  mov    %rax,0x30(%rsp)
L328:
  cmpl   $0x1,0x88(%rsp)
  jle    L83
  mov    0x68(%rsp),%rdx
  mov    0x58(%rsp),%rdi
  xor    %esi,%esi
  call   <memset@plt>
  mov    0x100(%rsp),%ecx
  test   %ecx,%ecx
  jle    L132
L305:
  mov    0x80(%rsp),%rax
  mov    0xe0(%rsp),%rbx
  mov    %r12,%rbp
  mov    0xd8(%rsp),%r14
  mov    %rax,0x28(%rsp)
  mov    0xd0(%rsp),%rax
  mov    %rbx,%r12
  mov    %rax,(%rsp)
  mov    0x60(%rsp),%rax
  mov    %rax,0x18(%rsp)
  mov    0x58(%rsp),%rax
  mov    %rax,0x8(%rsp)
  xchg   %ax,%ax
L27:
  mov    0x18(%rsp),%rax
  mov    0x40(%rsp),%rdi
  mov    (%rax),%eax
  lea    (%rax,%rax,2),%eax
  cltq
  lea    (%rdi,%rax,8),%r13
  mov    0x28(%rsp),%rax
  mov    (%rax),%r15d
  mov    %r15d,%eax
  neg    %eax
  cmovs  %r15d,%eax
  cmp    $0x3,%eax
  jg     L145
  cmp    $0xffffffff,%r15d
  jl     L24
  je     L355
  lea    0x1(%r15),%eax
  lea    0x2(%r15),%edx
  imul   %edx,%eax
  sar    %eax
  mov    %eax,0x20(%rsp)
  cltq
  shl    $0x3,%rax
  mov    %rax,0x38(%rsp)
L192:
  mov    (%rsp),%rax
  mov    (%rax),%edx
  test   %edx,%edx
  jle    L221
  xor    %eax,%eax
  mov    0x20(%rsp),%edi
  cmp    $0xffffffff,%r15d
  mov    %rbp,%rbx
  sete   %al
  sub    %eax,%edi
  xor    %eax,%eax
  mov    %edi,0x24(%rsp)
  mov    %eax,%ebp
  nopl   0x0(%rax,%rax,1)
L165:
  movsd  (%r12),%xmm0
  mov    %rbx,%rcx
  mov    %r13,%rsi
  mov    %r15d,%edi
  mov    0x10(%rsp),%rdx
  add    $0x8,%r12
  call   <gint1_fn_dispatch@plt>
  cmp    $0xffffffff,%r15d
  je     L243
  mov    0x8(%rsp),%rax
  mov    0x20(%rsp),%ecx
  mov    %rbx,%rdx
L135:
  movslq %ecx,%rsi
  lea    (%rax,%rsi,8),%r9
  cmp    %r9,%r14
  lea    0x8(%r14),%r9
  setae  %r11b
  cmp    %r9,%rax
  setae  %r10b
  or     %r11b,%r10b
  je     L350
  lea    0x8(%rdx),%r10
  cmp    %r10,%rax
  setne  %r11b
  cmp    $0x1,%ecx
  setne  %r10b
  test   %r10b,%r11b
  je     L350
  movsd  (%r14),%xmm1
  mov    %ecx,%r10d
  xor    %esi,%esi
  shr    %r10d
  unpcklpd %xmm1,%xmm1
  shl    $0x4,%r10
  nopl   (%rax)
L25:
  movupd (%rdx,%rsi,1),%xmm0
  movupd (%rax,%rsi,1),%xmm4
  mulpd  %xmm1,%xmm0
  addpd  %xmm4,%xmm0
  movups %xmm0,(%rax,%rsi,1)
  add    $0x10,%rsi
  cmp    %r10,%rsi
  jne    L25
  mov    %ecx,%r10d
  and    $0xfffffffe,%r10d
  mov    %r10d,%esi
  shl    $0x3,%rsi
  add    %rsi,%rdx
  add    %rax,%rsi
  cmp    %ecx,%r10d
  je     L39
  movsd  (%r14),%xmm0
  mulsd  (%rdx),%xmm0
  addsd  (%rsi),%xmm0
  movsd  %xmm0,(%rsi)
L39:
  mov    (%rsp),%rax
  mov    %r9,%r14
  add    $0x1,%ebp
  cmp    %ebp,(%rax)
  jg     L165
  mov    %rbx,%rbp
L221:
  addq   $0x4,0x18(%rsp)
  mov    0x38(%rsp),%rdi
  addq   $0x4,0x28(%rsp)
  mov    0x18(%rsp),%rax
  add    %rdi,0x8(%rsp)
  addq   $0x4,(%rsp)
  cmp    0x48(%rsp),%rax
  jne    L27
  mov    0x50(%rsp),%rax
  cmpl   $0x1,0x88(%rsp)
  mov    %rbp,%r12
  movq   $0x0,(%rax)
  jle    L183
L194:
  mov    0x58(%rsp),%rax
  pxor   %xmm7,%xmm7
  mov    $0x8,%esi
  cmpl   $0x3,0x88(%rsp)
  movapd %xmm7,%xmm3
  mov    $0x1,%ecx
  movsd  (%rax),%xmm1
  mov    0x78(%rsp),%rax
  movsd  (%rax),%xmm0
  lea    0x8(%rax),%rdx
  mov    0x50(%rsp),%rax
  mulsd  %xmm1,%xmm0
  addsd  %xmm7,%xmm0
  mulsd  %xmm1,%xmm0
  addsd  %xmm0,%xmm3
  movsd  %xmm3,(%rax)
  jle    L183
  mov    0x58(%rsp),%r8
  mov    0x8c(%rsp),%r10d
  mov    %rax,%r9
L65:
  cmp    $0x1,%ecx
  je     L246
  mov    %ecx,%edi
  xor    %eax,%eax
  pxor   %xmm0,%xmm0
  shr    %edi
  shl    $0x4,%rdi
  nopl   0x0(%rax)
L130:
  movupd (%rdx,%rax,1),%xmm2
  movupd (%r8,%rax,1),%xmm5
  add    $0x10,%rax
  mulpd  %xmm5,%xmm2
  addsd  %xmm2,%xmm0
  unpckhpd %xmm2,%xmm2
  addsd  %xmm2,%xmm0
  cmp    %rax,%rdi
  jne    L130
  mov    %ecx,%r11d
  and    $0xfffffffe,%r11d
  mov    %r11d,%eax
  shl    $0x3,%rax
  lea    (%r8,%rax,1),%rdi
  add    %rdx,%rax
  cmp    %r11d,%ecx
  je     L337
L179:
  movsd  (%rax),%xmm1
  mulsd  (%rdi),%xmm1
  addsd  %xmm1,%xmm0
L337:
  lea    (%rdx,%rsi,1),%rax
  movsd  (%r8,%rsi,1),%xmm2
  addsd  %xmm0,%xmm0
  add    $0x1,%ecx
  movsd  (%rax),%xmm1
  lea    0x8(%rax),%rdx
  add    $0x8,%rsi
  mulsd  %xmm2,%xmm1
  addsd  %xmm1,%xmm0
  mulsd  %xmm2,%xmm0
  addsd  %xmm0,%xmm3
  movsd  %xmm3,(%r9)
  cmp    %ecx,%r10d
  jne    L65
L183:
  addq   $0x8,0x50(%rsp)
  mov    0x50(%rsp),%rax
  addq   $0x18,0x10(%rsp)
  cmp    0x70(%rsp),%rax
  jne    L328
L291:
  xor    %r13d,%r13d
  jmp    L297
  nopl   0x0(%rax)
L243:
  movsd  (%rbx),%xmm0
  mov    0x24(%rsp),%edi
  lea    0x8(%r14),%rcx
  lea    0x10(%r14),%r9
  mov    0x8(%rsp),%rax
  mulsd  (%r14),%xmm0
  addsd  (%rax),%xmm0
  movsd  %xmm0,(%rax)
  test   %edi,%edi
  je     L39
  mov    %rcx,%r14
  mov    0x30(%rsp),%rdx
  add    $0x8,%rax
  mov    %edi,%ecx
  jmp    L135
  nopl   (%rax)
L350:
  xor    %ecx,%ecx
  nopw   0x0(%rax,%rax,1)
L228:
  movsd  (%r14),%xmm0
  mulsd  (%rdx,%rcx,8),%xmm0
  addsd  (%rax,%rcx,8),%xmm0
  movsd  %xmm0,(%rax,%rcx,8)
  add    $0x1,%rcx
  cmp    %rcx,%rsi
  jne    L228
  jmp    L39
L24:
  mov    %r15d,%eax
  neg    %eax
  lea    0x1(%rax,%rax,1),%eax
  mov    %eax,0x20(%rsp)
  cltq
  shl    $0x3,%rax
  mov    %rax,0x38(%rsp)
  jmp    L192
L355:
  movq   $0x20,0x38(%rsp)
  movl   $0x4,0x20(%rsp)
  jmp    L192
L145:
  mov    %rbp,%r12
  mov    $0xfffffffe,%r13d
L297:
  mov    %r12,%rdi
  call   <free@plt>
  mov    0x58(%rsp),%rdi
  call   <free@plt>
  add    $0x98,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L246:
  mov    %rdx,%rax
  mov    %r8,%rdi
  pxor   %xmm0,%xmm0
  jmp    L179
L83:
  mov    0x100(%rsp),%eax
  test   %eax,%eax
  jg     L305
  mov    0x50(%rsp),%rax
  movq   $0x0,(%rax)
  jmp    L183
L4:
  mov    $0xffffffff,%r13d
  jmp    L297
L132:
  mov    0x50(%rsp),%rax
  movq   $0x0,(%rax)
  jmp    L194
L97:
  call   <sqrt@plt>
  jmp    L118
```

tool_calls: name: read_data
arguments: data_tag: D19
type_infered: f64
name: read_data
arguments: data_tag: D5
type_infered: f64

tool: D19: 8

tool: D5: 1

assistant: ```c
int gint1_fn_dmat(double *dmat, double *density, double *points, double *centers, int *shell_types, int *shell_map, int *num_primitives, double *ccoeffs, double *exponents, int num_dmat, int num_points, int num_centers, int num_shells, int num_ccoeffs, int num_exponents) {
  int shell, shell_type, primitive, dof1, dof2, num_dof, num_shell_dof, result, i_point;
  double *work, *out, *center, *ccoeff, *exponent, *basis_fns, *shell_fns, *fn1, *fn2, *dmat_element;
  double tmp;
  result = 0;
  work = malloc(10 * sizeof(double));
  if (work == NULL) {
    result = -1;
    goto EXIT;
  };
  num_dof = ((int)(sqrt(1.0 + 8.0 * num_dmat) - 1.0)) / 2;
  basis_fns = malloc(num_dof * sizeof(double));
  if (basis_fns == NULL) {
    result = -1;
    goto EXIT;
  };
  for (i_point = 0; i_point < num_points; i_point++) {
    fn1 = basis_fns;
    for (dof1 = 0; dof1 < num_dof; dof1++) {
      *fn1 = 0.0;
      fn1++;
    }
    ccoeff = ccoeffs;
    exponent = exponents;
    shell_fns = basis_fns;
    for (shell = 0; shell < num_shells; shell++) {
      center = centers + (3 * shell_map[shell]);
      shell_type = shell_types[shell];
      if (abs(shell_type) > 3) {
        result = -2;
        goto EXIT;
      };
      num_shell_dof = ((shell_type < -1) ? (-2 * shell_type + 1) : ((shell_type == -1) ? (4) : (((shell_type + 1) * (shell_type + 2)) / 2)));
      for (primitive = 0; primitive < num_primitives[shell]; primitive++) {
        gint1_fn_dispatch(shell_type, center, *exponent, points, work);
        out = work;
        exponent++;
        fn1 = shell_fns;
        if (shell_type == -1) {
          *fn1 += (*out) * (*ccoeff);
          fn1++;
          out++;
          ccoeff++;
        }
        for (dof1 = num_shell_dof - (shell_type == -1); dof1 > 0; dof1--) {
          *fn1 += (*out) * (*ccoeff);
          fn1++;
          out++;
        }
        ccoeff++;
      }
      shell_fns += num_shell_dof;
    }
    *density = 0.0;
    dmat_element = dmat;
    fn1 = basis_fns;
    for (dof1 = 0; dof1 < num_dof; dof1++) {
      fn2 = basis_fns;
      tmp = 0.0;
      for (dof2 = 0; dof2 < dof1; dof2++) {
        tmp += (*fn2) * (*dmat_element);
        dmat_element++;
        fn2++;
      }
      tmp *= 2;
      tmp += (*fn1) * (*dmat_element);
      dmat_element++;
      *density += tmp * (*fn1);
      fn1++;
    }
    density++;
    points += 3;
  }
EXIT:
  free(work);
  free(basis_fns);
  return result;
}
```