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

```asm
<calc_dist>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,-0x20(%rsp)
  test   %r8d,%r8d
  jle    L97
  movslq %ecx,%r14
  mov    %rsi,%rdi
  mov    %ecx,%r12d
  mov    %rdx,%rsi
  lea    -0x1(%rcx),%r13d
  lea    0x8(%rdi),%r15
  and    $0xfffffffe,%r12d
  mov    %ecx,%ebx
  mov    %r13d,-0xc(%rsp)
  movslq %r12d,%r10
  xor    %r9d,%r9d
  pxor   %xmm4,%xmm4
  lea    0x0(,%r14,8),%rax
  mov    %r15,-0x18(%rsp)
  lea    (%rdi,%r10,8),%r11
  mov    %rax,-0x30(%rsp)
  movslq %r8d,%rax
  mov    %rax,-0x28(%rsp)
  mov    %ecx,%eax
  shr    %eax
  lea    -0x1(%rax),%r8d
  xor    %eax,%eax
  add    $0x1,%r8
  shl    $0x4,%r8
  nopl   (%rax)
L82:
  mov    %r9d,%r15d
  test   %ebx,%ebx
  jle    L125
  mov    -0x20(%rsp),%rcx
  pxor   %xmm3,%xmm3
  movswl (%rcx,%r9,2),%ecx
  cvtsi2sd %ecx,%xmm3
  cmp    %rdx,-0x18(%rsp)
  je     L106
  cmpl   $0x1,-0xc(%rsp)
  jbe    L106
  movapd %xmm3,%xmm5
  xor    %ecx,%ecx
  movapd %xmm4,%xmm0
  unpcklpd %xmm5,%xmm5
  nopl   0x0(%rax)
L83:
  movupd (%rdi,%rcx,1),%xmm6
  movapd %xmm5,%xmm2
  subpd  %xmm6,%xmm2
  mulpd  %xmm2,%xmm2
  addsd  %xmm2,%xmm0
  movups %xmm2,(%rdx,%rcx,1)
  unpckhpd %xmm2,%xmm2
  add    $0x10,%rcx
  addsd  %xmm2,%xmm0
  cmp    %r8,%rcx
  jne    L83
  cmp    %r12d,%ebx
  je     L124
  subsd  (%r11),%xmm3
  lea    (%rax,%r10,1),%rcx
  movapd %xmm3,%xmm1
  mulsd  %xmm3,%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm1,(%rsi,%rcx,8)
L124:
  ucomisd %xmm4,%xmm0
  jp     L10
  je     L125
L10:
  movapd %xmm0,%xmm2
  lea    (%r8,%rdx,1),%rbp
  mov    %rdx,%rcx
  unpcklpd %xmm2,%xmm2
  nopl   0x0(%rax)
L105:
  movupd (%rcx),%xmm1
  add    $0x10,%rcx
  divpd  %xmm2,%xmm1
  movups %xmm1,-0x10(%rcx)
  cmp    %rbp,%rcx
  jne    L105
  movslq %r12d,%rcx
  cmp    %r12d,%ebx
  je     L92
L114:
  add    %rax,%rcx
  lea    (%rsi,%rcx,8),%rcx
  movsd  (%rcx),%xmm1
  divsd  %xmm0,%xmm1
  movsd  %xmm1,(%rcx)
L92:
  add    $0x1,%r9
  add    %r14,%rax
  add    -0x30(%rsp),%rdx
  cmp    %r9,-0x28(%rsp)
  jne    L82
L97:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L106:
  xor    %ecx,%ecx
  movapd %xmm4,%xmm0
  cs nopw 0x0(%rax,%rax,1)
L9:
  movapd %xmm3,%xmm1
  subsd  (%rdi,%rcx,8),%xmm1
  mov    %rcx,%rbp
  mulsd  %xmm1,%xmm1
  movsd  %xmm1,(%rdx,%rcx,8)
  addsd  %xmm1,%xmm0
  add    $0x1,%rcx
  cmp    %rbp,%r13
  jne    L9
  ucomisd %xmm4,%xmm0
  jp     L72
  je     L125
L72:
  cmp    $0x1,%ebx
  jne    L10
  xor    %ecx,%ecx
  jmp    L114
  nopw   0x0(%rax,%rax,1)
L125:
  pop    %rbx
  mov    %r15d,%esi
  lea    D5(%rip),%rdi
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1050 <printf@plt>
```

tool_calls: name: retrieve_data
arguments: label: D5
datatype: string

tool: D5: div by 0 in dist %d 


assistant: ```c
void calc_dist(short int *img, double *g_avg, double *g_dst, int npart, int npix) {
  int i, j;
  double gsum, tmp;
  for (j = 0; j < npix; ++j) {
    gsum = 0.0;
    for (i = 0; i < npart; ++i) {
      *(g_dst + j * npart + i) = tmp = ((double)*(img + j) - (*(g_avg + i))) * ((double)*(img + j) - (*(g_avg + i)));
      gsum += tmp;
    }
    if (gsum == 0.0) {
      printf("div by 0 in dist %d \n", j);
      return;
    }
    for (i = 0; i < npart; ++i) {
      *(g_dst + j * npart + i) /= gsum;
    }
  }
}
```