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

; 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::nlpfilter" = type { double, i64, double, double, i8, %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector" }
%"struct.alglib_impl::ae_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon.0 }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%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

declare void @_ZN11alglib_impl6rgrowvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl10nlpfappendEPNS_9nlpfilterEddPNS_8ae_stateE(ptr noundef %0, double noundef %1, double noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %75, %36, %4
  %11 = load i64, ptr %9, align 8, !tbaa !11
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp slt i64 %11, %14
  br i1 %15, label %16, label %78

16:                                               ; preds = %10
  %17 = load double, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %18, i32 0, i32 5
  %20 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %19, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load i64, ptr %9, align 8, !tbaa !11
  %23 = getelementptr inbounds double, ptr %21, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fcmp ole double %17, %24
  br i1 %25, label %26, label %75

26:                                               ; preds = %16
  %27 = load double, ptr %7, align 8, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %28, i32 0, i32 6
  %30 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = load i64, ptr %9, align 8, !tbaa !11
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fcmp ole double %27, %34
  br i1 %35, label %36, label %75

36:                                               ; preds = %26
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %37, i32 0, i32 5
  %39 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = sub nsw i64 %43, 1
  %45 = getelementptr inbounds double, ptr %40, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %47, i32 0, i32 5
  %49 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i64, ptr %9, align 8, !tbaa !11
  %52 = getelementptr inbounds double, ptr %50, i64 %51
  store double %46, ptr %52, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %53, i32 0, i32 6
  %55 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !13
  %60 = sub nsw i64 %59, 1
  %61 = getelementptr inbounds double, ptr %56, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %63, i32 0, i32 6
  %65 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %64, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = load i64, ptr %9, align 8, !tbaa !11
  %68 = getelementptr inbounds double, ptr %66, i64 %67
  store double %62, ptr %68, align 8, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !13
  %72 = sub nsw i64 %71, 1
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %73, i32 0, i32 1
  store i64 %72, ptr %74, align 8, !tbaa !13
  br label %10, !llvm.loop !19

75:                                               ; preds = %26, %16
  %76 = load i64, ptr %9, align 8, !tbaa !11
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %9, align 8, !tbaa !11
  br label %10, !llvm.loop !19

78:                                               ; preds = %10
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !13
  %82 = add nsw i64 %81, 1
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %83, i32 0, i32 5
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN11alglib_impl6rgrowvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %82, ptr noundef %84, ptr noundef %85)
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %86, i32 0, i32 1
  %88 = load i64, ptr %87, align 8, !tbaa !13
  %89 = add nsw i64 %88, 1
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %90, i32 0, i32 6
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN11alglib_impl6rgrowvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %89, ptr noundef %91, ptr noundef %92)
  %93 = load double, ptr %6, align 8, !tbaa !9
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %94, i32 0, i32 5
  %96 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %95, i32 0, i32 4
  %97 = load ptr, ptr %96, align 8, !tbaa !18
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %98, i32 0, i32 1
  %100 = load i64, ptr %99, align 8, !tbaa !13
  %101 = getelementptr inbounds double, ptr %97, i64 %100
  store double %93, ptr %101, align 8, !tbaa !9
  %102 = load double, ptr %7, align 8, !tbaa !9
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %103, i32 0, i32 6
  %105 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %104, i32 0, i32 4
  %106 = load ptr, ptr %105, align 8, !tbaa !18
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %107, i32 0, i32 1
  %109 = load i64, ptr %108, align 8, !tbaa !13
  %110 = getelementptr inbounds double, ptr %106, i64 %109
  store double %102, ptr %110, align 8, !tbaa !9
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %111, i32 0, i32 1
  %113 = load i64, ptr %112, align 8, !tbaa !13
  %114 = add nsw i64 %113, 1
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  %116 = getelementptr inbounds %"struct.alglib_impl::nlpfilter", ptr %115, i32 0, i32 1
  store i64 %114, ptr %116, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTSN11alglib_impl9nlpfilterE", !10, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !15, i64 32, !16, i64 40, !16, i64 104}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN11alglib_impl9ae_vectorE", !12, i64 0, !12, i64 8, !15, i64 16, !17, i64 24, !7, i64 56}
!17 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

declare void @_ZN11alglib_impl6rgrowvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl10nlpfappendEPNS_9nlpfilterEddPNS_8ae_stateE(ptr noundef %0, double noundef %1, double noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %.promoted39 = load i64, ptr %5, align 8, !tbaa !5
  %6 = icmp sgt i64 %.promoted39, 0
  br i1 %6, label %.lr.ph.lr.ph, label %.outer._crit_edge

.lr.ph.lr.ph:                                     ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = getelementptr inbounds i8, ptr %0, i64 160
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %.outer
  %.0.ph44 = phi i64 [ 0, %.lr.ph.lr.ph ], [ %30, %.outer ]
  %.promoted4143 = phi i64 [ %.promoted39, %.lr.ph.lr.ph ], [ %.promoted40, %.outer ]
  br label %9

9:                                                ; preds = %.lr.ph, %19
  %.promoted40 = phi i64 [ %.promoted4143, %.lr.ph ], [ %28, %19 ]
  %10 = load ptr, ptr %7, align 8, !tbaa !15
  %11 = getelementptr inbounds double, ptr %10, i64 %.0.ph44
  %12 = load double, ptr %11, align 8, !tbaa !16
  %13 = fcmp ult double %12, %1
  br i1 %13, label %.outer, label %14

14:                                               ; preds = %9
  %15 = load ptr, ptr %8, align 8, !tbaa !15
  %16 = getelementptr inbounds double, ptr %15, i64 %.0.ph44
  %17 = load double, ptr %16, align 8, !tbaa !16
  %18 = fcmp ult double %17, %2
  br i1 %18, label %.outer, label %19

19:                                               ; preds = %14
  %20 = getelementptr double, ptr %10, i64 %.promoted40
  %21 = getelementptr i8, ptr %20, i64 -8
  %22 = load double, ptr %21, align 8, !tbaa !16
  store double %22, ptr %11, align 8, !tbaa !16
  %23 = load ptr, ptr %8, align 8, !tbaa !15
  %24 = getelementptr double, ptr %23, i64 %.promoted40
  %25 = getelementptr i8, ptr %24, i64 -8
  %26 = load double, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds double, ptr %23, i64 %.0.ph44
  store double %26, ptr %27, align 8, !tbaa !16
  %28 = add nsw i64 %.promoted40, -1
  store i64 %28, ptr %5, align 8, !tbaa !5
  %29 = icmp slt i64 %.0.ph44, %28
  br i1 %29, label %9, label %.outer._crit_edge, !llvm.loop !17

.outer:                                           ; preds = %14, %9
  %30 = add nuw nsw i64 %.0.ph44, 1
  %31 = icmp slt i64 %30, %.promoted40
  br i1 %31, label %.lr.ph, label %.outer._crit_edge, !llvm.loop !17

.outer._crit_edge:                                ; preds = %.outer, %19, %4
  %.lcssa = phi i64 [ %.promoted39, %4 ], [ %28, %19 ], [ %.promoted40, %.outer ]
  %32 = add nsw i64 %.lcssa, 1
  %33 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_ZN11alglib_impl6rgrowvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %32, ptr noundef nonnull %33, ptr noundef %3)
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = add nsw i64 %34, 1
  %36 = getelementptr inbounds i8, ptr %0, i64 104
  tail call void @_ZN11alglib_impl6rgrowvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %35, ptr noundef nonnull %36, ptr noundef %3)
  %37 = getelementptr inbounds i8, ptr %0, i64 96
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %38, i64 %39
  store double %1, ptr %40, align 8, !tbaa !16
  %41 = getelementptr inbounds i8, ptr %0, i64 160
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = getelementptr inbounds double, ptr %42, i64 %39
  store double %2, ptr %43, align 8, !tbaa !16
  %44 = add nsw i64 %39, 1
  store i64 %44, ptr %5, align 8, !tbaa !5
  ret void
}

attributes #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 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, !10, i64 8}
!6 = !{!"_ZTSN11alglib_impl9nlpfilterE", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !12, i64 104}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN11alglib_impl9ae_vectorE", !10, i64 0, !10, i64 8, !11, i64 16, !13, i64 24, !8, i64 56}
!13 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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