#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, int);
int /*<<< orphan*/ printf(char *, int);
double sqrt(double);
double rmse(double *vals, int len, double ref) {
  double sum = 0;
  printf("From C: len=%d\n", len);
  int i;
  for (i = 0; i < len; i++) {
    sum += pow(vals[i] - ref, 2);
  }
  return sqrt(sum / len);
}


x86 assembly (clang, -O0):
<rmse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a7 <rmse+0x77>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <rmse+0x32>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
xorpd  %xmm0,%xmm0
test   %r14d,%r14d
jle    1298 <rmse+0x168>
movsd  0x8(%rsp),%xmm1
mov    %r14d,%r12d
lea    -0x1(%r12),%rax
mov    %r12d,%r15d
and    $0x3,%r15d
cmp    $0x3,%rax
jae    1187 <rmse+0x57>
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
jmp    1250 <rmse+0x120>
and    $0xfffffffc,%r12d
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rbx,%rbp,8),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x18(%rbx,%rbp,8),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
add    $0x4,%rbp
cmp    %rbp,%r12
jne    11a0 <rmse+0x70>
test   %r15,%r15
je     1298 <rmse+0x168>
lea    (%rbx,%rbp,8),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1260 <rmse+0x130>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
ucomisd 0xd54(%rip),%xmm0
jb     12bf <rmse+0x18f>
sqrtsd %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sqrt@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"From C: len=%d\0A\00"
define double @rmse(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
store double 0.000000e+00, double* %7
%9 = load i32, i32* %5
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %8
br label %11
11: ; preds = %27, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load double*, double** %4
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = load double, double* %6
%22 = fsub double %20, %21
%23 = call i64 @pow(double %22, i32 2)
%24 = sitofp i64 %23 to double
%25 = load double, double* %7
%26 = fadd double %25, %24
store double %26, double* %7
br label %27
27: ; preds = %15
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %11
30: ; preds = %11
%31 = load double, double* %7
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
%35 = call double @sqrt(double %34)
ret double %35
}

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