; 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 speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @VecNd_numDifferentEle(ptr noundef %0, i32 noundef %1, double noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %47, %3
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %50

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = add i32 %17, 1
  store i32 %18, ptr %10, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %43, %16
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %46

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %30, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = fsub double %29, %34
  %36 = call double @llvm.fabs.f64(double %35)
  %37 = load double, ptr %6, align 8, !tbaa !11
  %38 = fcmp olt double %36, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %24
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %39, %24
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = add i32 %44, 1
  store i32 %45, ptr %10, align 4, !tbaa !9
  br label %19, !llvm.loop !13

46:                                               ; preds = %23
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !15

50:                                               ; preds = %15
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sub i32 %51, %52
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %53
}

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"}
!15 = distinct !{!15, !14}


; 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.fabs.f64(double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @VecNd_numDifferentEle(ptr nocapture noundef readonly %0, i32 noundef %1, double noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph22.preheader

.lr.ph22.preheader:                               ; preds = %3
  %4 = zext i32 %1 to i64
  %5 = add i32 %1, -2
  %broadcast.splatinsert33 = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat34 = shufflevector <2 x double> %broadcast.splatinsert33, <2 x double> poison, <2 x i32> zeroinitializer
  br label %.lr.ph22

.loopexit:                                        ; preds = %scalar.ph, %middle.block, %.lr.ph22
  %.1.lcssa = phi i32 [ %.01520, %.lr.ph22 ], [ %29, %middle.block ], [ %.2, %scalar.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond30.not = icmp eq i64 %indvars.iv.next28, %4
  br i1 %exitcond30.not, label %._crit_edge, label %.lr.ph22, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit, %3
  %.015.lcssa = phi i32 [ 0, %3 ], [ %.1.lcssa, %.loopexit ]
  %6 = sub i32 %1, %.015.lcssa
  ret i32 %6

.lr.ph22:                                         ; preds = %.lr.ph22.preheader, %.loopexit
  %indvars.iv27 = phi i64 [ 0, %.lr.ph22.preheader ], [ %indvars.iv.next28, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph22.preheader ], [ %indvars.iv.next, %.loopexit ]
  %.01520 = phi i32 [ 0, %.lr.ph22.preheader ], [ %.1.lcssa, %.loopexit ]
  %7 = trunc i64 %indvars.iv27 to i32
  %8 = sub i32 %5, %7
  %9 = zext i32 %8 to i64
  %10 = add nuw nsw i64 %9, 1
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %11 = icmp ult i64 %indvars.iv.next28, %4
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph22
  %12 = getelementptr inbounds double, ptr %0, i64 %indvars.iv27
  %13 = load double, ptr %12, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %8, 3
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %10, 8589934588
  %ind.end = add nuw i64 %indvars.iv, %n.vec
  %14 = insertelement <2 x i32> <i32 poison, i32 0>, i32 %.01520, i64 0
  %broadcast.splatinsert = insertelement <2 x double> poison, double %13, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %15 = getelementptr double, ptr %0, i64 %indvars.iv
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i32> [ %14, %vector.ph ], [ %26, %vector.body ]
  %vec.phi31 = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %27, %vector.body ]
  %16 = getelementptr double, ptr %15, i64 %index
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %wide.load = load <2 x double>, ptr %16, align 8, !tbaa !7
  %wide.load32 = load <2 x double>, ptr %17, align 8, !tbaa !7
  %18 = fsub <2 x double> %broadcast.splat, %wide.load
  %19 = fsub <2 x double> %broadcast.splat, %wide.load32
  %20 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %18)
  %21 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %19)
  %22 = fcmp olt <2 x double> %20, %broadcast.splat34
  %23 = fcmp olt <2 x double> %21, %broadcast.splat34
  %24 = zext <2 x i1> %22 to <2 x i32>
  %25 = zext <2 x i1> %23 to <2 x i32>
  %26 = add <2 x i32> %vec.phi, %24
  %27 = add <2 x i32> %vec.phi31, %25
  %index.next = add nuw i64 %index, 4
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i32> %27, %26
  %29 = tail call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %10, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv24.ph = phi i64 [ %indvars.iv, %.lr.ph ], [ %ind.end, %middle.block ]
  %.118.ph = phi i32 [ %.01520, %.lr.ph ], [ %29, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv24 = phi i64 [ %indvars.iv.next25, %scalar.ph ], [ %indvars.iv24.ph, %scalar.ph.preheader ]
  %.118 = phi i32 [ %.2, %scalar.ph ], [ %.118.ph, %scalar.ph.preheader ]
  %30 = getelementptr inbounds double, ptr %0, i64 %indvars.iv24
  %31 = load double, ptr %30, align 8, !tbaa !7
  %32 = fsub double %13, %31
  %33 = tail call double @llvm.fabs.f64(double %32)
  %34 = fcmp olt double %33, %2
  %35 = zext i1 %34 to i32
  %.2 = add i32 %.118, %35
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next25 to i32
  %exitcond.not = icmp eq i32 %lftr.wideiv, %1
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !14
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fabs.v2f64(<2 x double>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: read) 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !6, !13, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass