user: Converte this assembly snippet into its equivalent C code:

```asm
<calculate_weights>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %edi,-0x34(%rbp)
  mov    %esi,-0x38(%rbp)
  mov    %rdx,-0x40(%rbp)
  mov    %rcx,-0x48(%rbp)
  mov    %r8,-0x50(%rbp)
  mov    %r9d,-0x54(%rbp)
  mov    0x10(%rbp),%eax
  movsd  %xmm0,-0x60(%rbp)
  movsd  %xmm1,-0x68(%rbp)
  mov    %al,-0x58(%rbp)
  cmpl   $0x0,-0x54(%rbp)
  jne    L118
  mov    -0x38(%rbp),%eax
  jmp    L103
L118:
  mov    -0x34(%rbp),%eax
L103:
  mov    %eax,-0x28(%rbp)
  cmpl   $0x0,-0x54(%rbp)
  jne    L127
  mov    -0x34(%rbp),%eax
  jmp    L63
L127:
  mov    -0x38(%rbp),%eax
L63:
  mov    %eax,-0x24(%rbp)
  movsbl -0x58(%rbp),%eax
  mov    %eax,%edi
  call   <setmetric@plt>
  cltq
  mov    %rax,-0x20(%rbp)
  mov    -0x24(%rbp),%eax
  cltq
  shl    $0x3,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L18
  mov    $0x0,%eax
  jmp    L105
L18:
  mov    -0x24(%rbp),%eax
  cltq
  shl    $0x3,%eax
  mov    %eax,%edx
  mov    -0x18(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movl   $0x0,-0x30(%rbp)
  jmp    L33
L5:
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  D18(%rip),%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  movl   $0x0,-0x2c(%rbp)
  jmp    L126
L3:
  mov    -0x50(%rbp),%r9
  mov    -0x48(%rbp),%r8
  mov    -0x48(%rbp),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0x40(%rbp),%rsi
  mov    -0x28(%rbp),%eax
  sub    $0x8,%rsp
  mov    -0x54(%rbp),%edi
  push   %rdi
  mov    -0x2c(%rbp),%edi
  push   %rdi
  mov    -0x30(%rbp),%edi
  push   %rdi
  mov    -0x20(%rbp),%r10
  mov    %eax,%edi
  call   *%r10
  add    $0x20,%rsp
  movq   %xmm0,%rax
  mov    %rax,-0x10(%rbp)
  movsd  -0x60(%rbp),%xmm0
  comisd -0x10(%rbp),%xmm0
  jbe    L32
  movsd  -0x10(%rbp),%xmm0
  movapd %xmm0,%xmm1
  divsd  -0x60(%rbp),%xmm1
  movsd  D18(%rip),%xmm0
  subsd  %xmm1,%xmm0
  cvttsd2si %xmm0,%eax
  mov    %eax,%edi
  call   <log@plt>
  movq   %xmm0,%rax
  movq   %rax,%xmm2
  mulsd  -0x68(%rbp),%xmm2
  movq   %xmm2,%rax
  movq   %rax,%xmm0
  call   <exp@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  addsd  -0x8(%rbp),%xmm0
  movsd  %xmm0,(%rax)
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  addsd  -0x8(%rbp),%xmm0
  movsd  %xmm0,(%rax)
L32:
  addl   $0x1,-0x2c(%rbp)
L126:
  mov    -0x2c(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jl     L3
  addl   $0x1,-0x30(%rbp)
L33:
  mov    -0x30(%rbp),%eax
  cmp    -0x24(%rbp),%eax
  jl     L5
  movl   $0x0,-0x30(%rbp)
  jmp    L101
L104:
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  D18(%rip),%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  addl   $0x1,-0x30(%rbp)
L101:
  mov    -0x30(%rbp),%eax
  cmp    -0x24(%rbp),%eax
  jl     L104
  mov    -0x18(%rbp),%rax
L105:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: label: D18
type_infered: f64

tool: D18: 1

assistant: ```c
double *calculate_weights(int nrows, int ncolumns, double **data, int **mask, double weights[], int transpose, char dist, double cutoff, double exponent) {
  int i, j;
  const int ndata = (transpose == 0) ? ncolumns : nrows;
  const int nelements = (transpose == 0) ? nrows : ncolumns;
  double (*metric)(int, double **, double **, int **, int **, const double[], int, int, int) = setmetric(dist);
  double *result = malloc(nelements * sizeof(double));
  if (!result)
    return NULL;
  memset(result, 0, nelements * sizeof(double));
  for (i = 0; i < nelements; i++) {
    result[i] += 1.0;
    for (j = 0; j < i; j++) {
      const double distance = metric(ndata, data, data, mask, mask, weights, i, j, transpose);
      if (distance < cutoff) {
        const double dweight = exp(exponent * log(1 - distance / cutoff));
        result[i] += dweight;
        result[j] += dweight;
      }
    }
  }
  for (i = 0; i < nelements; i++)
    result[i] = 1.0 / result[i];
  return result;
}
```