#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);
double sqrt(int);
double rmse(double RMSE, int len, double *intake) {
  double diff = 0;
  double n = len / 2;
  printf(" elements passed into rmse: %i and n: %G \n", len, n);
  for (int i = 0; i < len; i += 2) {
    diff += pow(intake[i + 1] - intake[i], 2);
  }
  RMSE = sqrt(1 / n * diff);
  return RMSE;
}


x86 assembly (clang, -O0):
<rmse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cd <rmse+0x9d>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    117b <rmse+0x4b>
movsd  0xe2b(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmse>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
cvtsi2sd %eax,%xmm0
lea    0xeb6(%rip),%rdi
mov    %r14d,%esi
movsd  %xmm0,(%rsp)
call   1030 <printf@plt>
xorpd  %xmm1,%xmm1
test   %r14d,%r14d
jle    11a6 <rmse+0x76>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  (%rbx,%rbp,8),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
add    $0x2,%rbp
cmp    %r14d,%ebp
jl     1170 <rmse+0x40>
movsd  0xe52(%rip),%xmm0
divsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <sqrt@plt>

LLVM IR (-O0):
@.str = [43 x i8] c" elements passed into rmse: %i and n: %G \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 double
%9 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
store double* %2, double** %6
store double 0.000000e+00, double* %7
%10 = load i32, i32* %5
%11 = sdiv i32 %10, 2
%12 = sitofp i32 %11 to double
store double %12, double* %8
%13 = load i32, i32* %5
%14 = load double, double* %8
%15 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %13, double %14)
store i32 0, i32* %9
br label %16
16: ; preds = %37, %3
%17 = load i32, i32* %9
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load double*, double** %6
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %21, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %6
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fsub double %26, %31
%33 = call i64 @pow(double %32, i32 2)
%34 = sitofp i64 %33 to double
%35 = load double, double* %7
%36 = fadd double %35, %34
store double %36, double* %7
br label %37
37: ; preds = %20
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 2
store i32 %39, i32* %9
br label %16
40: ; preds = %16
%41 = load double, double* %8
%42 = fdiv double 1.000000e+00, %41
%43 = load double, double* %7
%44 = fmul double %42, %43
%45 = fptosi double %44 to i32
%46 = call double @sqrt(i32 %45)
store double %46, double* %4
%47 = load double, double* %4
ret double %47
}

LLVM IR (-O2):
@.str = [43 x i8] c" elements passed into rmse: %i and n: %G \0A\00"
define double @rmse(double %0, i32 %1, double* nocapture %2) {
%4 = sdiv i32 %1, 2
%5 = sitofp i32 %4 to double
%6 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %1, double %5)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %14, label %8
8: ; preds = %14, %3
%9 = phi double [ 0.000000e+00, %3 ], [ %25, %14 ]
%10 = fdiv double 1.000000e+00, %5
%11 = fmul double %10, %9
%12 = fptosi double %11 to i32
%13 = tail call double @sqrt(i32 %12)
ret double %13
14: ; preds = %3, %14
%15 = phi i64 [ %26, %14 ], [ 0, %3 ]
%16 = phi double [ %25, %14 ], [ 0.000000e+00, %3 ]
%17 = or i64 %15, 1
%18 = getelementptr inbounds double, double* %2, i64 %17
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %2, i64 %15
%21 = load double, double* %20
%22 = fsub double %19, %21
%23 = tail call i64 @pow(double %22, i32 2)
%24 = sitofp i64 %23 to double
%25 = fadd double %16, %24
%26 = add nuw i64 %15, 2
%27 = trunc i64 %26 to i32
%28 = icmp slt i32 %27, %1
br i1 %28, label %14, label %8
}