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

```asm
<distance2>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%r10
  mov    %rsi,%r11
  mov    %edx,%esi
  mov    %edx,-0x20(%rsp)
  mov    %ecx,%edi
  mov    %ecx,-0x8(%rsp)
  mov    %r9d,%edx
  mov    0x50(%rsp),%r9d
  mov    0x58(%rsp),%r14d
  mov    0x48(%rsp),%ecx
  neg    %ecx
  cmp    %ecx,0x48(%rsp)
  jl     L45
  mov    0x60(%rsp),%ebx
  add    %ebx,%ebx
  mov    %ebx,-0x14(%rsp)
  lea    (%r14,%r14,1),%r15d
  lea    (%r9,%r9,1),%ebx
  mov    %r14d,%ecx
  imul   %r9d,%ecx
  mov    %ecx,-0x10(%rsp)
  mov    %r8d,%ecx
  sub    0x48(%rsp),%ecx
  mov    %ecx,-0x18(%rsp)
  mov    0x48(%rsp),%ecx
  lea    0x1(%r8,%rcx,1),%ecx
  mov    %ecx,-0xc(%rsp)
  pxor   %xmm2,%xmm2
  mov    0x40(%rsp),%ecx
  sub    %r8d,%ecx
  mov    %ecx,-0x4(%rsp)
  mov    0x48(%rsp),%eax
  lea    0x1(%rdi,%rax,1),%eax
  mov    %eax,-0x24(%rsp)
  mov    0x38(%rsp),%eax
  sub    %edi,%eax
  mov    %eax,-0x1c(%rsp)
  mov    0x48(%rsp),%eax
  lea    0x1(%rsi,%rax,1),%r12d
  sub    %esi,%edx
  mov    %edx,%ebp
L12:
  mov    -0x18(%rsp),%eax
  mov    %eax,%edx
  neg    %edx
  cmovs  %eax,%edx
  mov    -0x4(%rsp),%ecx
  add    %eax,%ecx
  mov    %ecx,%eax
  neg    %eax
  cmovs  %ecx,%eax
  mov    -0x14(%rsp),%edi
  mov    %edi,%ecx
  sub    %edx,%ecx
  sub    $0x1,%ecx
  cmp    0x60(%rsp),%edx
  cmovge %ecx,%edx
  sub    %eax,%edi
  mov    %edi,%ecx
  sub    $0x1,%ecx
  cmp    0x60(%rsp),%eax
  cmovge %ecx,%eax
  mov    -0x10(%rsp),%edi
  imul   %edi,%edx
  mov    %edx,-0x2c(%rsp)
  imul   %edi,%eax
  mov    %eax,-0x28(%rsp)
  mov    -0x8(%rsp),%r13d
  sub    0x48(%rsp),%r13d
L4:
  mov    %r13d,%r8d
  neg    %r8d
  cmovs  %r13d,%r8d
  mov    -0x1c(%rsp),%eax
  add    %r13d,%eax
  mov    %eax,%edi
  neg    %edi
  cmovs  %eax,%edi
  mov    %r15d,%eax
  sub    %r8d,%eax
  sub    $0x1,%eax
  cmp    %r14d,%r8d
  cmovge %eax,%r8d
  mov    %r15d,%eax
  sub    %edi,%eax
  sub    $0x1,%eax
  cmp    %r14d,%edi
  cmovge %eax,%edi
  imul   %r9d,%r8d
  add    -0x2c(%rsp),%r8d
  imul   %r9d,%edi
  add    -0x28(%rsp),%edi
  mov    -0x20(%rsp),%ecx
  sub    0x48(%rsp),%ecx
L36:
  mov    %ecx,%edx
  neg    %edx
  cmovs  %ecx,%edx
  lea    0x0(%rbp,%rcx,1),%esi
  mov    %esi,%eax
  neg    %eax
  cmovs  %esi,%eax
  mov    %ebx,%esi
  sub    %edx,%esi
  sub    $0x1,%esi
  cmp    %r9d,%edx
  cmovge %esi,%edx
  mov    %ebx,%esi
  sub    %eax,%esi
  sub    $0x1,%esi
  cmp    %r9d,%eax
  cmovge %esi,%eax
  add    %r8d,%edx
  movslq %edx,%rdx
  add    %edi,%eax
  cltq
  pxor   %xmm0,%xmm0
  cvtss2sd (%r10,%rdx,4),%xmm0
  pxor   %xmm1,%xmm1
  cvtss2sd (%r11,%rdx,4),%xmm1
  subsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtss2sd (%r10,%rax,4),%xmm1
  pxor   %xmm3,%xmm3
  cvtss2sd (%r11,%rax,4),%xmm3
  subsd  %xmm3,%xmm1
  subsd  %xmm1,%xmm0
  mulsd  %xmm0,%xmm0
  addsd  %xmm0,%xmm2
  add    $0x1,%ecx
  cmp    %r12d,%ecx
  jne    L36
  add    $0x1,%r13d
  cmp    -0x24(%rsp),%r13d
  jne    L4
  addl   $0x1,-0x18(%rsp)
  mov    -0x18(%rsp),%eax
  cmp    -0xc(%rsp),%eax
  jne    L12
L2:
  mov    0x48(%rsp),%eax
  lea    0x1(%rax,%rax,1),%edx
  mov    %edx,%eax
  imul   %edx,%eax
  imul   %edx,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  divsd  %xmm0,%xmm2
  movapd %xmm2,%xmm0
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L45:
  pxor   %xmm2,%xmm2
  jmp    L2
```

assistant: ```c
double distance2(float *ima, float *medias, int x, int y, int z, int nx, int ny, int nz, int f, int sx, int sy, int sz) {
  double d, acu, distancetotal;
  int i, j, k, ni1, nj1, ni2, nj2, nk1, nk2;
  acu = 0;
  distancetotal = 0;
  for (k = -f; k <= f; k++) {
    nk1 = z + k;
    nk2 = nz + k;
    if (nk1 < 0)
      nk1 = -nk1;
    if (nk2 < 0)
      nk2 = -nk2;
    if (nk1 >= sz)
      nk1 = 2 * sz - nk1 - 1;
    if (nk2 >= sz)
      nk2 = 2 * sz - nk2 - 1;
    for (j = -f; j <= f; j++) {
      nj1 = y + j;
      nj2 = ny + j;
      if (nj1 < 0)
        nj1 = -nj1;
      if (nj2 < 0)
        nj2 = -nj2;
      if (nj1 >= sy)
        nj1 = 2 * sy - nj1 - 1;
      if (nj2 >= sy)
        nj2 = 2 * sy - nj2 - 1;
      for (i = -f; i <= f; i++) {
        ni1 = x + i;
        ni2 = nx + i;
        if (ni1 < 0)
          ni1 = -ni1;
        if (ni2 < 0)
          ni2 = -ni2;
        if (ni1 >= sx)
          ni1 = 2 * sx - ni1 - 1;
        if (ni2 >= sx)
          ni2 = 2 * sx - ni2 - 1;
        d = ((double)ima[nk1 * (sx * sy) + (nj1 * sx) + ni1] - (double)medias[nk1 * (sx * sy) + (nj1 * sx) + ni1]) - ((double)ima[nk2 * (sx * sy) + (nj2 * sx) + ni2] - (double)medias[nk2 * (sx * sy) + (nj2 * sx) + ni2]);
        distancetotal += d * d;
      }
    }
  }
  acu = (2 * f + 1) * (2 * f + 1) * (2 * f + 1);
  d = distancetotal / acu;
  return d;
}
```