; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src (alglibmisc)

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

; 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: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN11alglib_impl11xdebugi2sumEPNS_9ae_matrixEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %39, %2
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = sub nsw i64 %12, 1
  %14 = icmp sle i64 %9, %13
  br i1 %14, label %15, label %42

15:                                               ; preds = %8
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %35, %15
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !15
  %21 = sub nsw i64 %20, 1
  %22 = icmp sle i64 %17, %21
  br i1 %22, label %23, label %38

23:                                               ; preds = %16
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %25, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %27, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds i64, ptr %30, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = add nsw i64 %24, %33
  store i64 %34, ptr %7, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %23
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %6, align 8, !tbaa !9
  br label %16, !llvm.loop !17

38:                                               ; preds = %16
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %5, align 8, !tbaa !9
  br label %8, !llvm.loop !19

42:                                               ; preds = %8
  %43 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %43
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !10, i64 0}
!12 = !{!"_ZTSN11alglib_impl9ae_matrixE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !14, i64 40, !7, i64 72}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!12, !10, i64 8}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZN11alglib_impl11xdebugi2sumEPNS_9ae_matrixEPNS_8ae_stateE(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %.not.not16 = icmp sgt i64 %3, 0
  br i1 %.not.not16, label %.preheader.lr.ph, label %._crit_edge19

.preheader.lr.ph:                                 ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !13
  %.not.not1213 = icmp sgt i64 %5, 0
  br i1 %.not.not1213, label %.preheader.lr.ph.split.us, label %._crit_edge19

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %min.iters.check = icmp ult i64 %5, 4
  %n.vec = and i64 %5, 9223372036854775804
  %cmp.n = icmp eq i64 %5, %n.vec
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %.018.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %.lcssa, %._crit_edge.us ]
  %.01117.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %21, %._crit_edge.us ]
  %8 = getelementptr inbounds ptr, ptr %7, i64 %.01117.us
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.us
  %10 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %.018.us, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %10, %vector.ph ], [ %13, %vector.body ]
  %vec.phi23 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %14, %vector.body ]
  %11 = getelementptr inbounds i64, ptr %9, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <2 x i64>, ptr %11, align 8, !tbaa !16
  %wide.load24 = load <2 x i64>, ptr %12, align 8, !tbaa !16
  %13 = add <2 x i64> %wide.load, %vec.phi
  %14 = add <2 x i64> %wide.load24, %vec.phi23
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %14, %13
  %16 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %.115.us.ph = phi i64 [ %.018.us, %.preheader.us ], [ %16, %middle.block ]
  %.01014.us.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.115.us = phi i64 [ %19, %scalar.ph ], [ %.115.us.ph, %scalar.ph.preheader ]
  %.01014.us = phi i64 [ %20, %scalar.ph ], [ %.01014.us.ph, %scalar.ph.preheader ]
  %17 = getelementptr inbounds i64, ptr %9, i64 %.01014.us
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = add nsw i64 %18, %.115.us
  %20 = add nuw nsw i64 %.01014.us, 1
  %exitcond.not = icmp eq i64 %20, %5
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !21

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i64 [ %16, %middle.block ], [ %19, %scalar.ph ]
  %21 = add nuw nsw i64 %.01117.us, 1
  %exitcond22.not = icmp eq i64 %21, %3
  br i1 %exitcond22.not, label %._crit_edge19, label %.preheader.us, !llvm.loop !22

._crit_edge19:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %2
  %.0.lcssa = phi i64 [ 0, %2 ], [ 0, %.preheader.lr.ph ], [ %.lcssa, %._crit_edge.us ]
  ret i64 %.0.lcssa
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN11alglib_impl9ae_matrixE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !8, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!8, !8, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18, !20, !19}
!22 = distinct !{!22, !18}


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