#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double ed(double *, int, int, int);
int /*<<< orphan*/ free(int *);
int getpid();
int *nearest_neighbours(double *, int, int);
int /*<<< orphan*/ printf(char *, int, double, double);
int rand();
int /*<<< orphan*/ srand(scalar_t__);
double stress(double *, double *, int, int);
scalar_t__ time(int /*<<< orphan*/ *);
size_t trmIndex(int, int);
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));
}


x86 assembly (clang, -O0):
<CkNNStochasticProximityEmbedding>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %rax,-0xb0(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0xa8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%ecx
mov    -0xa8(%rbp),%eax
imul   %ecx,%eax
cltq
add    %rax,%rdi
call   1090 <srand@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1080 <nearest_neighbours@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x94(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    12da <CkNNStochasticProximityEmbedding+0x13a>
mov    $0x0,%al
call   10c0 <rand@plt>
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1296 <CkNNStochasticProximityEmbedding+0xf6>
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1583 <CkNNStochasticProximityEmbedding+0x3e3>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    14e9 <CkNNStochasticProximityEmbedding+0x349>
mov    $0x0,%al
call   10c0 <rand@plt>
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x4c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
imul   -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    14d0 <CkNNStochasticProximityEmbedding+0x330>
mov    -0x48(%rbp),%rax
movslq -0xa0(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x50(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   10a0 <ed@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x50(%rbp),%esi
call   1070 <trmIndex@plt>
mov    %rax,%rcx
mov    -0xb8(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
ucomisd -0x78(%rbp),%xmm0
jbe    14b7 <CkNNStochasticProximityEmbedding+0x317>
mov    -0x4c(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movsd  0xc4f(%rip),%xmm0
mulsd  -0x80(%rbp),%xmm0
movsd  -0x78(%rbp),%xmm1
subsd  -0x70(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc2c(%rip),%xmm1
addsd  -0x70(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movl   $0x0,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    14b2 <CkNNStochasticProximityEmbedding+0x312>
mov    -0x58(%rbp),%eax
add    -0xa4(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%eax
add    -0xa4(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x60(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    13ef <CkNNStochasticProximityEmbedding+0x24f>
jmp    14b7 <CkNNStochasticProximityEmbedding+0x317>
jmp    14bc <CkNNStochasticProximityEmbedding+0x31c>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    1323 <CkNNStochasticProximityEmbedding+0x183>
jmp    14d5 <CkNNStochasticProximityEmbedding+0x335>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    12fd <CkNNStochasticProximityEmbedding+0x15d>
mov    -0x98(%rbp),%eax
cltd
idivl  0x18(%rbp)
cmp    $0x0,%edx
jne    1549 <CkNNStochasticProximityEmbedding+0x3a9>
cmpl   $0x0,-0x98(%rbp)
je     1549 <CkNNStochasticProximityEmbedding+0x3a9>
cmpl   $0x0,0x18(%rbp)
jle    1549 <CkNNStochasticProximityEmbedding+0x3a9>
mov    -0x98(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <stress@plt>
mov    -0xbc(%rbp),%esi
movsd  -0x80(%rbp),%xmm1
lea    0xacc(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x80(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    12e4 <CkNNStochasticProximityEmbedding+0x144>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <stress@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CkNNStochasticProximityEmbedding>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9,0x20(%rsp)
movsd  %xmm1,0x30(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %r8d,(%rsp)
mov    %ecx,%ebx
mov    %edx,%r13d
mov    %rsi,%r12
mov    %rdi,%rbp
mov    0xe8(%rsp),%eax
mov    %eax,0x38(%rsp)
mov    0xe0(%rsp),%eax
mov    %eax,0x1c(%rsp)
xor    %edi,%edi
call   10b0 <time@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
imul   %r15d,%eax
movslq %eax,%rdi
add    %r14,%rdi
call   1090 <srand@plt>
mov    %rbp,0x28(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,0x18(%rsp)
mov    %r13d,%edx
call   1080 <nearest_neighbours@plt>
mov    %rax,0x58(%rsp)
mov    (%rsp),%eax
mov    %ebx,0x4(%rsp)
imul   %ebx,%eax
test   %eax,%eax
jle    125d <CkNNStochasticProximityEmbedding+0xbd>
mov    %eax,%ebx
xor    %ebp,%ebp
nop
xor    %eax,%eax
call   10c0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r12,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1240 <CkNNStochasticProximityEmbedding+0xa0>
mov    %r12,0x8(%rsp)
cmpl   $0x0,0x20(%rsp)
jle    1624 <CkNNStochasticProximityEmbedding+0x484>
movsd  0x10(%rsp),%xmm1
subsd  0x30(%rsp),%xmm1
mov    0x20(%rsp),%rax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x60(%rsp)
movslq 0x18(%rsp),%rax
mov    %rax,0x68(%rsp)
mov    (%rsp),%r12d
mov    0x8(%rsp),%rax
lea    (%rax,%r12,8),%rcx
mov    %rcx,0x50(%rsp)
mov    %r12d,%ecx
and    $0xfffffffe,%ecx
mov    %rcx,0x90(%rsp)
add    $0xfffffffffffffffe,%rcx
mov    %rcx,0x88(%rsp)
mov    %rcx,%rdx
shr    %rdx
add    $0x1,%rdx
mov    %rdx,%rcx
mov    %rdx,0x80(%rsp)
and    $0xfffffffffffffffe,%rdx
mov    %rdx,0x70(%rsp)
add    $0x10,%rax
mov    %rax,0x48(%rsp)
xor    %ebx,%ebx
jmp    131f <CkNNStochasticProximityEmbedding+0x17f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x10(%rsp),%xmm0
subsd  0x60(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0x1,%ebx
cmp    0x20(%rsp),%ebx
je     1624 <CkNNStochasticProximityEmbedding+0x484>
mov    %ebx,0x3c(%rsp)
cmpl   $0x0,0x1c(%rsp)
jle    15d0 <CkNNStochasticProximityEmbedding+0x430>
movsd  0x10(%rsp),%xmm0
mulsd  0xcc4(%rip),%xmm0
movsd  %xmm0,0xa0(%rsp)
xor    %eax,%eax
jmp    1361 <CkNNStochasticProximityEmbedding+0x1c1>
nopl   0x0(%rax)
mov    0x40(%rsp),%eax
add    $0x1,%eax
cmp    0x1c(%rsp),%eax
je     15d0 <CkNNStochasticProximityEmbedding+0x430>
mov    %eax,0x40(%rsp)
xor    %eax,%eax
call   10c0 <rand@plt>
cltd
idivl  0x4(%rsp)
mov    %edx,%r14d
lea    0x1(%r14),%ecx
mov    0x18(%rsp),%eax
imul   %eax,%ecx
mov    %ecx,0x44(%rsp)
cmp    %eax,%ecx
mov    0x8(%rsp),%rcx
jle    1350 <CkNNStochasticProximityEmbedding+0x1b0>
mov    %r14d,%eax
imul   (%rsp),%eax
movslq %eax,%rdx
lea    (%rcx,%rdx,8),%rbx
mov    0x50(%rsp),%rax
lea    (%rax,%rdx,8),%rax
mov    %rax,0x98(%rsp)
mov    0x48(%rsp),%rax
mov    %rdx,0x78(%rsp)
lea    (%rax,%rdx,8),%rbp
mov    0x68(%rsp),%r15
jmp    13cb <CkNNStochasticProximityEmbedding+0x22b>
add    $0x1,%r15
cmp    %r15d,0x44(%rsp)
je     1350 <CkNNStochasticProximityEmbedding+0x1b0>
mov    0x58(%rsp),%rax
mov    (%rax,%r15,4),%r13d
mov    0x8(%rsp),%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    (%rsp),%ecx
call   10a0 <ed@plt>
movsd  %xmm0,0x30(%rsp)
mov    %r14d,%edi
mov    %r13d,%esi
call   1070 <trmIndex@plt>
movsd  0x30(%rsp),%xmm2
mov    0x8(%rsp),%rdi
mov    0x28(%rsp),%rcx
movsd  (%rcx,%rax,8),%xmm0
ucomisd %xmm0,%xmm2
jbe    13c0 <CkNNStochasticProximityEmbedding+0x220>
movapd %xmm2,%xmm1
addsd  0xbe9(%rip),%xmm1
cmpl   $0x0,(%rsp)
jle    13c0 <CkNNStochasticProximityEmbedding+0x220>
subsd  %xmm2,%xmm0
mulsd  0xa0(%rsp),%xmm0
divsd  %xmm1,%xmm0
mov    (%rsp),%ecx
imul   %ecx,%r13d
movslq %r13d,%rax
cmp    $0x1,%ecx
je     1461 <CkNNStochasticProximityEmbedding+0x2c1>
mov    0x50(%rsp),%rcx
lea    (%rcx,%rax,8),%rcx
cmp    %rcx,%rbx
jae    14b3 <CkNNStochasticProximityEmbedding+0x313>
lea    (%rdi,%rax,8),%rcx
cmp    0x98(%rsp),%rcx
jae    14b3 <CkNNStochasticProximityEmbedding+0x313>
xor    %ecx,%ecx
lea    (%rdi,%rax,8),%rax
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm1
movapd %xmm1,%xmm2
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rbx,%rcx,8)
movsd  (%rax,%rcx,8),%xmm1
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm3,(%rax,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%r12
jne    1470 <CkNNStochasticProximityEmbedding+0x2d0>
jmp    13c0 <CkNNStochasticProximityEmbedding+0x220>
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
cmpq   $0x0,0x88(%rsp)
je     15ba <CkNNStochasticProximityEmbedding+0x41a>
mov    0x48(%rsp),%rcx
lea    (%rcx,%rax,8),%rdx
mov    0x70(%rsp),%rsi
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movupd -0x10(%rbp,%rcx,8),%xmm2
movupd -0x10(%rdx,%rcx,8),%xmm3
movapd %xmm2,%xmm4
subpd  %xmm3,%xmm4
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
movupd %xmm4,-0x10(%rbp,%rcx,8)
movapd %xmm3,%xmm2
subpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm2
addpd  %xmm3,%xmm2
movupd %xmm2,-0x10(%rdx,%rcx,8)
movupd 0x0(%rbp,%rcx,8),%xmm2
movupd (%rdx,%rcx,8),%xmm3
movapd %xmm2,%xmm4
subpd  %xmm3,%xmm4
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
movupd %xmm4,0x0(%rbp,%rcx,8)
movapd %xmm3,%xmm2
subpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm2
addpd  %xmm3,%xmm2
movupd %xmm2,(%rdx,%rcx,8)
add    $0x4,%rcx
add    $0xfffffffffffffffe,%rsi
jne    14e0 <CkNNStochasticProximityEmbedding+0x340>
testb  $0x1,0x80(%rsp)
01
je     15a1 <CkNNStochasticProximityEmbedding+0x401>
mov    0x78(%rsp),%rdx
add    %rcx,%rdx
add    %rax,%rcx
movupd (%rdi,%rdx,8),%xmm2
movupd (%rdi,%rcx,8),%xmm3
movapd %xmm2,%xmm4
subpd  %xmm3,%xmm4
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
movupd %xmm4,(%rdi,%rdx,8)
movapd %xmm3,%xmm2
subpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm2
addpd  %xmm3,%xmm2
movupd %xmm2,(%rdi,%rcx,8)
mov    0x90(%rsp),%rdx
mov    %rdx,%rcx
cmp    %r12,%rdx
je     13c0 <CkNNStochasticProximityEmbedding+0x220>
jmp    1463 <CkNNStochasticProximityEmbedding+0x2c3>
xor    %ecx,%ecx
testb  $0x1,0x80(%rsp)
01
jne    1562 <CkNNStochasticProximityEmbedding+0x3c2>
jmp    15a1 <CkNNStochasticProximityEmbedding+0x401>
nopl   0x0(%rax,%rax,1)
mov    0x3c(%rsp),%ebx
mov    %ebx,%eax
cltd
mov    0x38(%rsp),%ecx
idiv   %ecx
test   %ecx,%ecx
jle    1300 <CkNNStochasticProximityEmbedding+0x160>
test   %ebx,%ebx
je     1300 <CkNNStochasticProximityEmbedding+0x160>
test   %edx,%edx
jne    1300 <CkNNStochasticProximityEmbedding+0x160>
mov    0x28(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
call   1060 <stress@plt>
lea    0x9fe(%rip),%rdi
mov    %ebx,%esi
movsd  0x10(%rsp),%xmm1
call   1050 <printf@plt>
jmp    1300 <CkNNStochasticProximityEmbedding+0x160>
mov    0x58(%rsp),%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <stress@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Cycle %d - Residual stress: %.3f, lambda %.3f\0A\00"
define double @CkNNStochasticProximityEmbedding(double* %0, double* %1, i32 %2, i32 %3, i32 %4, double %5, double %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca double
%32 = alloca double
%33 = alloca double
%34 = alloca double
%35 = alloca double
%36 = alloca i32
%37 = alloca i32
%38 = alloca i32
%39 = alloca i32
%40 = alloca i32
store double* %0, double** %11
store double* %1, double** %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store double %5, double* %16
store double %6, double* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i32 %9, i32* %20
store i32 0, i32* %23
store i32 0, i32* %24
store i32 0, i32* %25
store i32 0, i32* %26
store i32 0, i32* %27
store i32 0, i32* %28
store i32 0, i32* %29
store i32 0, i32* %30
store double 0.000000e+00, double* %31
store double 0.000000e+00, double* %32
%41 = load double, double* %16
store double %41, double* %33
store double 0.000000e+00, double* %34
store double 0.000000e+00, double* %35
%42 = call i64 @time(i32* null)
%43 = call i32 (...) @getpid()
%44 = call i32 (...) @getpid()
%45 = mul nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = add nsw i64 %42, %46
%48 = call i32 @srand(i64 %47)
%49 = load double*, double** %11
%50 = load i32, i32* %14
%51 = load i32, i32* %13
%52 = call i32* @nearest_neighbours(double* %49, i32 %50, i32 %51)
store i32* %52, i32** %22
store i32 0, i32* %36
br label %53
53: ; preds = %66, %10
%54 = load i32, i32* %36
%55 = load i32, i32* %14
%56 = load i32, i32* %15
%57 = mul nsw i32 %55, %56
%58 = icmp slt i32 %54, %57
br i1 %58, label %59, label %69
59: ; preds = %53
%60 = call i32 (...) @rand()
%61 = sitofp i32 %60 to double
%62 = load double*, double** %12
%63 = load i32, i32* %36
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
store double %61, double* %65
br label %66
66: ; preds = %59
%67 = load i32, i32* %36
%68 = add nsw i32 %67, 1
store i32 %68, i32* %36
br label %53
69: ; preds = %53
store i32 0, i32* %37
br label %70
70: ; preds = %224, %69
%71 = load i32, i32* %37
%72 = load i32, i32* %18
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %227
74: ; preds = %70
store i32 0, i32* %38
br label %75
75: ; preds = %191, %74
%76 = load i32, i32* %38
%77 = load i32, i32* %19
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %194
79: ; preds = %75
%80 = call i32 (...) @rand()
%81 = load i32, i32* %14
%82 = srem i32 %80, %81
store i32 %82, i32* %23
%83 = load i32, i32* %13
store i32 %83, i32* %39
br label %84
84: ; preds = %187, %79
%85 = load i32, i32* %39
%86 = load i32, i32* %23
%87 = add nsw i32 %86, 1
%88 = load i32, i32* %13
%89 = mul nsw i32 %87, %88
%90 = icmp slt i32 %85, %89
br i1 %90, label %91, label %190
91: ; preds = %84
%92 = load i32*, i32** %22
%93 = load i32, i32* %39
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
%96 = load i32, i32* %95
store i32 %96, i32* %24
%97 = load double*, double** %12
%98 = load i32, i32* %23
%99 = load i32, i32* %24
%100 = load i32, i32* %15
%101 = call double @ed(double* %97, i32 %98, i32 %99, i32 %100)
store double %101, double* %31
%102 = load double*, double** %11
%103 = load i32, i32* %23
%104 = load i32, i32* %24
%105 = call i64 @trmIndex(i32 %103, i32 %104)
%106 = getelementptr inbounds double, double* %102, i64 %105
%107 = load double, double* %106
store double %107, double* %32
%108 = load double, double* %31
%109 = load double, double* %32
%110 = fcmp ogt double %108, %109
br i1 %110, label %111, label %186
111: ; preds = %91
%112 = load i32, i32* %23
%113 = load i32, i32* %15
%114 = mul nsw i32 %112, %113
store i32 %114, i32* %26
%115 = load i32, i32* %24
%116 = load i32, i32* %15
%117 = mul nsw i32 %115, %116
store i32 %117, i32* %27
%118 = load double, double* %33
%119 = fmul double %118, 5.000000e-01
%120 = load double, double* %32
%121 = load double, double* %31
%122 = fsub double %120, %121
%123 = fmul double %119, %122
%124 = load double, double* %31
%125 = fadd double %124, 1.000000e-08
%126 = fdiv double %123, %125
store double %126, double* %34
store i32 0, i32* %40
br label %127
127: ; preds = %182, %111
%128 = load i32, i32* %40
%129 = load i32, i32* %15
%130 = icmp slt i32 %128, %129
br i1 %130, label %131, label %185
131: ; preds = %127
%132 = load i32, i32* %26
%133 = load i32, i32* %40
%134 = add nsw i32 %132, %133
store i32 %134, i32* %28
%135 = load i32, i32* %27
%136 = load i32, i32* %40
%137 = add nsw i32 %135, %136
store i32 %137, i32* %29
%138 = load double*, double** %12
%139 = load i32, i32* %28
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds double, double* %138, i64 %140
%142 = load double, double* %141
%143 = load double, double* %34
%144 = load double*, double** %12
%145 = load i32, i32* %28
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds double, double* %144, i64 %146
%148 = load double, double* %147
%149 = load double*, double** %12
%150 = load i32, i32* %29
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds double, double* %149, i64 %151
%153 = load double, double* %152
%154 = fsub double %148, %153
%155 = call double @llvm.fmuladd.f64(double %143, double %154, double %142)
%156 = load double*, double** %12
%157 = load i32, i32* %28
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds double, double* %156, i64 %158
store double %155, double* %159
%160 = load double*, double** %12
%161 = load i32, i32* %29
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds double, double* %160, i64 %162
%164 = load double, double* %163
%165 = load double, double* %34
%166 = load double*, double** %12
%167 = load i32, i32* %29
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds double, double* %166, i64 %168
%170 = load double, double* %169
%171 = load double*, double** %12
%172 = load i32, i32* %28
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds double, double* %171, i64 %173
%175 = load double, double* %174
%176 = fsub double %170, %175
%177 = call double @llvm.fmuladd.f64(double %165, double %176, double %164)
%178 = load double*, double** %12
%179 = load i32, i32* %29
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds double, double* %178, i64 %180
store double %177, double* %181
br label %182
182: ; preds = %131
%183 = load i32, i32* %40
%184 = add nsw i32 %183, 1
store i32 %184, i32* %40
br label %127
185: ; preds = %127
br label %186
186: ; preds = %185, %91
br label %187
187: ; preds = %186
%188 = load i32, i32* %39
%189 = add nsw i32 %188, 1
store i32 %189, i32* %39
br label %84
190: ; preds = %84
br label %191
191: ; preds = %190
%192 = load i32, i32* %38
%193 = add nsw i32 %192, 1
store i32 %193, i32* %38
br label %75
194: ; preds = %75
%195 = load i32, i32* %37
%196 = load i32, i32* %20
%197 = srem i32 %195, %196
%198 = icmp eq i32 %197, 0
br i1 %198, label %199, label %214
199: ; preds = %194
%200 = load i32, i32* %37
%201 = icmp ne i32 %200, 0
br i1 %201, label %202, label %214
202: ; preds = %199
%203 = load i32, i32* %20
%204 = icmp sgt i32 %203, 0
br i1 %204, label %205, label %214
205: ; preds = %202
%206 = load i32, i32* %37
%207 = load double*, double** %11
%208 = load double*, double** %12
%209 = load i32, i32* %15
%210 = load i32, i32* %14
%211 = call double @stress(double* %207, double* %208, i32 %209, i32 %210)
%212 = load double, double* %33
%213 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %206, double %211, double %212)
br label %214
214: ; preds = %205, %202, %199, %194
%215 = load double, double* %33
%216 = load double, double* %16
%217 = load double, double* %17
%218 = fsub double %216, %217
%219 = load i32, i32* %18
%220 = sub nsw i32 %219, 1
%221 = sitofp i32 %220 to double
%222 = fdiv double %218, %221
%223 = fsub double %215, %222
store double %223, double* %33
br label %224
224: ; preds = %214
%225 = load i32, i32* %37
%226 = add nsw i32 %225, 1
store i32 %226, i32* %37
br label %70
227: ; preds = %70
%228 = load i32*, i32** %22
%229 = call i32 @free(i32* %228)
%230 = load double*, double** %11
%231 = load double*, double** %12
%232 = load i32, i32* %15
%233 = load i32, i32* %14
%234 = call double @stress(double* %230, double* %231, i32 %232, i32 %233)
ret double %234
}

LLVM IR (-O2):
@.str = [47 x i8] c"Cycle %d - Residual stress: %.3f, lambda %.3f\0A\00"
define double @CkNNStochasticProximityEmbedding(double* %0, double* %1, i32 %2, i32 %3, i32 %4, double %5, double %6, i32 %7, i32 %8, i32 %9) {
%11 = tail call i64 @time(i32* null)
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (...) @getpid()
%14 = mul nsw i32 %13, %12
%15 = sext i32 %14 to i64
%16 = add nsw i64 %11, %15
%17 = tail call i32 @srand(i64 %16)
%18 = tail call i32* @nearest_neighbours(double* %0, i32 %3, i32 %2)
%19 = mul i32 %4, %3
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = zext i32 %19 to i64
br label %48
23: ; preds = %48, %10
%24 = icmp sgt i32 %7, 0
br i1 %24, label %25, label %60
25: ; preds = %23
%26 = icmp sgt i32 %8, 0
%27 = icmp sgt i32 %4, 0
%28 = icmp sgt i32 %9, 0
%29 = fsub double %5, %6
%30 = add nsw i32 %7, -1
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = sext i32 %2 to i64
%34 = zext i32 %4 to i64
%35 = getelementptr double, double* %1, i64 %34
%36 = getelementptr double, double* %1, i64 %34
%37 = and i64 %34, 4294967294
%38 = add nsw i64 %37, -2
%39 = lshr exact i64 %38, 1
%40 = add nuw i64 %39, 1
%41 = icmp eq i32 %4, 1
%42 = and i64 %34, 4294967294
%43 = and i64 %40, 1
%44 = icmp eq i64 %38, 0
%45 = and i64 %40, -2
%46 = icmp eq i64 %43, 0
%47 = icmp eq i64 %42, %34
br label %55
48: ; preds = %21, %48
%49 = phi i64 [ 0, %21 ], [ %53, %48 ]
%50 = tail call i32 (...) @rand()
%51 = sitofp i32 %50 to double
%52 = getelementptr inbounds double, double* %1, i64 %49
store double %51, double* %52
%53 = add nuw nsw i64 %49, 1
%54 = icmp eq i64 %53, %22
br i1 %54, label %23, label %48
55: ; preds = %25, %187
%56 = phi i32 [ 0, %25 ], [ %189, %187 ]
%57 = phi double [ %5, %25 ], [ %188, %187 ]
br i1 %26, label %58, label %63
58: ; preds = %55
%59 = fmul double %57, 5.000000e-01
br label %69
60: ; preds = %187, %23
%61 = tail call i32 @free(i32* %18)
%62 = tail call double @stress(double* %0, double* %1, i32 %4, i32 %3)
ret double %62
63: ; preds = %81, %55
%64 = srem i32 %56, %9
%65 = icmp eq i32 %64, 0
%66 = icmp ne i32 %56, 0
%67 = and i1 %66, %65
%68 = and i1 %28, %67
br i1 %68, label %184, label %187
69: ; preds = %58, %81
%70 = phi i32 [ 0, %58 ], [ %82, %81 ]
%71 = tail call i32 (...) @rand()
%72 = srem i32 %71, %3
%73 = add nsw i32 %72, 1
%74 = mul i32 %73, %2
%75 = icmp sgt i32 %74, %2
br i1 %75, label %76, label %81
76: ; preds = %69
%77 = mul nsw i32 %72, %4
%78 = sext i32 %77 to i64
%79 = getelementptr double, double* %1, i64 %78
%80 = getelementptr double, double* %35, i64 %78
br label %84
81: ; preds = %180, %69
%82 = add nuw nsw i32 %70, 1
%83 = icmp eq i32 %82, %8
br i1 %83, label %63, label %69
84: ; preds = %76, %180
%85 = phi i64 [ %33, %76 ], [ %181, %180 ]
%86 = getelementptr inbounds i32, i32* %18, i64 %85
%87 = load i32, i32* %86
%88 = tail call double @ed(double* %1, i32 %72, i32 %87, i32 %4)
%89 = tail call i64 @trmIndex(i32 %72, i32 %87)
%90 = getelementptr inbounds double, double* %0, i64 %89
%91 = load double, double* %90
%92 = fcmp ogt double %88, %91
br i1 %92, label %93, label %180
93: ; preds = %84
%94 = fsub double %91, %88
%95 = fmul double %59, %94
%96 = fadd double %88, 1.000000e-08
%97 = fdiv double %95, %96
br i1 %27, label %98, label %180
98: ; preds = %93
%99 = mul nsw i32 %87, %4
%100 = sext i32 %99 to i64
br i1 %41, label %163, label %101
101: ; preds = %98
%102 = getelementptr double, double* %1, i64 %100
%103 = getelementptr double, double* %36, i64 %100
%104 = icmp ult double* %79, %103
%105 = icmp ult double* %102, %80
%106 = and i1 %104, %105
br i1 %106, label %163, label %107
107: ; preds = %101
%108 = insertelement <2 x double> poison, double %97, i64 0
%109 = shufflevector <2 x double> %108, <2 x double> poison, <2 x i32> zeroinitializer
br i1 %44, label %145, label %110
110: ; preds = %107, %110
%111 = phi i64 [ %142, %110 ], [ 0, %107 ]
%112 = phi i64 [ %143, %110 ], [ 0, %107 ]
%113 = add nsw i64 %111, %78
%114 = add nsw i64 %111, %100
%115 = getelementptr inbounds double, double* %1, i64 %113
%116 = bitcast double* %115 to <2 x double>*
%117 = load <2 x double>, <2 x double>* %116
%118 = getelementptr inbounds double, double* %1, i64 %114
%119 = bitcast double* %118 to <2 x double>*
%120 = load <2 x double>, <2 x double>* %119
%121 = fsub <2 x double> %117, %120
%122 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %109, <2 x double> %121, <2 x double> %117)
%123 = bitcast double* %115 to <2 x double>*
store <2 x double> %122, <2 x double>* %123
%124 = fsub <2 x double> %120, %122
%125 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %109, <2 x double> %124, <2 x double> %120)
%126 = bitcast double* %118 to <2 x double>*
store <2 x double> %125, <2 x double>* %126
%127 = or i64 %111, 2
%128 = add nsw i64 %127, %78
%129 = add nsw i64 %127, %100
%130 = getelementptr inbounds double, double* %1, i64 %128
%131 = bitcast double* %130 to <2 x double>*
%132 = load <2 x double>, <2 x double>* %131
%133 = getelementptr inbounds double, double* %1, i64 %129
%134 = bitcast double* %133 to <2 x double>*
%135 = load <2 x double>, <2 x double>* %134
%136 = fsub <2 x double> %132, %135
%137 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %109, <2 x double> %136, <2 x double> %132)
%138 = bitcast double* %130 to <2 x double>*
store <2 x double> %137, <2 x double>* %138
%139 = fsub <2 x double> %135, %137
%140 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %109, <2 x double> %139, <2 x double> %135)
%141 = bitcast double* %133 to <2 x double>*
store <2 x double> %140, <2 x double>* %141
%142 = add nuw i64 %111, 4
%143 = add nuw i64 %112, 2
%144 = icmp eq i64 %143, %45
br i1 %144, label %145, label %110
145: ; preds = %110, %107
%146 = phi i64 [ 0, %107 ], [ %142, %110 ]
br i1 %46, label %162, label %147
147: ; preds = %145
%148 = add nsw i64 %146, %78
%149 = add nsw i64 %146, %100
%150 = getelementptr inbounds double, double* %1, i64 %148
%151 = bitcast double* %150 to <2 x double>*
%152 = load <2 x double>, <2 x double>* %151
%153 = getelementptr inbounds double, double* %1, i64 %149
%154 = bitcast double* %153 to <2 x double>*
%155 = load <2 x double>, <2 x double>* %154
%156 = fsub <2 x double> %152, %155
%157 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %109, <2 x double> %156, <2 x double> %152)
%158 = bitcast double* %150 to <2 x double>*
store <2 x double> %157, <2 x double>* %158
%159 = fsub <2 x double> %155, %157
%160 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %109, <2 x double> %159, <2 x double> %155)
%161 = bitcast double* %153 to <2 x double>*
store <2 x double> %160, <2 x double>* %161
br label %162
162: ; preds = %145, %147
br i1 %47, label %180, label %163
163: ; preds = %101, %98, %162
%164 = phi i64 [ 0, %101 ], [ 0, %98 ], [ %42, %162 ]
br label %165
165: ; preds = %163, %165
%166 = phi i64 [ %178, %165 ], [ %164, %163 ]
%167 = add nsw i64 %166, %78
%168 = add nsw i64 %166, %100
%169 = getelementptr inbounds double, double* %1, i64 %167
%170 = load double, double* %169
%171 = getelementptr inbounds double, double* %1, i64 %168
%172 = load double, double* %171
%173 = fsub double %170, %172
%174 = tail call double @llvm.fmuladd.f64(double %97, double %173, double %170)
store double %174, double* %169
%175 = load double, double* %171
%176 = fsub double %175, %174
%177 = tail call double @llvm.fmuladd.f64(double %97, double %176, double %175)
store double %177, double* %171
%178 = add nuw nsw i64 %166, 1
%179 = icmp eq i64 %178, %34
br i1 %179, label %180, label %165
180: ; preds = %165, %162, %93, %84
%181 = add nsw i64 %85, 1
%182 = trunc i64 %181 to i32
%183 = icmp eq i32 %74, %182
br i1 %183, label %81, label %84
184: ; preds = %63
%185 = tail call double @stress(double* %0, double* %1, i32 %4, i32 %3)
%186 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %56, double %185, double %57)
br label %187
187: ; preds = %184, %63
%188 = fsub double %57, %32
%189 = add nuw nsw i32 %56, 1
%190 = icmp eq i32 %189, %7
br i1 %190, label %60, label %55
}