user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<dtw_distance>:
  endbr64
  push   %r15
  push   %r14
  mov    %r8d,%r14d
  push   %r13
  mov    %rsi,%r13
  push   %r12
  lea    (%r8,%r8,1),%r12d
  push   %rbp
  lea    0x1(%r12),%r15d
  push   %rbx
  mov    %rdi,%rbx
  lea    0x0(,%r15,8),%edi
  sub    $0x48,%rsp
  mov    %edi,(%rsp)
  mov    %rdx,0x28(%rsp)
  mov    %ecx,0x38(%rsp)
  mov    %r12d,0x3c(%rsp)
  movsd  %xmm0,0x30(%rsp)
  call   <malloc@plt>
  test   %r12d,%r12d
  mov    (%rsp),%edi
  mov    %rax,%rbp
  js     L146
  test   %r14d,%r14d
  je     L107
  mov    %r15d,%edx
  movapd D16(%rip),%xmm0
  shr    %edx
  shl    $0x4,%rdx
  add    %rax,%rdx
  nopl   0x0(%rax)
L181:
  movups %xmm0,(%rax)
  add    $0x10,%rax
  cmp    %rdx,%rax
  jne    L181
  mov    %r15d,%eax
  and    $0xfffffffe,%eax
  cmp    %r15d,%eax
  je     L150
L167:
  movsd  D16(%rip),%xmm2
  cltq
  movsd  %xmm2,0x0(%rbp,%rax,8)
  movsd  %xmm2,(%rsp)
  call   <malloc@plt>
  test   %r14d,%r14d
  movsd  (%rsp),%xmm2
  mov    %rax,%r12
  je     L188
  movapd D16(%rip),%xmm0
L75:
  mov    %r15d,%edx
  shr    %edx
  shl    $0x4,%rdx
  add    %rax,%rdx
  nopw   0x0(%rax,%rax,1)
L250:
  movups %xmm0,(%rax)
  add    $0x10,%rax
  cmp    %rdx,%rax
  jne    L250
  mov    %r15d,%eax
  movsd  D16(%rip),%xmm2
  and    $0xfffffffe,%eax
  and    $0x1,%r15d
  je     L118
L226:
  cltq
  movsd  %xmm2,(%r12,%rax,8)
L118:
  movslq 0x3c(%rsp),%rax
  shl    $0x3,%rax
L157:
  mov    0x38(%rsp),%edi
  test   %edi,%edi
  jle    L46
  movslq %edi,%rax
  mov    0x3c(%rsp),%r15d
  mov    %r14d,%r8d
  mov    %r14d,%r9d
  lea    -0x1(%rax),%edi
  mov    %rax,0x20(%rsp)
  movsd  D16(%rip),%xmm2
  xor    %r10d,%r10d
  mov    %edi,0x1c(%rsp)
  nopw   0x0(%rax,%rax,1)
L186:
  xor    %eax,%eax
  test   %r8d,%r8d
  mov    %r8d,%edi
  mov    0x1c(%rsp),%ecx
  cmovns %r8d,%eax
  neg    %edi
  movapd %xmm2,%xmm0
  mov    %r10d,%esi
  mov    %eax,(%rsp)
  mov    $0x0,%eax
  movslq (%rsp),%rdx
  cmovs  %eax,%edi
  cmp    0x38(%rsp),%r9d
  cmovl  %r9d,%ecx
  movslq %edi,%rax
  test   %r10,%r10
  je     L203
  cmp    %edi,%ecx
  jge    L78
  jmp    L349
  cs nopw 0x0(%rax,%rax,1)
L330:
  mov    %eax,%r14d
  mov    %edx,%r11d
  test   %edx,%edx
  jle    L335
  test   %eax,%eax
  jle    L335
  movsd  -0x8(%rbp,%rdx,8),%xmm1
  cmp    %edx,%r15d
  jg     L163
  movapd %xmm2,%xmm4
L279:
  movsd  (%r12,%rdx,8),%xmm3
L102:
  minsd  %xmm1,%xmm4
  movapd %xmm4,%xmm1
  minsd  %xmm3,%xmm1
  movapd %xmm1,%xmm3
  movsd  (%rbx,%r10,8),%xmm1
  subsd  0x0(%r13,%rax,8),%xmm1
  mulsd  %xmm1,%xmm1
  addsd  %xmm3,%xmm1
  movapd %xmm1,%xmm5
  minsd  %xmm0,%xmm5
  movapd %xmm5,%xmm0
L101:
  add    $0x1,%rax
  movsd  %xmm1,0x0(%rbp,%rdx,8)
  add    $0x1,%rdx
  cmp    %eax,%ecx
  jl     L349
L78:
  mov    %esi,%r14d
  or     %eax,%r14d
  jne    L330
  movsd  (%rbx),%xmm0
  subsd  0x0(%r13),%xmm0
  mulsd  %xmm0,%xmm0
  movapd %xmm0,%xmm1
  jmp    L101
  nopw   0x0(%rax,%rax,1)
L335:
  movapd %xmm2,%xmm1
  movapd %xmm2,%xmm4
  cmp    %r11d,%r15d
  jle    L252
L163:
  lea    0x1(%rdx),%r11d
  movslq %r11d,%r11
  movsd  (%r12,%r11,8),%xmm4
L252:
  test   %r14d,%r14d
  jg     L279
  movapd %xmm2,%xmm3
  jmp    L102
  nopl   0x0(%rax)
L349:
  add    $0x1,%ecx
  xor    %esi,%esi
  mov    %ecx,%eax
  sub    %edi,%eax
  cmp    %edi,%ecx
  cmovl  %esi,%eax
  add    (%rsp),%eax
  cmp    0x1c(%rsp),%r9d
  jl     L33
  add    $0x1,%r9d
L267:
  add    $0x1,%r10
  sub    $0x1,%r8d
  cmp    0x20(%rsp),%r10
  je     L249
  mov    %rbp,%rax
  mov    %r12,%rbp
  mov    %rax,%r12
  jmp    L186
  nopl   (%rax)
L33:
  add    $0x1,%r9d
  mov    0x28(%rsp),%rdi
  movslq %r9d,%rdx
  lea    (%rdi,%rdx,8),%r14
  movsd  (%r14),%xmm1
  addsd  %xmm0,%xmm1
  comisd 0x30(%rsp),%xmm1
  jb     L267
  mov    %rbp,%rdi
  movsd  %xmm0,(%rsp)
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  movsd  (%rsp),%xmm0
  addsd  (%r14),%xmm0
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L203:
  cmp    %edi,%ecx
  jge    L194
  jmp    L349
  nopl   0x0(%rax)
L79:
  test   %eax,%eax
  jle    L152
  test   %edx,%edx
  jle    L152
  movsd  -0x8(%rbp,%rdx,8),%xmm3
  comisd %xmm2,%xmm3
  jbe    L359
L152:
  movapd %xmm2,%xmm3
L317:
  movsd  (%rbx),%xmm1
  subsd  0x0(%r13,%rax,8),%xmm1
  mulsd  %xmm1,%xmm1
  addsd  %xmm3,%xmm1
  movapd %xmm1,%xmm6
  minsd  %xmm0,%xmm6
  movapd %xmm6,%xmm0
L199:
  add    $0x1,%rax
  movsd  %xmm1,0x0(%rbp,%rdx,8)
  add    $0x1,%rdx
  cmp    %eax,%ecx
  jl     L349
L194:
  mov    %esi,%r11d
  or     %eax,%r11d
  jne    L79
  movsd  (%rbx),%xmm0
  subsd  0x0(%r13),%xmm0
  mulsd  %xmm0,%xmm0
  movapd %xmm0,%xmm1
  jmp    L199
  nopl   0x0(%rax)
L359:
  minsd  %xmm2,%xmm3
  jmp    L317
L188:
  xor    %eax,%eax
  jmp    L226
L249:
  sub    $0x1,%eax
  cltq
  shl    $0x3,%rax
L44:
  movsd  0x0(%rbp,%rax,1),%xmm0
  mov    %r12,%rdi
  movsd  %xmm0,(%rsp)
  call   <free@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  movsd  (%rsp),%xmm0
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L150:
  movaps %xmm0,(%rsp)
  call   <malloc@plt>
  movapd (%rsp),%xmm0
  mov    %rax,%r12
  jmp    L75
L146:
  call   <malloc@plt>
  mov    %rax,%r12
  mov    $0xfffffffffffffff8,%rax
  jmp    L157
L107:
  xor    %eax,%eax
  jmp    L167
L46:
  mov    %r12,%rdx
  mov    %rbp,%r12
  mov    %rdx,%rbp
  jmp    L44
```

tool_calls: name: disassemble_data
arguments: tag: D16
datatype: f64[2]

tool: {"D16": [1e20,1e20]}

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;
}
```