#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 sqrt(double);
void molecules_distance_matrix(int n, double *cor, double *dm) {
  int i, j;
  double d, tmp;
  for (i = 0; i < n; i++) {
    for (j = 0; j < i; j++) {
      tmp = cor[3 * i] - cor[3 * j];
      d = tmp * tmp;
      tmp = cor[3 * i + 1] - cor[3 * j + 1];
      d += tmp * tmp;
      tmp = cor[3 * i + 2] - cor[3 * j + 2];
      d += tmp * tmp;
      d = sqrt(d);
      dm[i * n + j] = d;
      dm[j * n + i] = d;
    }
  }
}


x86 assembly (clang, -O0):
<molecules_distance_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1271 <molecules_distance_matrix+0x161>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    125e <molecules_distance_matrix+0x14e>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x20(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <molecules_distance_matrix+0x2d>
jmp    1263 <molecules_distance_matrix+0x153>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <molecules_distance_matrix+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<molecules_distance_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %edi,%edi
jle    1224 <molecules_distance_matrix+0x114>
mov    %rdx,%rbp
mov    %edi,%eax
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,8),%r15
lea    0x10(%rsi),%rcx
mov    %rcx,0x8(%rsp)
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
mov    %rdx,(%rsp)
jmp    1167 <molecules_distance_matrix+0x57>
nopl   (%rax)
add    $0x1,%rbx
addq   $0x8,(%rsp)
add    %r15,%rbp
cmp    0x10(%rsp),%rbx
je     1224 <molecules_distance_matrix+0x114>
test   %rbx,%rbx
je     1150 <molecules_distance_matrix+0x40>
lea    (%rbx,%rbx,2),%rdi
mov    %edi,%eax
lea    0x1(%rdi),%ecx
add    $0x2,%edi
mov    0x8(%rsp),%r14
mov    (%rsp),%r13
xor    %r12d,%r12d
mov    %rbx,0x30(%rsp)
mov    %rdi,0x28(%rsp)
mov    %rax,0x20(%rsp)
mov    %rcx,0x18(%rsp)
jmp    11e4 <molecules_distance_matrix+0xd4>
nopw   0x0(%rax,%rax,1)
mov    %rsi,%rbx
call   1030 <sqrt@plt>
mov    0x18(%rsp),%rcx
mov    0x20(%rsp),%rax
mov    0x28(%rsp),%rdi
xorpd  %xmm2,%xmm2
mov    %rbx,%rsi
mov    0x30(%rsp),%rbx
movsd  %xmm0,0x0(%rbp,%r12,8)
movsd  %xmm0,0x0(%r13)
add    $0x1,%r12
add    %r15,%r13
add    $0x18,%r14
cmp    %r12,%rbx
je     1150 <molecules_distance_matrix+0x40>
movsd  (%rsi,%rax,8),%xmm0
subsd  -0x10(%r14),%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsi,%rcx,8),%xmm1
subsd  -0x8(%r14),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  (%rsi,%rdi,8),%xmm0
subsd  (%r14),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     11a0 <molecules_distance_matrix+0x90>
sqrtsd %xmm0,%xmm0
jmp    11c3 <molecules_distance_matrix+0xb3>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @molecules_distance_matrix(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store i32 0, i32* %7
br label %11
11: ; preds = %99, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %102
15: ; preds = %11
store i32 0, i32* %8
br label %16
16: ; preds = %95, %15
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %98
20: ; preds = %16
%21 = load double*, double** %5
%22 = load i32, i32* %7
%23 = mul nsw i32 3, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %21, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %5
%28 = load i32, i32* %8
%29 = mul nsw i32 3, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %27, i64 %30
%32 = load double, double* %31
%33 = fsub double %26, %32
store double %33, double* %10
%34 = load double, double* %10
%35 = load double, double* %10
%36 = fmul double %34, %35
store double %36, double* %9
%37 = load double*, double** %5
%38 = load i32, i32* %7
%39 = mul nsw i32 3, %38
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %37, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %5
%45 = load i32, i32* %8
%46 = mul nsw i32 3, %45
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %44, i64 %48
%50 = load double, double* %49
%51 = fsub double %43, %50
store double %51, double* %10
%52 = load double, double* %10
%53 = load double, double* %10
%54 = load double, double* %9
%55 = call double @llvm.fmuladd.f64(double %52, double %53, double %54)
store double %55, double* %9
%56 = load double*, double** %5
%57 = load i32, i32* %7
%58 = mul nsw i32 3, %57
%59 = add nsw i32 %58, 2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %56, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %5
%64 = load i32, i32* %8
%65 = mul nsw i32 3, %64
%66 = add nsw i32 %65, 2
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %63, i64 %67
%69 = load double, double* %68
%70 = fsub double %62, %69
store double %70, double* %10
%71 = load double, double* %10
%72 = load double, double* %10
%73 = load double, double* %9
%74 = call double @llvm.fmuladd.f64(double %71, double %72, double %73)
store double %74, double* %9
%75 = load double, double* %9
%76 = call double @sqrt(double %75)
store double %76, double* %9
%77 = load double, double* %9
%78 = load double*, double** %6
%79 = load i32, i32* %7
%80 = load i32, i32* %4
%81 = mul nsw i32 %79, %80
%82 = load i32, i32* %8
%83 = add nsw i32 %81, %82
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %78, i64 %84
store double %77, double* %85
%86 = load double, double* %9
%87 = load double*, double** %6
%88 = load i32, i32* %8
%89 = load i32, i32* %4
%90 = mul nsw i32 %88, %89
%91 = load i32, i32* %7
%92 = add nsw i32 %90, %91
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %87, i64 %93
store double %86, double* %94
br label %95
95: ; preds = %20
%96 = load i32, i32* %8
%97 = add nsw i32 %96, 1
store i32 %97, i32* %8
br label %16
98: ; preds = %16
br label %99
99: ; preds = %98
%100 = load i32, i32* %7
%101 = add nsw i32 %100, 1
store i32 %101, i32* %7
br label %11
102: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @molecules_distance_matrix(i32 %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %53
5: ; preds = %3
%6 = zext i32 %0 to i64
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %50
%9 = phi i64 [ 0, %5 ], [ %51, %50 ]
%10 = icmp eq i64 %9, 0
br i1 %10, label %50, label %11
11: ; preds = %8
%12 = mul nuw nsw i64 %9, 3
%13 = and i64 %12, 4294967295
%14 = getelementptr inbounds double, double* %1, i64 %13
%15 = add nuw i64 %12, 1
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = add nuw i64 %12, 2
%19 = and i64 %18, 4294967295
%20 = getelementptr inbounds double, double* %1, i64 %19
%21 = mul nsw i64 %9, %6
br label %22
22: ; preds = %11, %22
%23 = phi i64 [ 0, %11 ], [ %48, %22 ]
%24 = load double, double* %14
%25 = mul nuw nsw i64 %23, 3
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = load double, double* %26
%28 = fsub double %24, %27
%29 = fmul double %28, %28
%30 = load double, double* %17
%31 = add nuw nsw i64 %25, 1
%32 = getelementptr inbounds double, double* %1, i64 %31
%33 = load double, double* %32
%34 = fsub double %30, %33
%35 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %29)
%36 = load double, double* %20
%37 = add nuw nsw i64 %25, 2
%38 = getelementptr inbounds double, double* %1, i64 %37
%39 = load double, double* %38
%40 = fsub double %36, %39
%41 = tail call double @llvm.fmuladd.f64(double %40, double %40, double %35)
%42 = tail call double @sqrt(double %41)
%43 = add nuw nsw i64 %23, %21
%44 = getelementptr inbounds double, double* %2, i64 %43
store double %42, double* %44
%45 = mul nsw i64 %23, %6
%46 = add nuw nsw i64 %45, %9
%47 = getelementptr inbounds double, double* %2, i64 %46
store double %42, double* %47
%48 = add nuw nsw i64 %23, 1
%49 = icmp eq i64 %48, %9
br i1 %49, label %50, label %22
50: ; preds = %22, %8
%51 = add nuw nsw i64 %9, 1
%52 = icmp eq i64 %51, %7
br i1 %52, label %53, label %8
53: ; preds = %50, %3
ret void
}