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

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

12:                                               ; preds = %35, %4
  %13 = load i32, ptr %10, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %40

16:                                               ; preds = %12
  store i32 0, ptr %11, align 4, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %17, ptr %9, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %27, %16
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %18
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %25, i32 1
  store ptr %26, ptr %5, align 8, !tbaa !5
  store double %24, ptr %25, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %22
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = sext i32 %30 to i64
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  store ptr %33, ptr %9, align 8, !tbaa !5
  br label %18, !llvm.loop !13

34:                                               ; preds = %18
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %10, align 4, !tbaa !9
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds double, ptr %38, i32 1
  store ptr %39, ptr %6, align 8, !tbaa !5
  br label %12, !llvm.loop !15

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN9MathTools5mattrEPdS0_ii(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge22

.preheader.lr.ph:                                 ; preds = %4
  %6 = icmp sgt i32 %2, 0
  %7 = zext nneg i32 %3 to i64
  br i1 %6, label %.preheader.us.preheader, label %._crit_edge22

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i32 %2, 7
  %8 = icmp ult i32 %2, 8
  %unroll_iter = and i32 %2, 2147483640
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01121.us = phi i32 [ %36, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.01320.us = phi ptr [ %.lcssa, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.01419.us = phi ptr [ %37, %._crit_edge.us ], [ %1, %.preheader.us.preheader ]
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.01217.us = phi ptr [ %32, %.preheader.us.new ], [ %.01419.us, %.preheader.us ]
  %.116.us = phi ptr [ %31, %.preheader.us.new ], [ %.01320.us, %.preheader.us ]
  %niter = phi i32 [ %niter.next.7, %.preheader.us.new ], [ 0, %.preheader.us ]
  %9 = load double, ptr %.01217.us, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %.116.us, i64 8
  store double %9, ptr %.116.us, align 8, !tbaa !5
  %11 = getelementptr inbounds double, ptr %.01217.us, i64 %7
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.116.us, i64 16
  store double %12, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %11, i64 %7
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %.116.us, i64 24
  store double %15, ptr %13, align 8, !tbaa !5
  %17 = getelementptr inbounds double, ptr %14, i64 %7
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.116.us, i64 32
  store double %18, ptr %16, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %17, i64 %7
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.116.us, i64 40
  store double %21, ptr %19, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %20, i64 %7
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.116.us, i64 48
  store double %24, ptr %22, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %23, i64 %7
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.116.us, i64 56
  store double %27, ptr %25, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %26, i64 %7
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.116.us, i64 64
  store double %30, ptr %28, align 8, !tbaa !5
  %32 = getelementptr inbounds double, ptr %29, i64 %7
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa.ph = phi ptr [ poison, %.preheader.us ], [ %31, %.preheader.us.new ]
  %.01217.us.unr = phi ptr [ %.01419.us, %.preheader.us ], [ %32, %.preheader.us.new ]
  %.116.us.unr = phi ptr [ %.01320.us, %.preheader.us ], [ %31, %.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
  %.01217.us.epil = phi ptr [ %35, %.epil.preheader ], [ %.01217.us.unr, %._crit_edge.us.unr-lcssa ]
  %.116.us.epil = phi ptr [ %34, %.epil.preheader ], [ %.116.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %33 = load double, ptr %.01217.us.epil, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.116.us.epil, i64 8
  store double %33, ptr %.116.us.epil, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %.01217.us.epil, i64 %7
  %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
  %.lcssa = phi ptr [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %34, %.epil.preheader ]
  %36 = add nuw nsw i32 %.01121.us, 1
  %37 = getelementptr inbounds i8, ptr %.01419.us, i64 8
  %exitcond24.not = icmp eq i32 %36, %3
  br i1 %exitcond24.not, label %._crit_edge22, label %.preheader.us, !llvm.loop !13

._crit_edge22:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %4
  ret void
}

attributes #0 = { 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