; LLVM IR from Dimandragon/non-parametric-dsp :: alglib-cpp/src (optimization)

; 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"

%"struct.alglib_impl::ae_matrix" = type { i64, i64, i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon.1 }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%union.anon.1 = type { ptr }
%"struct.alglib_impl::ae_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon.0 }
%union.anon.0 = type { ptr }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11alglib_impl26scaleshiftdensebrlcinplaceEPKNS_9ae_vectorES2_lPNS_9ae_matrixEPS0_S5_lPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7) #2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %84, %8
  %22 = load i64, ptr %17, align 8, !tbaa !9
  %23 = load i64, ptr %15, align 8, !tbaa !9
  %24 = sub nsw i64 %23, 1
  %25 = icmp sle i64 %22, %24
  br i1 %25, label %26, label %87

26:                                               ; preds = %21
  store double 0.000000e+00, ptr %19, align 8, !tbaa !11
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %67, %26
  %28 = load i64, ptr %18, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = sub nsw i64 %29, 1
  %31 = icmp sle i64 %28, %30
  br i1 %31, label %32, label %70

32:                                               ; preds = %27
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = load i64, ptr %17, align 8, !tbaa !9
  %37 = getelementptr inbounds ptr, ptr %35, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = load i64, ptr %18, align 8, !tbaa !9
  %40 = getelementptr inbounds double, ptr %38, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  store double %41, ptr %20, align 8, !tbaa !11
  %42 = load double, ptr %19, align 8, !tbaa !11
  %43 = load double, ptr %20, align 8, !tbaa !11
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = load i64, ptr %18, align 8, !tbaa !9
  %48 = getelementptr inbounds double, ptr %46, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = call double @llvm.fmuladd.f64(double %43, double %49, double %42)
  store double %50, ptr %19, align 8, !tbaa !11
  %51 = load double, ptr %20, align 8, !tbaa !11
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load i64, ptr %18, align 8, !tbaa !9
  %56 = getelementptr inbounds double, ptr %54, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fmul double %51, %57
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %59, i32 0, i32 6
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load i64, ptr %17, align 8, !tbaa !9
  %63 = getelementptr inbounds ptr, ptr %61, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load i64, ptr %18, align 8, !tbaa !9
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  store double %58, ptr %66, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %32
  %68 = load i64, ptr %18, align 8, !tbaa !9
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %18, align 8, !tbaa !9
  br label %27, !llvm.loop !14

70:                                               ; preds = %27
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  %74 = load i64, ptr %17, align 8, !tbaa !9
  %75 = getelementptr inbounds double, ptr %73, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load double, ptr %19, align 8, !tbaa !11
  %78 = fsub double %76, %77
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %79, i32 0, i32 4
  %81 = load ptr, ptr %80, align 8, !tbaa !13
  %82 = load i64, ptr %17, align 8, !tbaa !9
  %83 = getelementptr inbounds double, ptr %81, i64 %82
  store double %78, ptr %83, align 8, !tbaa !11
  br label %84

84:                                               ; preds = %70
  %85 = load i64, ptr %17, align 8, !tbaa !9
  %86 = add nsw i64 %85, 1
  store i64 %86, ptr %17, align 8, !tbaa !9
  br label %21, !llvm.loop !16

87:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 @_ZN11alglib_impl26scaleshiftdensebrlcinplaceEPKNS_9ae_vectorES2_lPNS_9ae_matrixEPS0_S5_lPNS_8ae_stateE(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readnone %5, i64 noundef %6, ptr nocapture noundef readnone %7) local_unnamed_addr #1 {
  %.not.not29 = icmp sgt i64 %6, 0
  br i1 %.not.not29, label %.preheader.lr.ph, label %._crit_edge31

.preheader.lr.ph:                                 ; preds = %8
  %.not.not2526 = icmp sgt i64 %2, 0
  %9 = getelementptr inbounds i8, ptr %3, i64 72
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  %12 = getelementptr inbounds i8, ptr %4, i64 56
  br i1 %.not.not2526, label %.preheader.us.preheader, label %._crit_edge31

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i64 %2, 1
  %13 = icmp eq i64 %2, 1
  %unroll_iter = and i64 %2, 9223372036854775806
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.030.us = phi i64 [ %59, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  br i1 %13, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.02328.us = phi double [ %36, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %.02427.us = phi i64 [ %41, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds ptr, ptr %14, i64 %.030.us
  %16 = load ptr, ptr %15, align 8, !tbaa !8
  %17 = getelementptr inbounds double, ptr %16, i64 %.02427.us
  %18 = load double, ptr %17, align 8, !tbaa !10
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 %.02427.us
  %21 = load double, ptr %20, align 8, !tbaa !10
  %22 = tail call double @llvm.fmuladd.f64(double %18, double %21, double %.02328.us)
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = getelementptr inbounds double, ptr %23, i64 %.02427.us
  %25 = load double, ptr %24, align 8, !tbaa !10
  %26 = fmul double %18, %25
  store double %26, ptr %17, align 8, !tbaa !10
  %27 = or disjoint i64 %.02427.us, 1
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.030.us
  %30 = load ptr, ptr %29, align 8, !tbaa !8
  %31 = getelementptr inbounds double, ptr %30, i64 %27
  %32 = load double, ptr %31, align 8, !tbaa !10
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds double, ptr %33, i64 %27
  %35 = load double, ptr %34, align 8, !tbaa !10
  %36 = tail call double @llvm.fmuladd.f64(double %32, double %35, double %22)
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %37, i64 %27
  %39 = load double, ptr %38, align 8, !tbaa !10
  %40 = fmul double %32, %39
  store double %40, ptr %31, align 8, !tbaa !10
  %41 = add nuw nsw i64 %.02427.us, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !12

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa.ph = phi double [ poison, %.preheader.us ], [ %36, %.preheader.us.new ]
  %.02328.us.unr = phi double [ 0.000000e+00, %.preheader.us ], [ %36, %.preheader.us.new ]
  %.02427.us.unr = phi i64 [ 0, %.preheader.us ], [ %41, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.030.us
  %44 = load ptr, ptr %43, align 8, !tbaa !8
  %45 = getelementptr inbounds double, ptr %44, i64 %.02427.us.unr
  %46 = load double, ptr %45, align 8, !tbaa !10
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %47, i64 %.02427.us.unr
  %49 = load double, ptr %48, align 8, !tbaa !10
  %50 = tail call double @llvm.fmuladd.f64(double %46, double %49, double %.02328.us.unr)
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds double, ptr %51, i64 %.02427.us.unr
  %53 = load double, ptr %52, align 8, !tbaa !10
  %54 = fmul double %46, %53
  store double %54, ptr %45, align 8, !tbaa !10
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %50, %._crit_edge.us.epilog-lcssa ]
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %55, i64 %.030.us
  %57 = load double, ptr %56, align 8, !tbaa !10
  %58 = fsub double %57, %.lcssa
  store double %58, ptr %56, align 8, !tbaa !10
  %59 = add nuw nsw i64 %.030.us, 1
  %exitcond33.not = icmp eq i64 %59, %6
  br i1 %exitcond33.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !14

._crit_edge31:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %8
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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