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

```asm
<dtw_distance>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%r13
  mov    %rdx,0x8(%rsp)
  mov    %ecx,0x1c(%rsp)
  mov    %r8d,0x28(%rsp)
  movsd  %xmm0,0x38(%rsp)
  lea    (%r8,%r8,1),%r12d
  lea    0x1(%r12),%r14d
  lea    0x0(,%r14,8),%r15d
  mov    %r15d,%edi
  call   <malloc@plt>
  mov    %rax,0x20(%rsp)
  mov    %rax,%rbx
  test   %r12d,%r12d
  js     L93
  lea    0x1(%r12),%edx
  lea    0x0(,%rdx,8),%rsi
  mov    %rsi,0x10(%rsp)
  mov    %rsi,%rdx
  add    %rax,%rdx
  movsd  D19(%rip),%xmm0
L189:
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L189
  mov    %r15d,%edi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    0x10(%rsp),%rdx
  add    %rax,%rdx
  movsd  D19(%rip),%xmm0
L231:
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L231
L61:
  mov    0x1c(%rsp),%ecx
  test   %ecx,%ecx
  jle    L14
  movslq 0x28(%rsp),%rax
  mov    0x8(%rsp),%rsi
  lea    0x8(%rsi,%rax,8),%rax
  mov    %rax,0x10(%rsp)
  mov    %ecx,%eax
  lea    -0x1(%rcx),%ecx
  mov    %ecx,0x20(%rsp)
  mov    %eax,%ecx
  mov    %rcx,0x30(%rsp)
  mov    $0x0,%ecx
  movsd  D19(%rip),%xmm3
  sub    $0x1,%eax
  mov    %eax,0x2c(%rsp)
  jmp    L219
L1:
  movsd  0x0(%rbp),%xmm0
  subsd  0x0(%r13),%xmm0
  movapd %xmm0,%xmm1
  mulsd  %xmm0,%xmm1
  movsd  %xmm1,(%rbx,%rdx,8)
  jmp    L21
L190:
  movsd  D19(%rip),%xmm0
  jmp    L18
L37:
  movapd %xmm3,%xmm4
L25:
  test   %sil,%sil
  jne    L141
  test   %r8b,%r8b
  jne    L141
  movsd  (%r15,%rdx,8),%xmm2
  jmp    L233
L141:
  movsd  D19(%rip),%xmm2
L233:
  minsd  %xmm0,%xmm4
  movapd %xmm4,%xmm0
  minsd  %xmm2,%xmm0
  movapd %xmm0,%xmm2
  movsd  0x0(%rbp,%rcx,8),%xmm0
  subsd  0x0(%r13,%rax,8),%xmm0
  mulsd  %xmm0,%xmm0
  addsd  %xmm2,%xmm0
  movsd  %xmm0,(%rbx,%rdx,8)
  minsd  %xmm1,%xmm0
  movapd %xmm0,%xmm1
L21:
  add    $0x1,%rax
  add    $0x1,%rdx
L22:
  mov    %eax,%esi
  cmp    %eax,%edi
  jl     L142
  mov    %r10d,%r9d
  or     %eax,%r9d
  je     L1
  test   %esi,%esi
  setle  %sil
  mov    %edx,%r9d
  test   %edx,%edx
  jle    L190
  test   %sil,%sil
  jne    L190
  movsd  -0x8(%rbx,%rdx,8),%xmm0
L18:
  test   %ecx,%ecx
  setle  %r8b
  cmp    %r9d,%r12d
  jle    L37
  test   %r8b,%r8b
  jne    L37
  movsd  0x8(%r15,%rdx,8),%xmm4
  jmp    L25
L142:
  add    $0x1,%edi
  mov    %edi,%eax
  sub    %r11d,%eax
  cmp    %edi,%r11d
  mov    $0x0,%edi
  cmovg  %edi,%eax
  add    %r14d,%eax
  mov    0x8(%rsp),%edi
  cmp    %edi,0x2c(%rsp)
  jle    L184
  mov    0x10(%rsp),%rdi
  movapd %xmm1,%xmm0
  addsd  (%rdi),%xmm0
  comisd 0x38(%rsp),%xmm0
  jae    L3
L184:
  add    $0x1,%rcx
  addq   $0x8,0x10(%rsp)
  cmp    0x30(%rsp),%rcx
  je     L28
  mov    %rbx,%rax
  mov    %r15,%rbx
  mov    %rax,%r15
L219:
  mov    %ecx,%r10d
  mov    0x28(%rsp),%edi
  mov    %edi,%r14d
  sub    %ecx,%r14d
  mov    $0x0,%eax
  cmovs  %eax,%r14d
  mov    %ecx,%r11d
  sub    %edi,%r11d
  cmovs  %eax,%r11d
  lea    (%rdi,%rcx,1),%eax
  mov    %eax,0x8(%rsp)
  cmp    %eax,0x1c(%rsp)
  mov    %eax,%edi
  cmovle 0x20(%rsp),%edi
  movslq %r11d,%rax
  movslq %r14d,%rdx
  movsd  D19(%rip),%xmm1
  jmp    L22
L3:
  mov    %rdi,%r14
  movq   %xmm1,%rbp
  mov    %rbx,%rdi
  call   <free@plt>
  mov    %r15,%rdi
  call   <free@plt>
  movq   %rbp,%xmm6
  addsd  (%r14),%xmm6
  movq   %xmm6,%r12
  jmp    L187
L28:
  mov    %eax,%r14d
L156:
  lea    -0x1(%r14),%eax
  cltq
  mov    (%rbx,%rax,8),%r12
  mov    %r15,%rdi
  call   <free@plt>
  mov    %rbx,%rdi
  call   <free@plt>
L187:
  movq   %r12,%xmm0
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L14:
  mov    %r15,%rbx
  mov    0x20(%rsp),%r15
  jmp    L156
L93:
  mov    %r15d,%edi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    $0x0,%r14d
  jmp    L61
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D19
data_type: f64

tool: D19: 1e+20

assistant: ```c
double dtw_distance(double *A, double *B, double *cb, int m, int r, double bsf) {
  double final_dtw;
  double *cost;
  double *cost_prev;
  double *cost_tmp;
  int i, j, k;
  double x, y, z, min_cost;
  cost = (double *)malloc(sizeof(double) * (2 * r + 1));
  for (k = 0; k < 2 * r + 1; k++)
    cost[k] = 1e20;
  cost_prev = (double *)malloc(sizeof(double) * (2 * r + 1));
  for (k = 0; k < 2 * r + 1; k++)
    cost_prev[k] = 1e20;
  for (i = 0; i < m; i++) {
    k = ((0) > (r - i) ? (0) : (r - i));
    min_cost = 1e20;
    for (j = ((0) > (i - r) ? (0) : (i - r)); j <= ((m - 1) < (i + r) ? (m - 1) : (i + r)); j++, k++) {
      if ((i == 0) && (j == 0)) {
        cost[k] = ((A[0] - B[0]) * (A[0] - B[0]));
        min_cost = cost[k];
        continue;
      }
      if ((j - 1 < 0) || (k - 1 < 0))
        y = 1e20;
      else
        y = cost[k - 1];
      if ((i - 1 < 0) || (k + 1 > 2 * r))
        x = 1e20;
      else
        x = cost_prev[k + 1];
      if ((i - 1 < 0) || (j - 1 < 0))
        z = 1e20;
      else
        z = cost_prev[k];
      cost[k] = ((((x) < (y) ? (x) : (y))) < (z) ? (((x) < (y) ? (x) : (y))) : (z)) + ((A[i] - B[j]) * (A[i] - B[j]));
      if (cost[k] < min_cost) {
        min_cost = cost[k];
      }
    }
    if (i + r < m - 1 && min_cost + cb[i + r + 1] >= bsf) {
      free(cost);
      free(cost_prev);
      return min_cost + cb[i + r + 1];
    }
    cost_tmp = cost;
    cost = cost_prev;
    cost_prev = cost_tmp;
  }
  k--;
  final_dtw = cost_prev[k];
  free(cost);
  free(cost_prev);
  return final_dtw;
}
```