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

```asm
<nj_sum_of_branch_lengths>:
  endbr64
  push   %r15
  movslq %ecx,%rcx
  mov    %edx,%r15d
  push   %r14
  mov    %r8d,%r14d
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x58,%rsp
  movsd  D2(%rip),%xmm3
  mov    0x90(%rsp),%rax
  mov    %r9,0x10(%rsp)
  xor    %r9d,%r9d
  mov    %rax,0x18(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  movslq %edx,%rax
  mov    %edx,0x28(%rsp)
  mov    (%rdi,%rax,8),%rax
  mov    %ecx,0x2c(%rsp)
  mulsd  (%rax,%rcx,8),%xmm3
  movsd  %xmm3,0x8(%rsp)
  nopl   0x0(%rax,%rax,1)
L127:
  movslq %r9d,%rdx
  movq   $0x0,0x30(%rsp,%rdx,8)
  test   %r14d,%r14d
  jle    L92
  movslq %r14d,%rbp
  xor    %eax,%eax
  xor    %ecx,%ecx
  nopl   0x0(%rax)
L219:
  mov    (%rbx,%rax,4),%r10d
  test   %r10d,%r10d
  je     L121
  cmp    %eax,%r15d
  je     L121
  cmp    %eax,%r13d
  je     L121
  movslq 0x28(%rsp,%rdx,4),%rsi
  add    $0x1,%ecx
  mov    (%r12,%rsi,8),%rsi
  movsd  (%rsi,%rax,8),%xmm0
  addsd  0x30(%rsp,%rdx,8),%xmm0
  movsd  %xmm0,0x30(%rsp,%rdx,8)
L121:
  add    $0x1,%rax
  cmp    %rbp,%rax
  jne    L219
  test   %ecx,%ecx
  je     L161
  mov    %r9d,%ebp
  mov    %r14d,%eax
  add    $0x1,%r9d
L225:
  pxor   %xmm1,%xmm1
  movslq %ebp,%rdx
  cvtsi2sd %ecx,%xmm1
  movsd  0x30(%rsp,%rdx,8),%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,0x30(%rsp,%rdx,8)
  cmp    $0x1,%r9d
  je     L127
  movsd  0x30(%rsp),%xmm2
  mov    0x10(%rsp),%rdi
  movsd  0x38(%rsp),%xmm0
  movsd  %xmm2,(%rdi)
  movapd %xmm2,%xmm1
  mov    0x18(%rsp),%rdi
  addsd  %xmm0,%xmm1
  mulsd  D2(%rip),%xmm1
  addsd  0x8(%rsp),%xmm1
  movsd  %xmm0,(%rdi)
  test   %r14d,%r14d
  jle    L86
  mov    $0x1,%ecx
  xor    %esi,%esi
  pxor   %xmm0,%xmm0
  mov    -0x4(%rbx,%rcx,4),%edi
  test   %edi,%edi
  je     L203
L110:
  lea    -0x1(%rcx),%edx
  cmp    %r15d,%edx
  je     L203
  cmp    %eax,%r13d
  je     L203
  cmp    %ecx,%r14d
  jle    L112
  mov    %rcx,%rax
  nopl   (%rax)
L58:
  mov    (%rbx,%rax,4),%edx
  test   %edx,%edx
  je     L173
  cmp    %eax,%r15d
  je     L173
  cmp    %eax,%r13d
  je     L173
  mov    -0x8(%r12,%rcx,8),%rdx
  add    $0x1,%esi
  addsd  (%rdx,%rax,8),%xmm0
L173:
  add    $0x1,%rax
  cmp    %eax,%r14d
  jg     L58
  mov    %r14d,%eax
L194:
  add    $0x1,%rcx
  mov    -0x4(%rbx,%rcx,4),%edi
  test   %edi,%edi
  jne    L110
L203:
  cmp    %ecx,%r14d
  jg     L194
L112:
  pxor   %xmm2,%xmm2
  cvtsi2sd %esi,%xmm2
L47:
  divsd  %xmm2,%xmm0
  addsd  %xmm1,%xmm0
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L19
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L161:
  mov    %r13d,%edx
  mov    %r15d,%esi
  lea    D24(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D35(%rip),%rdi
  call   <puts@plt>
  xor    %edx,%edx
  mov    %r12,(%rsp)
  mov    %rbx,%r12
  mov    %rbp,%rbx
  mov    %rdx,%rbp
  nopl   (%rax)
L23:
  mov    (%r12,%rbp,4),%r8d
  mov    %ebp,%esi
  test   %r8d,%r8d
  je     L35
  lea    D42(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
L35:
  add    $0x1,%rbp
  cmp    %rbx,%rbp
  jne    L23
  mov    %r12,%rbx
  mov    (%rsp),%r12
  lea    0x1(%r14),%r9d
  mov    %r14d,%ebp
L140:
  mov    $0xa,%edi
  mov    %r9d,(%rsp)
  call   <putchar@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  mov    (%rsp),%r9d
  mov    %ebp,%eax
  xor    %ecx,%ecx
  jmp    L225
  nopl   (%rax)
L92:
  mov    %r13d,%edx
  mov    %r15d,%esi
  lea    D24(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D35(%rip),%rdi
  xor    %ebp,%ebp
  call   <puts@plt>
  mov    $0x1,%r9d
  jmp    L140
L86:
  pxor   %xmm2,%xmm2
  movapd %xmm2,%xmm0
  jmp    L47
L19:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D2
type_guessed: byte[8]
name: unpack_data
arguments: tag: D24
type_guessed: string
name: unpack_data
arguments: tag: D35
type_guessed: string
name: unpack_data
arguments: tag: D42
type_guessed: string

tool: {"D2": [0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f]}

tool: D24: ** %d %d 


tool: D35: available:  

tool: D42: %4d

assistant: ```c
double nj_sum_of_branch_lengths(double **dist_table, int *current_list, int node_ctr1, int node_ctr2, int tree_size, double *avg1_ptr, double *avg2_ptr) {
  double sum, term;
  double avg[2];
  int current_pair[2] = {node_ctr1, node_ctr2};
  int ctr1, ctr2, n;
  sum = dist_table[node_ctr1][node_ctr2] / 2;
  for (ctr1 = 0; ctr1 < 2; ctr1++) {
    n = 0;
    avg[ctr1] = 0;
    for (ctr2 = 0; ctr2 < tree_size; ctr2++) {
      if (!current_list[ctr2])
        continue;
      if (ctr2 == node_ctr1 || ctr2 == node_ctr2)
        continue;
      avg[ctr1] += dist_table[current_pair[ctr1]][ctr2];
      n++;
    }
    if (!n) {
      printf("** %d %d \n", node_ctr1, node_ctr2);
      printf("available:  \n");
      for (ctr1 = 0; ctr1 < tree_size; ctr1++) {
        if (!current_list[ctr1])
          continue;
        printf("%4d", ctr1);
      }
      printf("\n");
      exit(1);
    }
    avg[ctr1] /= n;
  }
  sum += (avg[0] + avg[1]) / 2;
  *avg1_ptr = avg[0];
  *avg2_ptr = avg[1];
  term = 0;
  n = 0;
  for (ctr1 = 0; ctr1 < tree_size; ctr1++) {
    if (!current_list[ctr1])
      continue;
    if (ctr1 == node_ctr1 || ctr2 == node_ctr2)
      continue;
    for (ctr2 = ctr1 + 1; ctr2 < tree_size; ctr2++) {
      if (!current_list[ctr2])
        continue;
      if (ctr2 == node_ctr1 || ctr2 == node_ctr2)
        continue;
      term += dist_table[ctr1][ctr2];
      n++;
    }
  }
  sum += term / n;
  return sum;
}
```