; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsvector)

; 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"

%struct.XsVector = type { ptr, i64, i64 }

@XsMath_zero = external constant double, align 8

; 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: nounwind uwtable
define dso_local double @XsVector_dotProduct(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load double, ptr @XsMath_zero, align 8, !tbaa !9
  store double %7, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XsVector, ptr %8, i32 0, i32 1
  %10 = load i64, ptr %9, align 1, !tbaa !11
  store i64 %10, ptr %5, align 8, !tbaa !14
  br label %11

11:                                               ; preds = %15, %2
  %12 = load i64, ptr %5, align 8, !tbaa !14
  %13 = add i64 %12, -1
  store i64 %13, ptr %5, align 8, !tbaa !14
  %14 = icmp ne i64 %12, 0
  br i1 %14, label %15, label %30

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XsVector, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 1, !tbaa !15
  %19 = load i64, ptr %5, align 8, !tbaa !14
  %20 = getelementptr inbounds double, ptr %18, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XsVector, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 1, !tbaa !15
  %25 = load i64, ptr %5, align 8, !tbaa !14
  %26 = getelementptr inbounds double, ptr %24, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = load double, ptr %6, align 8, !tbaa !9
  %29 = call double @llvm.fmuladd.f64(double %21, double %27, double %28)
  store double %29, ptr %6, align 8, !tbaa !9
  br label %11, !llvm.loop !16

30:                                               ; preds = %11
  %31 = load double, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %31
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"XsVector", !6, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@XsMath_zero = external local_unnamed_addr constant double, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local double @XsVector_dotProduct(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load double, ptr @XsMath_zero, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 1, !tbaa !9
  %.not8 = icmp eq i64 %5, 0
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = load ptr, ptr %0, align 1, !tbaa !13
  %7 = load ptr, ptr %1, align 1, !tbaa !13
  %xtraiter = and i64 %5, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph, %.prol.preheader
  %.010.prol = phi double [ %13, %.prol.preheader ], [ %3, %.lr.ph ]
  %.079.prol = phi i64 [ %8, %.prol.preheader ], [ %5, %.lr.ph ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph ]
  %8 = add i64 %.079.prol, -1
  %9 = getelementptr inbounds double, ptr %6, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds double, ptr %7, i64 %8
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = tail call double @llvm.fmuladd.f64(double %10, double %12, double %.010.prol)
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !14

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph
  %.lcssa.unr = phi double [ poison, %.lr.ph ], [ %13, %.prol.preheader ]
  %.010.unr = phi double [ %3, %.lr.ph ], [ %13, %.prol.preheader ]
  %.079.unr = phi i64 [ %5, %.lr.ph ], [ %8, %.prol.preheader ]
  %14 = icmp ult i64 %5, 4
  br i1 %14, label %._crit_edge, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %.010 = phi double [ %38, %.lr.ph.new ], [ %.010.unr, %.prol.loopexit ]
  %.079 = phi i64 [ %33, %.lr.ph.new ], [ %.079.unr, %.prol.loopexit ]
  %15 = add i64 %.079, -1
  %16 = getelementptr inbounds double, ptr %6, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds double, ptr %7, i64 %15
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = tail call double @llvm.fmuladd.f64(double %17, double %19, double %.010)
  %21 = add i64 %.079, -2
  %22 = getelementptr inbounds double, ptr %6, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds double, ptr %7, i64 %21
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = tail call double @llvm.fmuladd.f64(double %23, double %25, double %20)
  %27 = add i64 %.079, -3
  %28 = getelementptr inbounds double, ptr %6, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %7, i64 %27
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = tail call double @llvm.fmuladd.f64(double %29, double %31, double %26)
  %33 = add i64 %.079, -4
  %34 = getelementptr inbounds double, ptr %6, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds double, ptr %7, i64 %33
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = tail call double @llvm.fmuladd.f64(double %35, double %37, double %32)
  %.not.3 = icmp eq i64 %33, 0
  br i1 %.not.3, label %._crit_edge, label %.lr.ph.new, !llvm.loop !16

._crit_edge:                                      ; preds = %.prol.loopexit, %.lr.ph.new, %2
  %.0.lcssa = phi double [ %3, %2 ], [ %.lcssa.unr, %.prol.loopexit ], [ %38, %.lr.ph.new ]
  ret double %.0.lcssa
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 #1 = { mustprogress 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 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"XsVector", !11, i64 0, !12, i64 8, !12, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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