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

```asm
<aligndistance>:
  endbr64
  push   %r15
  mov    %r9d,%eax
  mov    %rdi,%r11
  push   %r14
  imul   %r9d,%eax
  push   %r13
  push   %r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x40,%rsp
  mov    %eax,0x1c(%rsp)
  test   %r9d,%r9d
  jle    L85
  mov    %r9d,%edi
  mov    %rcx,%rsi
  lea    0x18(%rcx),%r10
  movslq %r9d,%rax
  and    $0xfffffffc,%edi
  mov    %rax,-0x50(%rsp)
  mov    %r9d,%r13d
  lea    (%rax,%rax,2),%rax
  lea    (%rdi,%rdi,2),%edx
  lea    (%r8,%rax,8),%rax
  mov    %edi,-0x20(%rsp)
  movdqa D57(%rip),%xmm9
  movslq %edx,%rcx
  mov    %rax,-0x60(%rsp)
  mov    %r9d,%eax
  shl    $0x3,%rcx
  shr    $0x2,%eax
  movl   $0x0,-0x48(%rsp)
  lea    (%r8,%rcx,1),%r14
  sub    $0x1,%eax
  mov    %r8,-0x68(%rsp)
  mov    %r14,-0x38(%rsp)
  lea    0x8(%r8,%rcx,1),%r14
  add    $0x1,%rax
  lea    0x10(%r8,%rcx,1),%rcx
  mov    %rcx,-0x28(%rsp)
  lea    0x1(%rdi),%ecx
  shl    $0x5,%rax
  mov    %ecx,-0x1c(%rsp)
  lea    0x3(%rdx),%ecx
  add    $0x6,%edx
  movslq %ecx,%rcx
  mov    %r14,-0x30(%rsp)
  movslq %edx,%rdx
  shl    $0x3,%rcx
  shl    $0x3,%rdx
  mov    %rax,-0x40(%rsp)
  mov    %r9d,%eax
  lea    (%r8,%rcx,1),%r14
  movl   $0x0,-0x6c(%rsp)
  mov    %r14,-0x18(%rsp)
  lea    0x8(%r8,%rcx,1),%r14
  lea    0x10(%r8,%rcx,1),%rcx
  mov    %rcx,-0x8(%rsp)
  lea    0x2(%rdi),%ecx
  mov    %ecx,0x18(%rsp)
  lea    (%r8,%rdx,1),%rcx
  mov    %rcx,(%rsp)
  lea    0x8(%r8,%rdx,1),%rcx
  mov    %rcx,0x8(%rsp)
  lea    0x10(%r8,%rdx,1),%rcx
  mov    %rcx,0x10(%rsp)
  lea    -0x1(%r9),%ecx
  mov    %r14,-0x10(%rsp)
  mov    %ecx,-0x44(%rsp)
  mov    %rax,0x28(%rsp)
  xchg   %ax,%ax
L306:
  movslq -0x48(%rsp),%rdi
  pxor   %xmm8,%xmm8
  cvtsi2sdl -0x6c(%rsp),%xmm8
  lea    0x0(,%rdi,8),%rax
  add    -0x50(%rsp),%rdi
  lea    0x8(%rax),%rdx
  shl    $0x3,%rdi
  lea    (%rbx,%rax,1),%rcx
  lea    (%r11,%rdi,1),%r8
  lea    (%rbx,%rdi,1),%r14
  mov    %rdx,-0x58(%rsp)
  add    %rbp,%rdi
  lea    (%r11,%rdx,1),%r12
  lea    0x0(%rbp,%rax,1),%rdx
  add    %r11,%rax
  cmp    %r8,-0x68(%rsp)
  setae  %r15b
  cmp    %rax,-0x60(%rsp)
  setbe  %r9b
  or     %r9d,%r15d
  cmp    %rsi,%r8
  setbe  %r9b
  cmp    %r10,%rax
  setae  %r8b
  or     %r9d,%r8d
  and    %r15d,%r8d
  cmpl   $0x2,-0x44(%rsp)
  seta   %r9b
  and    %r9d,%r8d
  cmp    %rsi,%r14
  setbe  %r9b
  cmp    %r10,%rcx
  setae  %r15b
  or     %r15d,%r9d
  and    %r9d,%r8d
  cmp    %rcx,-0x60(%rsp)
  mov    %r8d,%r15d
  setbe  %r8b
  cmp    -0x68(%rsp),%r14
  setbe  %r9b
  or     %r8d,%r9d
  and    %r15d,%r9d
  cmp    %r10,%rdx
  setae  %r8b
  cmp    %rsi,%rdi
  setbe  %r14b
  or     %r14d,%r8d
  and    %r9d,%r8d
  cmp    %rdx,-0x60(%rsp)
  setbe  %r9b
  cmp    %rdi,-0x68(%rsp)
  setae  %dil
  or     %edi,%r9d
  mov    %rcx,%rdi
  sub    %r12,%rdi
  and    %r8d,%r9d
  mov    %rdx,%r8
  cmp    $0x10,%rdi
  seta   %dil
  sub    %r12,%r8
  and    %r9d,%edi
  cmp    $0x10,%r8
  seta   %r8b
  test   %r8b,%dil
  je     L283
  mov    -0x58(%rsp),%r12
  mov    %rdx,%rdi
  add    %rbx,%r12
  sub    %r12,%rdi
  cmp    $0x10,%rdi
  jbe    L283
  movsd  (%rsi),%xmm7
  movsd  0x8(%rsi),%xmm6
  movapd %xmm8,%xmm4
  movsd  0x10(%rsi),%xmm5
  mov    -0x40(%rsp),%r14
  unpcklpd %xmm4,%xmm4
  mov    -0x68(%rsp),%rdi
  movdqa D48(%rip),%xmm3
  unpcklpd %xmm7,%xmm7
  unpcklpd %xmm6,%xmm6
  unpcklpd %xmm5,%xmm5
  lea    (%rax,%r14,1),%r8
  nop
L18:
  movupd (%rdi),%xmm12
  movupd 0x30(%rdi),%xmm14
  movapd %xmm7,%xmm1
  movapd %xmm6,%xmm13
  movdqa %xmm3,%xmm2
  add    $0x20,%rax
  add    $0x60,%rdi
  add    $0x20,%rcx
  movapd %xmm12,%xmm0
  movhps -0x48(%rdi),%xmm0
  movapd %xmm14,%xmm10
  movhps -0x18(%rdi),%xmm10
  movapd %xmm6,%xmm11
  paddd  %xmm9,%xmm3
  add    $0x20,%rdx
  subpd  %xmm0,%xmm1
  movapd %xmm7,%xmm0
  subpd  %xmm10,%xmm0
  movapd %xmm12,%xmm10
  shufpd $0x1,%xmm12,%xmm10
  movhpd -0x40(%rdi),%xmm10
  subpd  %xmm10,%xmm13
  mulpd  %xmm1,%xmm1
  movapd %xmm14,%xmm10
  shufpd $0x1,%xmm14,%xmm10
  mulpd  %xmm0,%xmm0
  movhpd -0x10(%rdi),%xmm10
  subpd  %xmm10,%xmm11
  movupd -0x50(%rdi),%xmm10
  mulpd  %xmm13,%xmm13
  unpcklpd %xmm12,%xmm10
  movhps -0x38(%rdi),%xmm10
  movapd %xmm5,%xmm12
  mulpd  %xmm11,%xmm11
  subpd  %xmm10,%xmm12
  movupd -0x20(%rdi),%xmm10
  unpcklpd %xmm14,%xmm10
  addpd  %xmm13,%xmm1
  mulpd  %xmm12,%xmm12
  movapd %xmm10,%xmm14
  movhps -0x8(%rdi),%xmm14
  movapd %xmm5,%xmm10
  addpd  %xmm11,%xmm0
  subpd  %xmm14,%xmm10
  mulpd  %xmm10,%xmm10
  addpd  %xmm12,%xmm1
  movups %xmm1,-0x20(%rax)
  addpd  %xmm10,%xmm0
  movups %xmm0,-0x10(%rax)
  cvtdq2pd %xmm2,%xmm0
  pshufd $0xee,%xmm2,%xmm2
  movups %xmm4,-0x20(%rcx)
  cvtdq2pd %xmm2,%xmm2
  movups %xmm4,-0x10(%rcx)
  movups %xmm0,-0x20(%rdx)
  movups %xmm2,-0x10(%rdx)
  cmp    %r8,%rax
  jne    L18
  mov    -0x48(%rsp),%eax
  mov    -0x20(%rsp),%ecx
  add    %ecx,%eax
  cmp    %ecx,%r13d
  je     L211
  mov    -0x38(%rsp),%rdx
  movsd  (%rsi),%xmm0
  movsd  0x8(%rsi),%xmm2
  movsd  0x10(%rsi),%xmm1
  subsd  (%rdx),%xmm0
  mov    -0x30(%rsp),%rdx
  subsd  (%rdx),%xmm2
  mov    -0x28(%rsp),%rdx
  mulsd  %xmm0,%xmm0
  subsd  (%rdx),%xmm1
  movslq %eax,%rdx
  add    $0x1,%eax
  mulsd  %xmm2,%xmm2
  mulsd  %xmm1,%xmm1
  addsd  %xmm2,%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%r11,%rdx,8)
  pxor   %xmm0,%xmm0
  cvtsi2sd %ecx,%xmm0
  mov    -0x1c(%rsp),%ecx
  movsd  %xmm8,(%rbx,%rdx,8)
  movsd  %xmm0,0x0(%rbp,%rdx,8)
  cmp    %ecx,%r13d
  jle    L211
  mov    -0x18(%rsp),%rdx
  movsd  (%rsi),%xmm0
  cltq
  movsd  0x8(%rsi),%xmm2
  movsd  0x10(%rsi),%xmm1
  subsd  (%rdx),%xmm0
  mov    -0x10(%rsp),%rdx
  subsd  (%rdx),%xmm2
  mov    -0x8(%rsp),%rdx
  mulsd  %xmm0,%xmm0
  subsd  (%rdx),%xmm1
  lea    0x0(,%rax,8),%rdx
  mulsd  %xmm2,%xmm2
  mulsd  %xmm1,%xmm1
  addsd  %xmm2,%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%r11,%rax,8)
  pxor   %xmm0,%xmm0
  cvtsi2sd %ecx,%xmm0
  movsd  %xmm8,(%rbx,%rax,8)
  movsd  %xmm0,0x0(%rbp,%rax,8)
  mov    0x18(%rsp),%eax
  cmp    %eax,%r13d
  jle    L211
  mov    (%rsp),%rcx
  movsd  (%rsi),%xmm0
  movsd  0x8(%rsi),%xmm2
  movsd  0x10(%rsi),%xmm1
  subsd  (%rcx),%xmm0
  mov    0x8(%rsp),%rcx
  subsd  (%rcx),%xmm2
  mov    0x10(%rsp),%rcx
  mulsd  %xmm0,%xmm0
  subsd  (%rcx),%xmm1
  mulsd  %xmm2,%xmm2
  mulsd  %xmm1,%xmm1
  addsd  %xmm2,%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,0x8(%r11,%rdx,1)
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  movsd  %xmm8,0x8(%rbx,%rdx,1)
  movsd  %xmm0,0x8(%rbp,%rdx,1)
L211:
  addl   $0x1,-0x6c(%rsp)
  mov    -0x6c(%rsp),%eax
  add    $0x18,%r10
  add    $0x18,%rsi
  add    %r13d,-0x48(%rsp)
  cmp    %eax,%r13d
  jne    L306
L37:
  mov    D10(%rip),%rsi
  mov    0x20(%rsp),%ecx
  xor    %eax,%eax
  mov    0x1c(%rsp),%edx
  movq   %rsi,%xmm1
  mov    0x24(%rsp),%esi
  nopl   (%rax)
L147:
  movsd  (%r11,%rax,8),%xmm0
  comisd %xmm0,%xmm1
  jbe    L62
  cvttsd2si (%rbx,%rax,8),%ecx
  movapd %xmm0,%xmm1
  cvttsd2si 0x0(%rbp,%rax,8),%esi
L62:
  add    $0x1,%rax
  cmp    %eax,%edx
  jg     L147
  mov    D10(%rip),%rdx
  mov    %ecx,0x20(%rsp)
  xor    %eax,%eax
  mov    %esi,0x24(%rsp)
  movq   %rdx,%xmm1
  mov    0x1c(%rsp),%edx
  nopl   (%rax)
L263:
  movsd  (%r11,%rax,8),%xmm0
  comisd %xmm0,%xmm1
  jbe    L73
  pxor   %xmm3,%xmm3
  movsd  (%rbx,%rax,8),%xmm2
  cvtsi2sd %ecx,%xmm3
  ucomisd %xmm3,%xmm2
  jp     L108
  je     L73
L108:
  pxor   %xmm4,%xmm4
  movsd  0x0(%rbp,%rax,8),%xmm3
  cvtsi2sd %esi,%xmm4
  ucomisd %xmm4,%xmm3
  jp     L183
  je     L73
L183:
  cvttsd2si %xmm2,%edi
  movapd %xmm0,%xmm1
  mov    %edi,0x30(%rsp)
  cvttsd2si %xmm3,%edi
  mov    %edi,0x34(%rsp)
  nopl   0x0(%rax,%rax,1)
L73:
  add    $0x1,%rax
  cmp    %eax,%edx
  jg     L263
  mov    D10(%rip),%rsi
  mov    0x20(%rsp),%ecx
  xor    %eax,%eax
  mov    0x30(%rsp),%edi
  mov    0x1c(%rsp),%edx
  movq   %rsi,%xmm1
  mov    0x24(%rsp),%esi
  cs nopw 0x0(%rax,%rax,1)
L57:
  movsd  (%r11,%rax,8),%xmm0
  comisd %xmm0,%xmm1
  jbe    L96
  pxor   %xmm3,%xmm3
  movsd  (%rbx,%rax,8),%xmm2
  cvtsi2sd %ecx,%xmm3
  ucomisd %xmm3,%xmm2
  jp     L315
  je     L96
L315:
  pxor   %xmm4,%xmm4
  movsd  0x0(%rbp,%rax,8),%xmm3
  cvtsi2sd %esi,%xmm4
  ucomisd %xmm4,%xmm3
  jp     L43
  je     L96
L43:
  pxor   %xmm4,%xmm4
  cvtsi2sd %edi,%xmm4
  ucomisd %xmm4,%xmm2
  jp     L256
  je     L96
L256:
  pxor   %xmm2,%xmm2
  cvtsi2sdl 0x34(%rsp),%xmm2
  ucomisd %xmm2,%xmm3
  jp     L142
  jne    L142
  nopl   0x0(%rax)
L96:
  add    $0x1,%rax
  cmp    %eax,%edx
  jg     L57
L72:
  add    $0x40,%rsp
  movapd %xmm1,%xmm0
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L283:
  mov    -0x68(%rsp),%r8
  mov    0x28(%rsp),%r9
  xor    %edi,%edi
  nopl   0x0(%rax)
L121:
  movsd  (%rsi),%xmm0
  movsd  0x8(%rsi),%xmm2
  add    $0x18,%r8
  subsd  -0x18(%r8),%xmm0
  subsd  -0x10(%r8),%xmm2
  movsd  0x10(%rsi),%xmm1
  subsd  -0x8(%r8),%xmm1
  mulsd  %xmm0,%xmm0
  mulsd  %xmm2,%xmm2
  mulsd  %xmm1,%xmm1
  addsd  %xmm2,%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax,%rdi,8)
  pxor   %xmm0,%xmm0
  cvtsi2sd %edi,%xmm0
  movsd  %xmm8,(%rcx,%rdi,8)
  movsd  %xmm0,(%rdx,%rdi,8)
  add    $0x1,%rdi
  cmp    %rdi,%r9
  jne    L121
  jmp    L211
L142:
  add    $0x1,%rax
  movapd %xmm0,%xmm1
  cmp    %eax,%edx
  jg     L57
  jmp    L72
L85:
  mov    0x1c(%rsp),%eax
  test   %eax,%eax
  jne    L37
  movsd  D10(%rip),%xmm1
  jmp    L72
```

tool_calls: name: read_data
arguments: label: D57
type: byte[16]
name: read_data
arguments: label: D48
type: byte[16]
name: read_data
arguments: label: D10
type: f64

tool: {"D57": [0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00]}

tool: {"D48": [0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00]}

tool: D10: 10000

assistant: ```c
double aligndistance(double *dists, double *distsA, double *distsB, double *x, double *y, int ats) {
  int i, j, k, dind = 0;
  for (i = 0; i < ats; i++) {
    for (j = 0; j < ats; j++) {
      dists[dind] = (x[3 * i] - y[3 * j]) * (x[3 * i] - y[3 * j]) + (x[3 * i + 1] - y[3 * j + 1]) * (x[3 * i + 1] - y[3 * j + 1]) + (x[3 * i + 2] - y[3 * j + 2]) * (x[3 * i + 2] - y[3 * j + 2]);
      distsA[dind] = i;
      distsB[dind] = j;
      dind++;
    }
  }
  double mind = 10000.0;
  int mindi, mindj;
  for (k = 0; k < ats * ats; k++) {
    if (dists[k] < mind) {
      mind = dists[k];
      mindi = distsA[k];
      mindj = distsB[k];
    }
  }
  double mind2 = 10000.0;
  int mind2i, mind2j;
  for (k = 0; k < ats * ats; k++) {
    if ((dists[k] < mind2) && (distsA[k] != mindi) && (distsB[k] != mindj)) {
      mind2 = dists[k];
      mind2i = distsA[k];
      mind2j = distsB[k];
    }
  }
  double mind3 = 10000.0;
  for (k = 0; k < ats * ats; k++) {
    if ((dists[k] < mind3) && (distsA[k] != mindi) && (distsB[k] != mindj) && (distsA[k] != mind2i) && (distsB[k] != mind2j)) {
      mind3 = dists[k];
    }
  }
  return mind3;
}
```