#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 */
size_t map(int, int, int, char);
scalar_t__ pow(double, double);
double sqrt(double);
double RMSE(double *X, double *M, int ncols, int nrows) {
  int i, j;
  double error = 0.0;
  for (i = 0; i < nrows; i++) {
    for (j = 0; j < ncols; j++) {
      error += pow((X[map(i, j, ncols, 'n')] - M[map(i, j, ncols, 'n')]), 2.0);
    }
  }
  return sqrt(error / (nrows * ncols));
}


x86 assembly (clang, -O0):
<RMSE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1209 <RMSE+0xd9>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f6 <RMSE+0xc6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    $0x6e,%ecx
call   1030 <map@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    $0x6e,%ecx
call   1030 <map@plt>
movsd  -0x38(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
subsd  (%rax,%rcx,8),%xmm0
movsd  0xe2c(%rip),%xmm1
call   1040 <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    1168 <RMSE+0x38>
jmp    11fb <RMSE+0xcb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <RMSE+0x25>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RMSE>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
xorpd  %xmm0,%xmm0
test   %ecx,%ecx
jle    11d8 <RMSE+0xa8>
mov    %rsi,%r15
mov    %rdi,%r12
xor    %r13d,%r13d
xorpd  %xmm0,%xmm0
jmp    1169 <RMSE+0x39>
xchg   %ax,%ax
add    $0x1,%r13d
cmp    %r14d,%r13d
je     11d8 <RMSE+0xa8>
test   %ebp,%ebp
jle    1160 <RMSE+0x30>
xor    %ebx,%ebx
nop
movsd  %xmm0,0x10(%rsp)
mov    %r13d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    $0x6e,%ecx
call   1030 <map@plt>
movsd  (%r12,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    $0x6e,%ecx
call   1030 <map@plt>
movsd  0x8(%rsp),%xmm0
subsd  (%r15,%rax,8),%xmm0
movsd  0xe48(%rip),%xmm1
call   1040 <pow@plt>
movsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1170 <RMSE+0x40>
jmp    1160 <RMSE+0x30>
imul   %ebp,%r14d
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
ucomisd 0xe18(%rip),%xmm0
jb     1205 <RMSE+0xd5>
sqrtsd %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sqrt@plt>

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

LLVM IR (-O2):
define double @RMSE(double* nocapture %0, double* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %30
6: ; preds = %4
%7 = icmp sgt i32 %2, 0
br label %8
8: ; preds = %6, %26
%9 = phi double [ 0.000000e+00, %6 ], [ %27, %26 ]
%10 = phi i32 [ 0, %6 ], [ %28, %26 ]
br i1 %7, label %11, label %26
11: ; preds = %8, %11
%12 = phi double [ %23, %11 ], [ %9, %8 ]
%13 = phi i32 [ %24, %11 ], [ 0, %8 ]
%14 = tail call i64 @map(i32 %10, i32 %13, i32 %2, i8 signext 110)
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = tail call i64 @map(i32 %10, i32 %13, i32 %2, i8 signext 110)
%18 = getelementptr inbounds double, double* %1, i64 %17
%19 = load double, double* %18
%20 = fsub double %16, %19
%21 = tail call i64 @pow(double %20, double 2.000000e+00)
%22 = sitofp i64 %21 to double
%23 = fadd double %12, %22
%24 = add nuw nsw i32 %13, 1
%25 = icmp eq i32 %24, %2
br i1 %25, label %26, label %11
26: ; preds = %11, %8
%27 = phi double [ %9, %8 ], [ %23, %11 ]
%28 = add nuw nsw i32 %10, 1
%29 = icmp eq i32 %28, %3
br i1 %29, label %30, label %8
30: ; preds = %26, %4
%31 = phi double [ 0.000000e+00, %4 ], [ %27, %26 ]
%32 = mul nsw i32 %3, %2
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
%35 = tail call double @sqrt(double %34)
ret double %35
}