; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libUSAC/utils/MathFunctions.ll (ZN9MathTools4vmulEPdS0_S0_i)

; 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.fmuladd.f64(double, double, 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: mustprogress nounwind uwtable
define dso_local void @_ZN9MathTools4vmulEPdS0_S0_i(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %39, %4
  %14 = load i32, ptr %11, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %42

17:                                               ; preds = %13
  store i32 0, ptr %12, align 4, !tbaa !9
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %18, ptr %10, align 8, !tbaa !5
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %32, %17
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %35

23:                                               ; preds = %19
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i32 1
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load double, ptr %24, align 8, !tbaa !11
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds double, ptr %27, i32 1
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = load double, ptr %27, align 8, !tbaa !11
  %30 = load double, ptr %9, align 8, !tbaa !11
  %31 = call double @llvm.fmuladd.f64(double %26, double %29, double %30)
  store double %31, ptr %9, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %23
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %12, align 4, !tbaa !9
  br label %19, !llvm.loop !13

35:                                               ; preds = %19
  %36 = load double, ptr %9, align 8, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %37, i32 1
  store ptr %38, ptr %5, align 8, !tbaa !5
  store double %36, ptr %37, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %35
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %11, align 4, !tbaa !9
  br label %13, !llvm.loop !15

42:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress 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++ 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.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN9MathTools4vmulEPdS0_S0_i(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.preheader.us.preheader, label %._crit_edge25

.preheader.us.preheader:                          ; preds = %4
  %xtraiter = and i32 %3, 3
  %6 = icmp ult i32 %3, 4
  %unroll_iter = and i32 %3, 2147483644
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01124.us = phi i32 [ %33, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.01423.us = phi ptr [ %32, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.01522.us = phi ptr [ %.lcssa30, %._crit_edge.us ], [ %1, %.preheader.us.preheader ]
  br i1 %6, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.01219.us = phi ptr [ %24, %.preheader.us.new ], [ %2, %.preheader.us ]
  %.01318.us = phi double [ %26, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %.117.us = phi ptr [ %22, %.preheader.us.new ], [ %.01522.us, %.preheader.us ]
  %niter = phi i32 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %7 = getelementptr inbounds i8, ptr %.117.us, i64 8
  %8 = load double, ptr %.117.us, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %.01219.us, i64 8
  %10 = load double, ptr %.01219.us, align 8, !tbaa !5
  %11 = tail call double @llvm.fmuladd.f64(double %8, double %10, double %.01318.us)
  %12 = getelementptr inbounds i8, ptr %.117.us, i64 16
  %13 = load double, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.01219.us, i64 16
  %15 = load double, ptr %9, align 8, !tbaa !5
  %16 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %11)
  %17 = getelementptr inbounds i8, ptr %.117.us, i64 24
  %18 = load double, ptr %12, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.01219.us, i64 24
  %20 = load double, ptr %14, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %16)
  %22 = getelementptr inbounds i8, ptr %.117.us, i64 32
  %23 = load double, ptr %17, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.01219.us, i64 32
  %25 = load double, ptr %19, align 8, !tbaa !5
  %26 = tail call double @llvm.fmuladd.f64(double %23, double %25, double %21)
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa30.ph = phi ptr [ poison, %.preheader.us ], [ %22, %.preheader.us.new ]
  %.lcssa.ph = phi double [ poison, %.preheader.us ], [ %26, %.preheader.us.new ]
  %.01219.us.unr = phi ptr [ %2, %.preheader.us ], [ %24, %.preheader.us.new ]
  %.01318.us.unr = phi double [ 0.000000e+00, %.preheader.us ], [ %26, %.preheader.us.new ]
  %.117.us.unr = phi ptr [ %.01522.us, %.preheader.us ], [ %22, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.01219.us.epil = phi ptr [ %29, %.epil.preheader ], [ %.01219.us.unr, %._crit_edge.us.unr-lcssa ]
  %.01318.us.epil = phi double [ %31, %.epil.preheader ], [ %.01318.us.unr, %._crit_edge.us.unr-lcssa ]
  %.117.us.epil = phi ptr [ %27, %.epil.preheader ], [ %.117.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %27 = getelementptr inbounds i8, ptr %.117.us.epil, i64 8
  %28 = load double, ptr %.117.us.epil, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.01219.us.epil, i64 8
  %30 = load double, ptr %.01219.us.epil, align 8, !tbaa !5
  %31 = tail call double @llvm.fmuladd.f64(double %28, double %30, double %.01318.us.epil)
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %.lcssa30 = phi ptr [ %.lcssa30.ph, %._crit_edge.us.unr-lcssa ], [ %27, %.epil.preheader ]
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %31, %.epil.preheader ]
  %32 = getelementptr inbounds i8, ptr %.01423.us, i64 8
  store double %.lcssa, ptr %.01423.us, align 8, !tbaa !5
  %33 = add nuw nsw i32 %.01124.us, 1
  %exitcond27.not = icmp eq i32 %33, %3
  br i1 %exitcond27.not, label %._crit_edge25, label %.preheader.us, !llvm.loop !13

._crit_edge25:                                    ; preds = %._crit_edge.us, %4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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" }

!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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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