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

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

@.str.82 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.83 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.84 = external hidden unnamed_addr constant [21 x i8], align 1
@_ZN11alglib_implL24sparse_desiredloadfactorE = external hidden global double, align 8
@_ZN11alglib_implL17sparse_additionalE = external hidden global i64, align 8

; 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
define dso_local void @_ZN11alglib_impl15sparsecreatebufElllPNS_12sparsematrixEPNS_8ae_stateE(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, 0
  %14 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %13, ptr noundef @.str.82, ptr noundef %14)
  %15 = load i64, ptr %7, align 8, !tbaa !5
  %16 = icmp sgt i64 %15, 0
  %17 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %16, ptr noundef @.str.83, ptr noundef %17)
  %18 = load i64, ptr %8, align 8, !tbaa !5
  %19 = icmp sge i64 %18, 0
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %19, ptr noundef @.str.84, ptr noundef %20)
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = sitofp i64 %21 to double
  %23 = load double, ptr @_ZN11alglib_implL24sparse_desiredloadfactorE, align 8, !tbaa !11
  %24 = fdiv double %22, %23
  %25 = load i64, ptr @_ZN11alglib_implL17sparse_additionalE, align 8, !tbaa !5
  %26 = sitofp i64 %25 to double
  %27 = fadd double %24, %26
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  %29 = call noundef i64 @_ZN11alglib_impl8ae_roundEdPNS_8ae_stateE(double noundef %27, ptr noundef %28)
  %30 = load ptr, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %30, i32 0, i32 10
  store i64 %29, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %32, i32 0, i32 10
  %34 = load i64, ptr %33, align 8, !tbaa !13
  %35 = load ptr, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_ZN11alglib_impl7rallocvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %34, ptr noundef %36, ptr noundef %37)
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !18
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %42, i32 0, i32 10
  store i64 %41, ptr %43, align 8, !tbaa !13
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %44, i32 0, i32 5
  store i64 0, ptr %45, align 8, !tbaa !19
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !9
  %48 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %47, i32 0, i32 6
  store i64 %46, ptr %48, align 8, !tbaa !20
  %49 = load i64, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %50, i32 0, i32 7
  store i64 %49, ptr %51, align 8, !tbaa !21
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %52, i32 0, i32 10
  %54 = load i64, ptr %53, align 8, !tbaa !13
  %55 = load ptr, ptr %9, align 8, !tbaa !9
  %56 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %55, i32 0, i32 8
  store i64 %54, ptr %56, align 8, !tbaa !22
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %57, i32 0, i32 10
  %59 = load i64, ptr %58, align 8, !tbaa !13
  %60 = mul nsw i64 2, %59
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_ZN11alglib_impl7iallocvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %60, ptr noundef %62, ptr noundef %63)
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %79, %5
  %65 = load i64, ptr %11, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !9
  %67 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %66, i32 0, i32 10
  %68 = load i64, ptr %67, align 8, !tbaa !13
  %69 = sub nsw i64 %68, 1
  %70 = icmp sle i64 %65, %69
  br i1 %70, label %71, label %82

71:                                               ; preds = %64
  %72 = load ptr, ptr %9, align 8, !tbaa !9
  %73 = getelementptr inbounds %"struct.alglib_impl::sparsematrix", ptr %72, i32 0, i32 1
  %74 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !23
  %76 = load i64, ptr %11, align 8, !tbaa !5
  %77 = mul nsw i64 2, %76
  %78 = getelementptr inbounds i64, ptr %75, i64 %77
  store i64 -1, ptr %78, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %71
  %80 = load i64, ptr %11, align 8, !tbaa !5
  %81 = add nsw i64 %80, 1
  store i64 %81, ptr %11, align 8, !tbaa !5
  br label %64, !llvm.loop !24

82:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

declare noundef i64 @_ZN11alglib_impl8ae_roundEdPNS_8ae_stateE(double noundef, ptr noundef) #1

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

declare void @_ZN11alglib_impl7iallocvElPNS_9ae_vectorEPNS_8ae_stateE(i64 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 360}
!14 = !{!"_ZTSN11alglib_impl12sparsematrixE", !15, i64 0, !15, i64 64, !15, i64 128, !15, i64 192, !15, i64 256, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360}
!15 = !{!"_ZTSN11alglib_impl9ae_vectorE", !6, i64 0, !6, i64 8, !16, i64 16, !17, i64 24, !7, i64 56}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!18 = !{!14, !6, i64 0}
!19 = !{!14, !6, i64 320}
!20 = !{!14, !6, i64 328}
!21 = !{!14, !6, i64 336}
!22 = !{!14, !6, i64 344}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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.82 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.83 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.84 = external hidden unnamed_addr constant [21 x i8], align 1
@_ZN11alglib_implL24sparse_desiredloadfactorE = external hidden local_unnamed_addr global double, align 8
@_ZN11alglib_implL17sparse_additionalE = external hidden local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl15sparsecreatebufElllPNS_12sparsematrixEPNS_8ae_stateE(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = icmp sgt i64 %0, 0
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %6, ptr noundef nonnull @.str.82, ptr noundef %4)
  %7 = icmp sgt i64 %1, 0
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %7, ptr noundef nonnull @.str.83, ptr noundef %4)
  %8 = icmp sgt i64 %2, -1
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %8, ptr noundef nonnull @.str.84, ptr noundef %4)
  %9 = sitofp i64 %2 to double
  %10 = load double, ptr @_ZN11alglib_implL24sparse_desiredloadfactorE, align 8, !tbaa !5
  %11 = fdiv double %9, %10
  %12 = load i64, ptr @_ZN11alglib_implL17sparse_additionalE, align 8, !tbaa !9
  %13 = sitofp i64 %12 to double
  %14 = fadd double %11, %13
  %15 = tail call noundef i64 @_ZN11alglib_impl8ae_roundEdPNS_8ae_stateE(double noundef %14, ptr noundef %4)
  %16 = getelementptr inbounds i8, ptr %3, i64 360
  store i64 %15, ptr %16, align 8, !tbaa !11
  tail call void @_ZN11alglib_impl7rallocvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %15, ptr noundef %3, ptr noundef %4)
  %17 = load i64, ptr %3, align 8, !tbaa !17
  store i64 %17, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %3, i64 320
  store i64 0, ptr %18, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %3, i64 328
  store i64 %0, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %3, i64 336
  store i64 %1, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %3, i64 344
  store i64 %17, ptr %21, align 8, !tbaa !21
  %22 = shl nsw i64 %17, 1
  %23 = getelementptr inbounds i8, ptr %3, i64 64
  tail call void @_ZN11alglib_impl7iallocvElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %22, ptr noundef nonnull %23, ptr noundef %4)
  %24 = load i64, ptr %16, align 8, !tbaa !11
  %.not.not28 = icmp sgt i64 %24, 0
  br i1 %.not.not28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %25 = getelementptr inbounds i8, ptr %3, i64 120
  br label %26

26:                                               ; preds = %.lr.ph, %26
  %.029 = phi i64 [ 0, %.lr.ph ], [ %29, %26 ]
  %27 = load ptr, ptr %25, align 8, !tbaa !22
  %.idx = shl nsw i64 %.029, 4
  %28 = getelementptr inbounds i8, ptr %27, i64 %.idx
  store i64 -1, ptr %28, align 8, !tbaa !9
  %29 = add nuw nsw i64 %.029, 1
  %30 = load i64, ptr %16, align 8, !tbaa !11
  %.not.not = icmp slt i64 %29, %30
  br i1 %.not.not, label %26, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %26, %5
  ret void
}

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

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

declare void @_ZN11alglib_impl7iallocvElPNS_9ae_vectorEPNS_8ae_stateE(i64 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, !6, i64 0}
!6 = !{!"double", !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, !10, i64 360}
!12 = !{!"_ZTSN11alglib_impl12sparsematrixE", !13, i64 0, !13, i64 64, !13, i64 128, !13, i64 192, !13, i64 256, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360}
!13 = !{!"_ZTSN11alglib_impl9ae_vectorE", !10, i64 0, !10, i64 8, !14, i64 16, !15, i64 24, !7, i64 56}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24}
!16 = !{!"any pointer", !7, i64 0}
!17 = !{!12, !10, i64 0}
!18 = !{!12, !10, i64 320}
!19 = !{!12, !10, i64 328}
!20 = !{!12, !10, i64 336}
!21 = !{!12, !10, i64 344}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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