; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/DSP/Source/StatisticsFunctions (f64)

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

16:                                               ; preds = %29, %3
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp ugt i32 %17, 0
  br i1 %18, label %19, label %32

19:                                               ; preds = %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i32 1
  store ptr %21, ptr %4, align 8, !tbaa !5
  %22 = load double, ptr %20, align 8, !tbaa !11
  %23 = call double @llvm.fabs.f64(double %22)
  store double %23, ptr %7, align 8, !tbaa !11
  %24 = load double, ptr %8, align 8, !tbaa !11
  %25 = load double, ptr %7, align 8, !tbaa !11
  %26 = fcmp olt double %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %19
  %28 = load double, ptr %7, align 8, !tbaa !11
  store double %28, ptr %8, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %27, %19
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = add i32 %30, -1
  store i32 %31, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !13

32:                                               ; preds = %16
  %33 = load double, ptr %8, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  store double %33, ptr %34, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @arm_absmax_no_idx_f64(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = tail call double @llvm.fabs.f64(double %4)
  %.012 = add i32 %1, -1
  %.not13 = icmp eq i32 %.012, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %xtraiter = and i32 %.012, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %.010.prol = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load double, ptr %.010.prol, align 8, !tbaa !5
  %7 = tail call double @llvm.fabs.f64(double %6)
  %8 = fcmp olt double %5, %7
  %.1.prol = select i1 %8, double %7, double %5
  %.0.prol = add i32 %1, -2
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.1.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %.1.prol, %.lr.ph.prol ]
  %.016.unr = phi i32 [ %.012, %.lr.ph.preheader ], [ %.0.prol, %.lr.ph.prol ]
  %.0915.unr = phi double [ %5, %.lr.ph.preheader ], [ %.1.prol, %.lr.ph.prol ]
  %.pn14.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %.010.prol, %.lr.ph.prol ]
  %9 = icmp eq i32 %1, 2
  br i1 %9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.016 = phi i32 [ %.0.1, %.lr.ph ], [ %.016.unr, %.lr.ph.prol.loopexit ]
  %.0915 = phi double [ %.1.1, %.lr.ph ], [ %.0915.unr, %.lr.ph.prol.loopexit ]
  %.pn14 = phi ptr [ %.010.1, %.lr.ph ], [ %.pn14.unr, %.lr.ph.prol.loopexit ]
  %.010 = getelementptr inbounds i8, ptr %.pn14, i64 8
  %10 = load double, ptr %.010, align 8, !tbaa !5
  %11 = tail call double @llvm.fabs.f64(double %10)
  %12 = fcmp olt double %.0915, %11
  %.1 = select i1 %12, double %11, double %.0915
  %.010.1 = getelementptr inbounds i8, ptr %.pn14, i64 16
  %13 = load double, ptr %.010.1, align 8, !tbaa !5
  %14 = tail call double @llvm.fabs.f64(double %13)
  %15 = fcmp olt double %.1, %14
  %.1.1 = select i1 %15, double %14, double %.1
  %.0.1 = add i32 %.016, -2
  %.not.1 = icmp eq i32 %.0.1, 0
  br i1 %.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %3
  %.09.lcssa = phi double [ %5, %3 ], [ %.1.lcssa.unr, %.lr.ph.prol.loopexit ], [ %.1.1, %.lr.ph ]
  store double %.09.lcssa, ptr %2, align 8, !tbaa !5
  ret void
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: 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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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