#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 */
int /*<<< orphan*/ printf(char *, double);
double sqrt(double);
extern void kruskal_stress(double **distance_rn, double **distance_r2,
                           int instances) {
  double num = 0.0;
  double den = 0.0;
  int i, j;
  for (i = 0; i < instances; i++) {
    for (j = 1; j < instances; j++) {
      double dist_rn = distance_rn[i][j];
      double dist_r2 = distance_r2[i][j];
      num += (dist_rn - dist_r2) * (dist_rn - dist_r2);
      den += dist_rn * dist_rn;
    }
  }
  double result = sqrt(num / den);
  printf("Stress: %lf\n", result);
}


x86 assembly (clang, -O0):
<kruskal_stress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1200 <kruskal_stress+0xe0>
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ed <kruskal_stress+0xcd>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
subsd  -0x40(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    115d <kruskal_stress+0x3d>
jmp    11f2 <kruskal_stress+0xd2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114a <kruskal_stress+0x2a>
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kruskal_stress>:
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1222 <kruskal_stress+0x102>
mov    %edx,%r9d
lea    -0x1(%r9),%r8
mov    %r8,%r10
and    $0xfffffffffffffffe,%r10
neg    %r10
xorpd  %xmm1,%xmm1
xor    %r11d,%r11d
jmp    115d <kruskal_stress+0x3d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r11
cmp    %r9,%r11
je     1214 <kruskal_stress+0xf4>
cmp    $0x1,%edx
je     1150 <kruskal_stress+0x30>
mov    (%rdi,%r11,8),%rax
mov    (%rsi,%r11,8),%r14
mov    $0x1,%ebx
cmp    $0x2,%edx
jne    1180 <kruskal_stress+0x60>
jmp    11e2 <kruskal_stress+0xc2>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rax,%rbx,8),%xmm2
movapd %xmm2,%xmm3
subsd  (%r14,%rbx,8),%xmm3
movsd  0x8(%rax,%rbx,8),%xmm0
unpcklpd %xmm3,%xmm2
mulpd  %xmm2,%xmm2
addpd  %xmm1,%xmm2
movapd %xmm0,%xmm1
subsd  0x8(%r14,%rbx,8),%xmm1
unpcklpd %xmm1,%xmm0
mulpd  %xmm0,%xmm0
movapd %xmm0,%xmm1
addpd  %xmm2,%xmm1
lea    (%r10,%rbx,1),%rcx
add    $0x2,%rcx
add    $0x2,%rbx
cmp    $0x1,%rcx
jne    1190 <kruskal_stress+0x70>
addpd  %xmm2,%xmm0
movapd %xmm1,%xmm2
movapd %xmm0,%xmm1
test   $0x1,%r8b
je     1150 <kruskal_stress+0x30>
movsd  (%rax,%rbx,8),%xmm1
movapd %xmm1,%xmm0
subsd  (%r14,%rbx,8),%xmm0
unpcklpd %xmm0,%xmm1
mulpd  %xmm1,%xmm1
addpd  %xmm2,%xmm1
jmp    1150 <kruskal_stress+0x30>
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  %xmm1,%xmm0
jmp    122a <kruskal_stress+0x10a>
movsd  0xdd6(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     123a <kruskal_stress+0x11a>
sqrtsd %xmm0,%xmm0
jmp    123f <kruskal_stress+0x11f>
call   1040 <sqrt@plt>
lea    0xdc2(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Stress: %lf\0A\00"
define void @kruskal_stress(double** %0, double** %1, i32 %2) {
%4 = alloca double**
%5 = alloca double**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double** %0, double*** %4
store double** %1, double*** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %14
14: ; preds = %58, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %61
18: ; preds = %14
store i32 1, i32* %10
br label %19
19: ; preds = %54, %18
%20 = load i32, i32* %10
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %57
23: ; preds = %19
%24 = load double**, double*** %4
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
%28 = load double*, double** %27
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
store double %32, double* %11
%33 = load double**, double*** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double*, double** %33, i64 %35
%37 = load double*, double** %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
store double %41, double* %12
%42 = load double, double* %11
%43 = load double, double* %12
%44 = fsub double %42, %43
%45 = load double, double* %11
%46 = load double, double* %12
%47 = fsub double %45, %46
%48 = load double, double* %7
%49 = call double @llvm.fmuladd.f64(double %44, double %47, double %48)
store double %49, double* %7
%50 = load double, double* %11
%51 = load double, double* %11
%52 = load double, double* %8
%53 = call double @llvm.fmuladd.f64(double %50, double %51, double %52)
store double %53, double* %8
br label %54
54: ; preds = %23
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %19
57: ; preds = %19
br label %58
58: ; preds = %57
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %14
61: ; preds = %14
%62 = load double, double* %7
%63 = load double, double* %8
%64 = fdiv double %62, %63
%65 = call double @sqrt(double %64)
store double %65, double* %13
%66 = load double, double* %13
%67 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %66)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Stress: %lf\0A\00"
define void @kruskal_stress(double** nocapture %0, double** nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %68
5: ; preds = %3
%6 = icmp eq i32 %2, 1
%7 = zext i32 %2 to i64
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 1
%10 = icmp eq i32 %2, 2
%11 = and i64 %8, -2
%12 = icmp eq i64 %9, 0
br label %13
13: ; preds = %5, %60
%14 = phi i64 [ 0, %5 ], [ %62, %60 ]
%15 = phi <2 x double> [ zeroinitializer, %5 ], [ %61, %60 ]
br i1 %6, label %60, label %16
16: ; preds = %13
%17 = getelementptr inbounds double*, double** %0, i64 %14
%18 = load double*, double** %17
%19 = getelementptr inbounds double*, double** %1, i64 %14
%20 = load double*, double** %19
br i1 %10, label %47, label %21
21: ; preds = %16, %21
%22 = phi i64 [ %42, %21 ], [ 1, %16 ]
%23 = phi <2 x double> [ %41, %21 ], [ %15, %16 ]
%24 = phi i64 [ %43, %21 ], [ 0, %16 ]
%25 = getelementptr inbounds double, double* %18, i64 %22
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %20, i64 %22
%28 = load double, double* %27
%29 = fsub double %26, %28
%30 = insertelement <2 x double> poison, double %26, i64 0
%31 = insertelement <2 x double> %30, double %29, i64 1
%32 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %31, <2 x double> %23)
%33 = add nuw nsw i64 %22, 1
%34 = getelementptr inbounds double, double* %18, i64 %33
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %20, i64 %33
%37 = load double, double* %36
%38 = fsub double %35, %37
%39 = insertelement <2 x double> poison, double %35, i64 0
%40 = insertelement <2 x double> %39, double %38, i64 1
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %40, <2 x double> %40, <2 x double> %32)
%42 = add nuw nsw i64 %22, 2
%43 = add i64 %24, 2
%44 = icmp eq i64 %43, %11
br i1 %44, label %45, label %21
45: ; preds = %21
%46 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %40, <2 x double> %40, <2 x double> %32)
br label %47
47: ; preds = %45, %16
%48 = phi <2 x double> [ undef, %16 ], [ %46, %45 ]
%49 = phi i64 [ 1, %16 ], [ %42, %45 ]
%50 = phi <2 x double> [ %15, %16 ], [ %41, %45 ]
br i1 %12, label %60, label %51
51: ; preds = %47
%52 = getelementptr inbounds double, double* %18, i64 %49
%53 = load double, double* %52
%54 = getelementptr inbounds double, double* %20, i64 %49
%55 = load double, double* %54
%56 = fsub double %53, %55
%57 = insertelement <2 x double> poison, double %53, i64 0
%58 = insertelement <2 x double> %57, double %56, i64 1
%59 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %58, <2 x double> %58, <2 x double> %50)
br label %60
60: ; preds = %51, %47, %13
%61 = phi <2 x double> [ %15, %13 ], [ %48, %47 ], [ %59, %51 ]
%62 = add nuw nsw i64 %14, 1
%63 = icmp eq i64 %62, %7
br i1 %63, label %64, label %13
64: ; preds = %60
%65 = extractelement <2 x double> %61, i64 0
%66 = extractelement <2 x double> %61, i64 1
%67 = fdiv double %66, %65
br label %68
68: ; preds = %64, %3
%69 = phi double [ %67, %64 ], [ 0x7FF8000000000000, %3 ]
%70 = tail call double @sqrt(double %69)
%71 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %70)
ret void
}