; 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::xbfgshessian" = type { i64, %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", i64, i64, double, double, double, double, double, double, double, i64, double, double, %"struct.alglib_impl::ae_matrix", i64, double, double, double, i64, double, %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", i8, i64, %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", i8, %"struct.alglib_impl::ae_vector", i8, i64, %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", i8, %"struct.alglib_impl::ae_vector", double, double, i64, %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector" }
%"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 }

@.str.261 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.262 = external hidden unnamed_addr constant [52 x i8], align 1

; 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_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN11alglib_implL25optserv_resetlowrankmodelEPNS_12xbfgshessianEPNS_8ae_stateE(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl16hessiansetscalesEPNS_12xbfgshessianEPKNS_9ae_vectorEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  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
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %24, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 3
  br i1 %18, label %24, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = icmp eq i64 %22, 4
  br label %24

24:                                               ; preds = %19, %14, %3
  %25 = phi i1 [ true, %14 ], [ true, %3 ], [ %23, %19 ]
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %25, ptr noundef @.str.261, ptr noundef %26)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = icmp ne i64 %29, 4
  br i1 %30, label %31, label %32

31:                                               ; preds = %24
  store i32 1, ptr %9, align 4
  br label %72

32:                                               ; preds = %24
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %33, i32 0, i32 3
  %35 = load i64, ptr %34, align 8, !tbaa !17
  store i64 %35, ptr %8, align 8, !tbaa !18
  store i64 0, ptr %7, align 8, !tbaa !18
  br label %36

36:                                               ; preds = %52, %32
  %37 = load i64, ptr %7, align 8, !tbaa !18
  %38 = load i64, ptr %8, align 8, !tbaa !18
  %39 = sub nsw i64 %38, 1
  %40 = icmp sle i64 %37, %39
  br i1 %40, label %41, label %55

41:                                               ; preds = %36
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = load i64, ptr %7, align 8, !tbaa !18
  %46 = getelementptr inbounds double, ptr %44, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !20
  %48 = fcmp ole double %47, 0.000000e+00
  br i1 %48, label %49, label %51

49:                                               ; preds = %41
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext false, ptr noundef @.str.262, ptr noundef %50)
  br label %51

51:                                               ; preds = %49, %41
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %7, align 8, !tbaa !18
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %7, align 8, !tbaa !18
  br label %36, !llvm.loop !21

55:                                               ; preds = %36
  %56 = load i64, ptr %8, align 8, !tbaa !18
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl6rcopyvElPKNS_9ae_vectorEPS0_PNS_8ae_stateE(i64 noundef %56, ptr noundef %57, ptr noundef %59, ptr noundef %60)
  %61 = load i64, ptr %8, align 8, !tbaa !18
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl5rsetvEldPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %61, double noundef 1.000000e+00, ptr noundef %63, ptr noundef %64)
  %65 = load i64, ptr %8, align 8, !tbaa !18
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.alglib_impl::xbfgshessian", ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl10rmergedivvElPKNS_9ae_vectorEPS0_PNS_8ae_stateE(i64 noundef %65, ptr noundef %66, ptr noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_implL25optserv_resetlowrankmodelEPNS_12xbfgshessianEPNS_8ae_stateE(ptr noundef %70, ptr noundef %71)
  store i32 0, ptr %9, align 4
  br label %72

72:                                               ; preds = %55, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %73 = load i32, ptr %9, align 4
  switch i32 %73, label %75 [
    i32 0, label %74
    i32 1, label %74
  ]

74:                                               ; preds = %72, %72
  ret void

75:                                               ; preds = %72
  unreachable
}

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

declare void @_ZN11alglib_impl5rsetvEldPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef, double noundef, ptr noundef, ptr noundef) #1

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

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, !11, i64 0}
!10 = !{!"_ZTSN11alglib_impl12xbfgshessianE", !11, i64 0, !12, i64 8, !12, i64 72, !11, i64 136, !11, i64 144, !15, i64 152, !15, i64 160, !15, i64 168, !15, i64 176, !15, i64 184, !15, i64 192, !15, i64 200, !11, i64 208, !15, i64 216, !15, i64 224, !16, i64 232, !11, i64 312, !15, i64 320, !15, i64 328, !15, i64 336, !11, i64 344, !15, i64 352, !16, i64 360, !16, i64 440, !16, i64 520, !16, i64 600, !13, i64 680, !11, i64 688, !16, i64 696, !16, i64 776, !13, i64 856, !12, i64 864, !13, i64 928, !11, i64 936, !16, i64 944, !12, i64 1024, !12, i64 1088, !16, i64 1152, !12, i64 1232, !12, i64 1296, !13, i64 1360, !12, i64 1368, !15, i64 1432, !15, i64 1440, !11, i64 1448, !16, i64 1456, !12, i64 1536, !12, i64 1600, !12, i64 1664, !12, i64 1728, !12, i64 1792, !12, i64 1856, !16, i64 1920, !16, i64 2000, !16, i64 2080, !16, i64 2160, !16, i64 2240, !16, i64 2320, !16, i64 2400, !16, i64 2480, !12, i64 2560, !12, i64 2624, !16, i64 2688, !12, i64 2768, !16, i64 2832, !16, i64 2912, !16, i64 2992, !16, i64 3072, !16, i64 3152, !12, i64 3232, !12, i64 3296}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSN11alglib_impl9ae_vectorE", !11, i64 0, !11, i64 8, !13, i64 16, !14, i64 24, !7, i64 56}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTSN11alglib_impl9ae_matrixE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !13, i64 32, !14, i64 40, !7, i64 72}
!17 = !{!10, !11, i64 136}
!18 = !{!11, !11, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!15, !15, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str.261 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.262 = external hidden unnamed_addr constant [52 x i8], align 1

declare void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN11alglib_implL25optserv_resetlowrankmodelEPNS_12xbfgshessianEPNS_8ae_stateE(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl16hessiansetscalesEPNS_12xbfgshessianEPKNS_9ae_vectorEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
switch.edge:
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = icmp ult i64 %3, 5
  %switch.cast = trunc i64 %3 to i5
  %switch.downshift = lshr i5 -7, %switch.cast
  %switch.masked = trunc i5 %switch.downshift to i1
  %5 = select i1 %4, i1 %switch.masked, i1 false
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %5, ptr noundef nonnull @.str.261, ptr noundef %2)
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 4
  br i1 %.not, label %7, label %21

7:                                                ; preds = %switch.edge
  %8 = getelementptr inbounds i8, ptr %0, i64 136
  %9 = load i64, ptr %8, align 8, !tbaa !16
  %.not25.not26 = icmp sgt i64 %9, 0
  br i1 %.not25.not26, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  br label %11

11:                                               ; preds = %.lr.ph, %17
  %.027 = phi i64 [ 0, %.lr.ph ], [ %18, %17 ]
  %12 = load ptr, ptr %10, align 8, !tbaa !17
  %13 = getelementptr inbounds double, ptr %12, i64 %.027
  %14 = load double, ptr %13, align 8, !tbaa !18
  %15 = fcmp ugt double %14, 0.000000e+00
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext false, ptr noundef nonnull @.str.262, ptr noundef %2)
  br label %17

17:                                               ; preds = %11, %16
  %18 = add nuw nsw i64 %.027, 1
  %exitcond.not = icmp eq i64 %18, %9
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !19

._crit_edge:                                      ; preds = %17, %7
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN11alglib_impl6rcopyvElPKNS_9ae_vectorEPS0_PNS_8ae_stateE(i64 noundef %9, ptr noundef %1, ptr noundef nonnull %19, ptr noundef %2)
  %20 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @_ZN11alglib_impl5rsetvEldPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %9, double noundef 1.000000e+00, ptr noundef nonnull %20, ptr noundef %2)
  tail call void @_ZN11alglib_impl10rmergedivvElPKNS_9ae_vectorEPS0_PNS_8ae_stateE(i64 noundef %9, ptr noundef %1, ptr noundef nonnull %20, ptr noundef %2)
  tail call void @_ZN11alglib_implL25optserv_resetlowrankmodelEPNS_12xbfgshessianEPNS_8ae_stateE(ptr noundef nonnull %0, ptr noundef %2)
  br label %21

21:                                               ; preds = %switch.edge, %._crit_edge
  ret void
}

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

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

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

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, !7, i64 0}
!6 = !{!"_ZTSN11alglib_impl12xbfgshessianE", !7, i64 0, !10, i64 8, !10, i64 72, !7, i64 136, !7, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !14, i64 192, !14, i64 200, !7, i64 208, !14, i64 216, !14, i64 224, !15, i64 232, !7, i64 312, !14, i64 320, !14, i64 328, !14, i64 336, !7, i64 344, !14, i64 352, !15, i64 360, !15, i64 440, !15, i64 520, !15, i64 600, !11, i64 680, !7, i64 688, !15, i64 696, !15, i64 776, !11, i64 856, !10, i64 864, !11, i64 928, !7, i64 936, !15, i64 944, !10, i64 1024, !10, i64 1088, !15, i64 1152, !10, i64 1232, !10, i64 1296, !11, i64 1360, !10, i64 1368, !14, i64 1432, !14, i64 1440, !7, i64 1448, !15, i64 1456, !10, i64 1536, !10, i64 1600, !10, i64 1664, !10, i64 1728, !10, i64 1792, !10, i64 1856, !15, i64 1920, !15, i64 2000, !15, i64 2080, !15, i64 2160, !15, i64 2240, !15, i64 2320, !15, i64 2400, !15, i64 2480, !10, i64 2560, !10, i64 2624, !15, i64 2688, !10, i64 2768, !15, i64 2832, !15, i64 2912, !15, i64 2992, !15, i64 3072, !15, i64 3152, !10, i64 3232, !10, i64 3296}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN11alglib_impl9ae_vectorE", !7, i64 0, !7, i64 8, !11, i64 16, !12, i64 24, !8, i64 56}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = !{!"_ZTSN11alglib_impl9ae_matrixE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !8, i64 72}
!16 = !{!6, !7, i64 136}
!17 = !{!8, !8, i64 0}
!18 = !{!14, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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