#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 */
scalar_t__ pow(double, double);
double sqrt(double);
double RMSE2(double *X, double *M, int *omega, int kn) {
  int i;
  double error = 0.0;
  for (i = 0; i < kn; i++) {
    error += pow((X[omega[i]] - M[omega[i]]), 2.0);
  }
  return sqrt(error / kn);
}


x86 assembly (clang, -O0):
<RMSE2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a6 <RMSE2+0x86>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  0xe7c(%rip),%xmm1
call   1030 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1146 <RMSE2+0x26>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RMSE2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
test   %ecx,%ecx
jle    121f <RMSE2+0xff>
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %r14d,%r12d
cmp    $0x1,%r14d
mov    %r12,0x10(%rsp)
jne    1160 <RMSE2+0x40>
xorpd  %xmm2,%xmm2
xor    %ebp,%ebp
jmp    11db <RMSE2+0xbb>
and    $0xfffffffe,%r12d
xorpd  %xmm2,%xmm2
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
movslq 0x0(%r13,%rbp,4),%rax
movsd  (%rbx,%rax,8),%xmm0
subsd  (%r15,%rax,8),%xmm0
movsd  0xe72(%rip),%xmm1
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movslq 0x4(%r13,%rbp,4),%rax
movsd  (%rbx,%rax,8),%xmm0
subsd  (%r15,%rax,8),%xmm0
movsd  0xe41(%rip),%xmm1
call   1030 <pow@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
addsd  0x8(%rsp),%xmm2
add    $0x2,%rbp
cmp    %rbp,%r12
jne    1170 <RMSE2+0x50>
testb  $0x1,0x10(%rsp)
xorpd  %xmm1,%xmm1
je     121f <RMSE2+0xff>
movslq 0x0(%r13,%rbp,4),%rax
movsd  (%rbx,%rax,8),%xmm0
subsd  (%r15,%rax,8),%xmm0
movsd  0xe02(%rip),%xmm1
movsd  %xmm2,0x8(%rsp)
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm2
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
jb     1247 <RMSE2+0x127>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movapd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @RMSE2(double* %0, double* %1, i32* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %10
store i32 0, i32* %9
br label %11
11: ; preds = %39, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %42
15: ; preds = %11
%16 = load double*, double** %5
%17 = load i32*, i32** %7
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %16, i64 %22
%24 = load double, double* %23
%25 = load double*, double** %6
%26 = load i32*, i32** %7
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %25, i64 %31
%33 = load double, double* %32
%34 = fsub double %24, %33
%35 = call i64 @pow(double %34, double 2.000000e+00)
%36 = sitofp i64 %35 to double
%37 = load double, double* %10
%38 = fadd double %37, %36
store double %38, double* %10
br label %39
39: ; preds = %15
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %11
42: ; preds = %11
%43 = load double, double* %10
%44 = load i32, i32* %8
%45 = sitofp i32 %44 to double
%46 = fdiv double %43, %45
%47 = call double @sqrt(double %46)
ret double %47
}

LLVM IR (-O2):
define double @RMSE2(double* nocapture %0, double* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %59
6: ; preds = %4
%7 = zext i32 %3 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %3, 1
br i1 %9, label %42, label %10
10: ; preds = %6
%11 = and i64 %7, 4294967294
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ 0, %10 ], [ %39, %12 ]
%14 = phi double [ 0.000000e+00, %10 ], [ %38, %12 ]
%15 = phi i64 [ 0, %10 ], [ %40, %12 ]
%16 = getelementptr inbounds i32, i32* %2, i64 %13
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %1, i64 %18
%22 = load double, double* %21
%23 = fsub double %20, %22
%24 = tail call i64 @pow(double %23, double 2.000000e+00)
%25 = sitofp i64 %24 to double
%26 = fadd double %14, %25
%27 = or i64 %13, 1
%28 = getelementptr inbounds i32, i32* %2, i64 %27
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %0, i64 %30
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %1, i64 %30
%34 = load double, double* %33
%35 = fsub double %32, %34
%36 = tail call i64 @pow(double %35, double 2.000000e+00)
%37 = sitofp i64 %36 to double
%38 = fadd double %26, %37
%39 = add nuw nsw i64 %13, 2
%40 = add i64 %15, 2
%41 = icmp eq i64 %40, %11
br i1 %41, label %42, label %12
42: ; preds = %12, %6
%43 = phi double [ undef, %6 ], [ %38, %12 ]
%44 = phi i64 [ 0, %6 ], [ %39, %12 ]
%45 = phi double [ 0.000000e+00, %6 ], [ %38, %12 ]
%46 = icmp eq i64 %8, 0
br i1 %46, label %59, label %47
47: ; preds = %42
%48 = getelementptr inbounds i32, i32* %2, i64 %44
%49 = load i32, i32* %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %0, i64 %50
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %1, i64 %50
%54 = load double, double* %53
%55 = fsub double %52, %54
%56 = tail call i64 @pow(double %55, double 2.000000e+00)
%57 = sitofp i64 %56 to double
%58 = fadd double %45, %57
br label %59
59: ; preds = %47, %42, %4
%60 = phi double [ 0.000000e+00, %4 ], [ %43, %42 ], [ %58, %47 ]
%61 = sitofp i32 %3 to double
%62 = fdiv double %60, %61
%63 = tail call double @sqrt(double %62)
ret double %63
}