; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libUSAC/utils/MathFunctions.ll (ZN9MathTools4mmulEPdS0_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 uwtable
define dso_local void @_ZN9MathTools4mmulEPdS0_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 ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = 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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZN9MathTools4trnmEPdi(ptr noundef %15, i32 noundef %16)
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %53, %4
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %60

21:                                               ; preds = %17
  store i32 0, ptr %13, align 4, !tbaa !9
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %22, ptr %10, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %49, %21
  %24 = load i32, ptr %13, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %52

27:                                               ; preds = %23
  store i32 0, ptr %14, align 4, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %28, ptr %9, align 8, !tbaa !5
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %42, %27
  %30 = load i32, ptr %14, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %45

33:                                               ; preds = %29
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %34, i32 1
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load double, ptr %34, align 8, !tbaa !11
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %37, i32 1
  store ptr %38, ptr %10, align 8, !tbaa !5
  %39 = load double, ptr %37, align 8, !tbaa !11
  %40 = load double, ptr %11, align 8, !tbaa !11
  %41 = call double @llvm.fmuladd.f64(double %36, double %39, double %40)
  store double %41, ptr %11, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %33
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %14, align 4, !tbaa !9
  br label %29, !llvm.loop !13

45:                                               ; preds = %29
  %46 = load double, ptr %11, align 8, !tbaa !11
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %47, i32 1
  store ptr %48, ptr %5, align 8, !tbaa !5
  store double %46, ptr %47, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %45
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %13, align 4, !tbaa !9
  br label %23, !llvm.loop !15

52:                                               ; preds = %23
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %12, align 4, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds double, ptr %57, i64 %58
  store ptr %59, ptr %6, align 8, !tbaa !5
  br label %17, !llvm.loop !16

60:                                               ; preds = %17
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZN9MathTools4trnmEPdi(ptr noundef %61, i32 noundef %62)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9MathTools4trnmEPdi(ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress 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 = { 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 #4 = { 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}
!16 = distinct !{!16, !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 nounwind uwtable
define dso_local void @_ZN9MathTools4mmulEPdS0_S0_i(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  tail call void @_ZN9MathTools4trnmEPdi(ptr noundef %2, i32 noundef %3)
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.preheader30.lr.ph, label %._crit_edge

.preheader30.lr.ph:                               ; preds = %4
  %6 = zext nneg i32 %3 to i64
  %xtraiter = and i32 %3, 3
  %7 = icmp ult i32 %3, 4
  %unroll_iter = and i32 %3, 2147483644
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader30.us

.preheader30.us:                                  ; preds = %._crit_edge39.split.us.us, %.preheader30.lr.ph
  %.02243.us = phi i32 [ 0, %.preheader30.lr.ph ], [ %35, %._crit_edge39.split.us.us ]
  %.02642.us = phi ptr [ %0, %.preheader30.lr.ph ], [ %33, %._crit_edge39.split.us.us ]
  %.02841.us = phi ptr [ %1, %.preheader30.lr.ph ], [ %36, %._crit_edge39.split.us.us ]
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %._crit_edge.us.us, %.preheader30.us
  %.02138.us.us = phi i32 [ 0, %.preheader30.us ], [ %34, %._crit_edge.us.us ]
  %.02437.us.us = phi ptr [ %2, %.preheader30.us ], [ %.lcssa52, %._crit_edge.us.us ]
  %.12736.us.us = phi ptr [ %.02642.us, %.preheader30.us ], [ %33, %._crit_edge.us.us ]
  br i1 %7, label %._crit_edge.us.us.unr-lcssa, label %.preheader.us.us.new

.preheader.us.us.new:                             ; preds = %.preheader.us.us, %.preheader.us.us.new
  %.02333.us.us = phi double [ %27, %.preheader.us.us.new ], [ 0.000000e+00, %.preheader.us.us ]
  %.132.us.us = phi ptr [ %25, %.preheader.us.us.new ], [ %.02437.us.us, %.preheader.us.us ]
  %.02531.us.us = phi ptr [ %23, %.preheader.us.us.new ], [ %.02841.us, %.preheader.us.us ]
  %niter = phi i32 [ %niter.next.3, %.preheader.us.us.new ], [ 0, %.preheader.us.us ]
  %8 = getelementptr inbounds i8, ptr %.02531.us.us, i64 8
  %9 = load double, ptr %.02531.us.us, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %.132.us.us, i64 8
  %11 = load double, ptr %.132.us.us, align 8, !tbaa !5
  %12 = tail call double @llvm.fmuladd.f64(double %9, double %11, double %.02333.us.us)
  %13 = getelementptr inbounds i8, ptr %.02531.us.us, i64 16
  %14 = load double, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.132.us.us, i64 16
  %16 = load double, ptr %10, align 8, !tbaa !5
  %17 = tail call double @llvm.fmuladd.f64(double %14, double %16, double %12)
  %18 = getelementptr inbounds i8, ptr %.02531.us.us, i64 24
  %19 = load double, ptr %13, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.132.us.us, i64 24
  %21 = load double, ptr %15, align 8, !tbaa !5
  %22 = tail call double @llvm.fmuladd.f64(double %19, double %21, double %17)
  %23 = getelementptr inbounds i8, ptr %.02531.us.us, i64 32
  %24 = load double, ptr %18, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.132.us.us, i64 32
  %26 = load double, ptr %20, align 8, !tbaa !5
  %27 = tail call double @llvm.fmuladd.f64(double %24, double %26, double %22)
  %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.us.unr-lcssa, label %.preheader.us.us.new, !llvm.loop !9

._crit_edge.us.us.unr-lcssa:                      ; preds = %.preheader.us.us.new, %.preheader.us.us
  %.lcssa52.ph = phi ptr [ poison, %.preheader.us.us ], [ %25, %.preheader.us.us.new ]
  %.lcssa.ph = phi double [ poison, %.preheader.us.us ], [ %27, %.preheader.us.us.new ]
  %.02333.us.us.unr = phi double [ 0.000000e+00, %.preheader.us.us ], [ %27, %.preheader.us.us.new ]
  %.132.us.us.unr = phi ptr [ %.02437.us.us, %.preheader.us.us ], [ %25, %.preheader.us.us.new ]
  %.02531.us.us.unr = phi ptr [ %.02841.us, %.preheader.us.us ], [ %23, %.preheader.us.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.us.unr-lcssa, %.epil.preheader
  %.02333.us.us.epil = phi double [ %32, %.epil.preheader ], [ %.02333.us.us.unr, %._crit_edge.us.us.unr-lcssa ]
  %.132.us.us.epil = phi ptr [ %30, %.epil.preheader ], [ %.132.us.us.unr, %._crit_edge.us.us.unr-lcssa ]
  %.02531.us.us.epil = phi ptr [ %28, %.epil.preheader ], [ %.02531.us.us.unr, %._crit_edge.us.us.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.us.unr-lcssa ]
  %28 = getelementptr inbounds i8, ptr %.02531.us.us.epil, i64 8
  %29 = load double, ptr %.02531.us.us.epil, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.132.us.us.epil, i64 8
  %31 = load double, ptr %.132.us.us.epil, align 8, !tbaa !5
  %32 = tail call double @llvm.fmuladd.f64(double %29, double %31, double %.02333.us.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.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us.us:                                ; preds = %.epil.preheader, %._crit_edge.us.us.unr-lcssa
  %.lcssa52 = phi ptr [ %.lcssa52.ph, %._crit_edge.us.us.unr-lcssa ], [ %30, %.epil.preheader ]
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.us.unr-lcssa ], [ %32, %.epil.preheader ]
  %33 = getelementptr inbounds i8, ptr %.12736.us.us, i64 8
  store double %.lcssa, ptr %.12736.us.us, align 8, !tbaa !5
  %34 = add nuw nsw i32 %.02138.us.us, 1
  %exitcond46.not = icmp eq i32 %34, %3
  br i1 %exitcond46.not, label %._crit_edge39.split.us.us, label %.preheader.us.us, !llvm.loop !13

._crit_edge39.split.us.us:                        ; preds = %._crit_edge.us.us
  %35 = add nuw nsw i32 %.02243.us, 1
  %36 = getelementptr inbounds double, ptr %.02841.us, i64 %6
  %exitcond47.not = icmp eq i32 %35, %3
  br i1 %exitcond47.not, label %._crit_edge, label %.preheader30.us, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge39.split.us.us, %4
  tail call void @_ZN9MathTools4trnmEPdi(ptr noundef %2, i32 noundef %3)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9MathTools4trnmEPdi(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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


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