; LLVM IR from HRI-EU/Rcs :: src/RcsCore (Rcs_VecNd)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local double @VecNd_covariance(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store double 0.000000e+00, ptr %4, align 8
  br label %53

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = call double @VecNd_mean(ptr noundef %16, i32 noundef %17)
  store double %18, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = call double @VecNd_mean(ptr noundef %19, i32 noundef %20)
  store double %21, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %44, %15
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp ult i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %47

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load double, ptr %8, align 8, !tbaa !11
  %34 = fsub double %32, %33
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load double, ptr %9, align 8, !tbaa !11
  %41 = fsub double %39, %40
  %42 = load double, ptr %10, align 8, !tbaa !11
  %43 = call double @llvm.fmuladd.f64(double %34, double %41, double %42)
  store double %43, ptr %10, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %27
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = add i32 %45, 1
  store i32 %46, ptr %11, align 4, !tbaa !9
  br label %22, !llvm.loop !13

47:                                               ; preds = %26
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = uitofp i32 %48 to double
  %50 = load double, ptr %10, align 8, !tbaa !11
  %51 = fdiv double %50, %49
  store double %51, ptr %10, align 8, !tbaa !11
  %52 = load double, ptr %10, align 8, !tbaa !11
  store double %52, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %53

53:                                               ; preds = %47, %14
  %54 = load double, ptr %4, align 8
  ret double %54
}

; Function Attrs: nounwind uwtable
declare dso_local double @VecNd_mean(ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
define dso_local double @VecNd_covariance(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %34, label %5

5:                                                ; preds = %3
  %6 = tail call double @VecNd_mean(ptr noundef %0, i32 noundef %2)
  %7 = tail call double @VecNd_mean(ptr noundef %1, i32 noundef %2)
  %wide.trip.count = zext i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %2, 1
  br i1 %8, label %.unr-lcssa, label %.new

.new:                                             ; preds = %5
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %19

.unr-lcssa:                                       ; preds = %19, %5
  %.lcssa.ph = phi double [ poison, %5 ], [ %33, %19 ]
  %indvars.iv.unr = phi i64 [ 0, %5 ], [ %indvars.iv.next.1, %19 ]
  %.01821.unr = phi double [ 0.000000e+00, %5 ], [ %33, %19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %16, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %9 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fsub double %10, %6
  %12 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fsub double %13, %7
  %15 = tail call double @llvm.fmuladd.f64(double %11, double %14, double %.01821.unr)
  br label %16

16:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %.unr-lcssa ], [ %15, %.epilog-lcssa ]
  %17 = uitofp i32 %2 to double
  %18 = fdiv double %.lcssa, %17
  br label %34

19:                                               ; preds = %19, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.1, %19 ]
  %.01821 = phi double [ 0.000000e+00, %.new ], [ %33, %19 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.1, %19 ]
  %20 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %21, %6
  %23 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fsub double %24, %7
  %26 = tail call double @llvm.fmuladd.f64(double %22, double %25, double %.01821)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %27 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fsub double %28, %6
  %30 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fsub double %31, %7
  %33 = tail call double @llvm.fmuladd.f64(double %29, double %32, double %26)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.unr-lcssa, label %19, !llvm.loop !9

34:                                               ; preds = %3, %16
  %.019 = phi double [ %18, %16 ], [ 0.000000e+00, %3 ]
  ret double %.019
}

; Function Attrs: nounwind uwtable
declare dso_local double @VecNd_mean(ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass