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

```asm
<CkNNStochasticProximityEmbedding>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x78,%rsp
  mov    %rdi,%r14
  mov    %rsi,%r15
  mov    %edx,0x30(%rsp)
  mov    %ecx,%r12d
  mov    %ecx,0x34(%rsp)
  mov    %r8d,%r13d
  movsd  %xmm0,0x58(%rsp)
  movsd  %xmm1,0x68(%rsp)
  mov    %r9d,0x64(%rsp)
  mov    $0x0,%edi
  call   <time@plt>
  mov    %rax,%rbp
  mov    $0x0,%eax
  call   <getpid@plt>
  mov    %eax,%ebx
  mov    $0x0,%eax
  call   <getpid@plt>
  imul   %eax,%ebx
  movslq %ebx,%rdi
  add    %rbp,%rdi
  call   <srand@plt>
  mov    0x30(%rsp),%edx
  mov    %r12d,%esi
  mov    %r14,%rdi
  call   <nearest_neighbours@plt>
  mov    %rax,0x50(%rsp)
  imul   %r13d,%r12d
  test   %r12d,%r12d
  jle    L93
  mov    %r15,%rbx
  lea    -0x1(%r12),%eax
  lea    0x8(%r15,%rax,8),%rbp
L161:
  mov    $0x0,%eax
  call   <rand@plt>
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  movsd  %xmm0,(%rbx)
  add    $0x8,%rbx
  cmp    %rbp,%rbx
  jne    L161
L93:
  cmpl   $0x0,0x64(%rsp)
  jle    L63
  movslq 0x30(%rsp),%rax
  mov    %rax,0x48(%rsp)
  mov    0x50(%rsp),%rbx
  lea    (%rbx,%rax,4),%rax
  mov    %rax,0x40(%rsp)
  movsd  0x58(%rsp),%xmm7
  movsd  %xmm7,0x28(%rsp)
  movl   $0x0,0x60(%rsp)
  mov    %r15,%rax
  mov    %r14,%r15
  mov    %rax,%r14
  jmp    L13
L158:
  add    $0x4,%r12
  cmp    0x8(%rsp),%r12
  je     L136
L65:
  mov    (%r12),%ebp
  mov    %r13d,%ecx
  mov    %ebp,%edx
  mov    %r14d,%esi
  mov    %rbx,%rdi
  call   <ed@plt>
  movsd  %xmm0,(%rsp)
  mov    %ebp,%esi
  mov    %r14d,%edi
  call   <trmIndex@plt>
  movsd  (%r15,%rax,8),%xmm0
  movsd  (%rsp),%xmm4
  comisd %xmm0,%xmm4
  jbe    L158
  imul   %r13d,%ebp
  movsd  0x28(%rsp),%xmm3
  mulsd  D0(%rip),%xmm3
  movapd %xmm4,%xmm5
  subsd  %xmm4,%xmm0
  mulsd  %xmm0,%xmm3
  addsd  D27(%rip),%xmm5
  divsd  %xmm5,%xmm3
  test   %r13d,%r13d
  jle    L158
  movslq %ebp,%rbp
  lea    (%rbx,%rbp,8),%rax
  mov    0x1c(%rsp),%edx
  add    %rbp,%rdx
  mov    0x20(%rsp),%rdi
  lea    (%rdi,%rdx,8),%rcx
  movslq 0x18(%rsp),%rdx
  sub    %rbp,%rdx
L99:
  movsd  (%rax,%rdx,8),%xmm1
  movapd %xmm1,%xmm0
  subsd  (%rax),%xmm0
  mulsd  %xmm3,%xmm0
  addsd  %xmm0,%xmm1
  movsd  %xmm1,(%rax,%rdx,8)
  movsd  (%rax),%xmm2
  movapd %xmm2,%xmm0
  subsd  %xmm1,%xmm0
  mulsd  %xmm3,%xmm0
  addsd  %xmm2,%xmm0
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L99
  jmp    L158
L136:
  addl   $0x1,0x14(%rsp)
  mov    0x14(%rsp),%eax
  cmp    %eax,0xb0(%rsp)
  je     L4
L12:
  mov    $0x0,%eax
  call   <rand@plt>
  cltd
  idivl  0x34(%rsp)
  mov    %edx,%r14d
  lea    0x1(%rdx),%eax
  mov    0x30(%rsp),%esi
  imul   %esi,%eax
  cmp    %eax,%esi
  jge    L136
  mov    %edx,%edi
  imul   %r13d,%edi
  mov    %edi,0x18(%rsp)
  sub    %esi,%eax
  lea    -0x1(%rax),%eax
  add    0x48(%rsp),%rax
  mov    0x38(%rsp),%rsi
  lea    (%rsi,%rax,4),%rax
  mov    %rax,0x8(%rsp)
  mov    0x40(%rsp),%r12
  lea    -0x1(%r13),%eax
  mov    %eax,0x1c(%rsp)
  lea    0x8(%rbx),%rax
  mov    %rax,0x20(%rsp)
  jmp    L65
L4:
  mov    %rbx,%r14
L89:
  mov    0x60(%rsp),%eax
  cltd
  idivl  0xb8(%rsp)
  test   %edx,%edx
  jne    L39
  mov    0x60(%rsp),%ebx
  test   %ebx,%ebx
  je     L39
  cmpl   $0x0,0xb8(%rsp)
  jg     L96
L39:
  mov    0x64(%rsp),%ebx
  lea    -0x1(%rbx),%eax
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  movsd  0x58(%rsp),%xmm0
  subsd  0x68(%rsp),%xmm0
  divsd  %xmm1,%xmm0
  movsd  0x28(%rsp),%xmm6
  subsd  %xmm0,%xmm6
  movsd  %xmm6,0x28(%rsp)
  addl   $0x1,0x60(%rsp)
  mov    0x60(%rsp),%eax
  cmp    %eax,%ebx
  je     L74
L13:
  movl   $0x0,0x14(%rsp)
  mov    0x50(%rsp),%rax
  add    $0x4,%rax
  mov    %rax,0x38(%rsp)
  mov    %r14,%rbx
  cmpl   $0x0,0xb0(%rsp)
  jg     L12
  jmp    L89
L96:
  mov    0x34(%rsp),%ecx
  mov    %r13d,%edx
  mov    %r14,%rsi
  mov    %r15,%rdi
  call   <stress@plt>
  movsd  0x28(%rsp),%xmm1
  mov    %ebx,%esi
  lea    D11(%rip),%rdi
  call   <printf@plt>
  jmp    L39
L74:
  mov    %r14,%rax
  mov    %r15,%r14
  mov    %rax,%r15
L63:
  mov    0x50(%rsp),%rdi
  call   <free@plt>
  mov    0x34(%rsp),%ecx
  mov    %r13d,%edx
  mov    %r15,%rsi
  mov    %r14,%rdi
  call   <stress@plt>
  add    $0x78,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D0
type: f64
name: retrieve_data
arguments: data_label: D27
type: byte[8]
name: retrieve_data
arguments: data_label: D11
type: string

tool: D0: 0.5

tool: {"D27": [0x3a,0x8c,0x30,0xe2,0x8e,0x79,0x45,0x3e]}

tool: D11: Cycle %d - Residual stress: %.3f, lambda %.3f


assistant: ```c
double CkNNStochasticProximityEmbedding(double *s, double *d_coords, int kn, int nelem, int dim, double maxlam, double minlam, int ncycle, int nstep, int stressfreq) {
  int *tmp;
  int *neighbours;
  int a = 0, b = 0, idx = 0, idxa = 0, idxb = 0, idxak = 0, idxbk = 0, idxab = 0;
  double dab = 0.0, rab = 0.0;
  double lam = maxlam;
  double t = 0.0;
  double finalstress = 0.0;
  srand(time(NULL) + getpid() * getpid());
  neighbours = nearest_neighbours(s, nelem, kn);
  for (int i = 0; i < nelem * dim; i++) {
    d_coords[i] = (double)rand();
  }
  for (int i = 0; i < ncycle; i++) {
    for (int j = 0; j < nstep; j++) {
      a = rand() % nelem;
      for (int k = kn; k < (a + 1) * kn; k++) {
        b = neighbours[k];
        dab = ed(d_coords, a, b, dim);
        rab = s[trmIndex(a, b)];
        if (dab > rab) {
          idxa = a * dim;
          idxb = b * dim;
          t = lam * 0.5 * (rab - dab) / (dab + 1e-8);
          for (int k = 0; k < dim; k++) {
            idxak = idxa + k;
            idxbk = idxb + k;
            d_coords[idxak] = d_coords[idxak] + t * (d_coords[idxak] - d_coords[idxbk]);
            d_coords[idxbk] = d_coords[idxbk] + t * (d_coords[idxbk] - d_coords[idxak]);
          }
        }
      }
    }
    if (i % stressfreq == 0 && i != 0 && stressfreq > 0)
      printf("Cycle %d - Residual stress: %.3f, lambda %.3f\n", i, stress(s, d_coords, dim, nelem), lam);
    lam = lam - (maxlam - minlam) / (double)(ncycle - 1);
  }
  free(neighbours);
  return (stress(s, d_coords, dim, nelem));
}
```