#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);
double calc_rmsd_c(double *v1, double *v2, int n) {
  double sum = 0;
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < 3; j++)
      sum += (v1[j] - v2[j]) * (v1[j] - v2[j]);
  sum /= n;
  return sqrt(sum);
}


x86 assembly (clang, -O0):
<calc_rmsd_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b6 <calc_rmsd_c+0xa6>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    11a3 <calc_rmsd_c+0x93>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1145 <calc_rmsd_c+0x35>
jmp    11a8 <calc_rmsd_c+0x98>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <calc_rmsd_c+0x22>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_rmsd_c>:
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %edx,%edx
jle    11ae <calc_rmsd_c+0x9e>
movsd  (%rdi),%xmm3
movsd  0x8(%rdi),%xmm2
subsd  (%rsi),%xmm3
subsd  0x8(%rsi),%xmm2
movsd  0x10(%rdi),%xmm4
subsd  0x10(%rsi),%xmm4
cmp    $0x1,%edx
jne    1147 <calc_rmsd_c+0x37>
xorpd  %xmm0,%xmm0
jmp    118d <calc_rmsd_c+0x7d>
mov    %edx,%eax
and    $0xfffffffe,%eax
xorpd  %xmm0,%xmm0
movapd %xmm3,%xmm5
mulsd  %xmm3,%xmm5
movapd %xmm2,%xmm6
mulsd  %xmm2,%xmm6
movapd %xmm4,%xmm7
mulsd  %xmm4,%xmm7
nopl   0x0(%rax,%rax,1)
addsd  %xmm5,%xmm0
addsd  %xmm6,%xmm0
addsd  %xmm7,%xmm0
addsd  %xmm5,%xmm0
addsd  %xmm6,%xmm0
addsd  %xmm7,%xmm0
add    $0xfffffffe,%eax
jne    1170 <calc_rmsd_c+0x60>
test   $0x1,%dl
je     11ae <calc_rmsd_c+0x9e>
mulsd  %xmm3,%xmm3
addsd  %xmm0,%xmm3
mulsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm4,%xmm4
addsd  %xmm2,%xmm4
movapd %xmm4,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     11c4 <calc_rmsd_c+0xb4>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @calc_rmsd_c(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %10
10: ; preds = %47, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %50
14: ; preds = %10
store i32 0, i32* %9
br label %15
15: ; preds = %43, %14
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %46
18: ; preds = %15
%19 = load double*, double** %4
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double*, double** %5
%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 = fsub double %23, %28
%30 = load double*, double** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %5
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fsub double %34, %39
%41 = load double, double* %7
%42 = call double @llvm.fmuladd.f64(double %29, double %40, double %41)
store double %42, double* %7
br label %43
43: ; preds = %18
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %15
46: ; preds = %15
br label %47
47: ; preds = %46
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %10
50: ; preds = %10
%51 = load i32, i32* %6
%52 = sitofp i32 %51 to double
%53 = load double, double* %7
%54 = fdiv double %53, %52
store double %54, double* %7
%55 = load double, double* %7
%56 = call double @sqrt(double %55)
ret double %56
}

LLVM IR (-O2):
define double @calc_rmsd_c(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %42
5: ; preds = %3
%6 = load double, double* %0
%7 = load double, double* %1
%8 = getelementptr inbounds double, double* %0, i64 1
%9 = load double, double* %8
%10 = getelementptr inbounds double, double* %1, i64 1
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %0, i64 2
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 2
%15 = load double, double* %14
%16 = fsub double %6, %7
%17 = fsub double %9, %11
%18 = fsub double %13, %15
%19 = and i32 %2, 1
%20 = icmp eq i32 %2, 1
br i1 %20, label %34, label %21
21: ; preds = %5
%22 = and i32 %2, -2
br label %23
23: ; preds = %23, %21
%24 = phi double [ 0.000000e+00, %21 ], [ %31, %23 ]
%25 = phi i32 [ 0, %21 ], [ %32, %23 ]
%26 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %24)
%27 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %26)
%28 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %27)
%29 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %28)
%30 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %29)
%31 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %30)
%32 = add i32 %25, 2
%33 = icmp eq i32 %32, %22
br i1 %33, label %34, label %23
34: ; preds = %23, %5
%35 = phi double [ undef, %5 ], [ %31, %23 ]
%36 = phi double [ 0.000000e+00, %5 ], [ %31, %23 ]
%37 = icmp eq i32 %19, 0
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %36)
%40 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %39)
%41 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %40)
br label %42
42: ; preds = %38, %34, %3
%43 = phi double [ 0.000000e+00, %3 ], [ %35, %34 ], [ %41, %38 ]
%44 = sitofp i32 %2 to double
%45 = fdiv double %43, %44
%46 = tail call double @sqrt(double %45)
ret double %46
}