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

; 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 @_ZN9MathTools4trnmEPdi(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = sub nsw i32 %11, 1
  store i32 %12, ptr %10, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %46, %2
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sub nsw i32 %15, 1
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %56

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 1
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  store ptr %24, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %42, %18
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %45

29:                                               ; preds = %25
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load double, ptr %30, align 8, !tbaa !11
  store double %31, ptr %5, align 8, !tbaa !11
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %34, i32 1
  store ptr %35, ptr %6, align 8, !tbaa !5
  store double %33, ptr %34, align 8, !tbaa !11
  %36 = load double, ptr %5, align 8, !tbaa !11
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store double %36, ptr %37, align 8, !tbaa !11
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds double, ptr %39, i64 %40
  store ptr %41, ptr %7, align 8, !tbaa !5
  br label %42

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

45:                                               ; preds = %25
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %10, align 4, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds double, ptr %53, i64 %54
  store ptr %55, ptr %3, align 8, !tbaa !5
  br label %13, !llvm.loop !15

56:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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 @_ZN9MathTools4trnmEPdi(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = add i32 %1, -1
  %4 = icmp sgt i32 %1, 1
  br i1 %4, label %.lr.ph32, label %._crit_edge33

.lr.ph32:                                         ; preds = %2
  %5 = zext nneg i32 %1 to i64
  %6 = add nuw nsw i32 %1, 1
  %7 = zext nneg i32 %6 to i64
  %8 = add nsw i32 %1, -2
  br label %9

9:                                                ; preds = %.lr.ph32, %._crit_edge
  %.030 = phi i32 [ %3, %.lr.ph32 ], [ %24, %._crit_edge ]
  %.02029 = phi i32 [ 0, %.lr.ph32 ], [ %23, %._crit_edge ]
  %.02328 = phi ptr [ %0, %.lr.ph32 ], [ %25, %._crit_edge ]
  %10 = icmp sgt i32 %.030, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %11 = sub i32 %8, %.02029
  %xtraiter = and i32 %.030, 3
  %12 = icmp ult i32 %11, 3
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %.030, 2147483644
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.023.pn26 = phi ptr [ %.02328, %.lr.ph.preheader.new ], [ %.021.3, %.lr.ph ]
  %.023.pn2425 = phi ptr [ %.02328, %.lr.ph.preheader.new ], [ %.022.3, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %.022 = getelementptr inbounds i8, ptr %.023.pn2425, i64 8
  %.021 = getelementptr inbounds double, ptr %.023.pn26, i64 %5
  %13 = load double, ptr %.022, align 8, !tbaa !5
  %14 = load double, ptr %.021, align 8, !tbaa !5
  store double %14, ptr %.022, align 8, !tbaa !5
  store double %13, ptr %.021, align 8, !tbaa !5
  %.022.1 = getelementptr inbounds i8, ptr %.023.pn2425, i64 16
  %.021.1 = getelementptr inbounds double, ptr %.021, i64 %5
  %15 = load double, ptr %.022.1, align 8, !tbaa !5
  %16 = load double, ptr %.021.1, align 8, !tbaa !5
  store double %16, ptr %.022.1, align 8, !tbaa !5
  store double %15, ptr %.021.1, align 8, !tbaa !5
  %.022.2 = getelementptr inbounds i8, ptr %.023.pn2425, i64 24
  %.021.2 = getelementptr inbounds double, ptr %.021.1, i64 %5
  %17 = load double, ptr %.022.2, align 8, !tbaa !5
  %18 = load double, ptr %.021.2, align 8, !tbaa !5
  store double %18, ptr %.022.2, align 8, !tbaa !5
  store double %17, ptr %.021.2, align 8, !tbaa !5
  %.022.3 = getelementptr inbounds i8, ptr %.023.pn2425, i64 32
  %.021.3 = getelementptr inbounds double, ptr %.021.2, i64 %5
  %19 = load double, ptr %.022.3, align 8, !tbaa !5
  %20 = load double, ptr %.021.3, align 8, !tbaa !5
  store double %20, ptr %.022.3, align 8, !tbaa !5
  store double %19, ptr %.021.3, align 8, !tbaa !5
  %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.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.023.pn26.unr = phi ptr [ %.02328, %.lr.ph.preheader ], [ %.021.3, %.lr.ph ]
  %.023.pn2425.unr = phi ptr [ %.02328, %.lr.ph.preheader ], [ %.022.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.023.pn26.epil = phi ptr [ %.021.epil, %.lr.ph.epil ], [ %.023.pn26.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.023.pn2425.epil = phi ptr [ %.022.epil, %.lr.ph.epil ], [ %.023.pn2425.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %.022.epil = getelementptr inbounds i8, ptr %.023.pn2425.epil, i64 8
  %.021.epil = getelementptr inbounds double, ptr %.023.pn26.epil, i64 %5
  %21 = load double, ptr %.022.epil, align 8, !tbaa !5
  %22 = load double, ptr %.021.epil, align 8, !tbaa !5
  store double %22, ptr %.022.epil, align 8, !tbaa !5
  store double %21, ptr %.021.epil, align 8, !tbaa !5
  %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, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %9
  %23 = add nuw nsw i32 %.02029, 1
  %24 = add nsw i32 %.030, -1
  %25 = getelementptr inbounds double, ptr %.02328, i64 %7
  %exitcond34.not = icmp eq i32 %23, %3
  br i1 %exitcond34.not, label %._crit_edge33, label %9, !llvm.loop !13

._crit_edge33:                                    ; preds = %._crit_edge, %2
  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: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass