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

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

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

12:                                               ; preds = %42, %4
  %13 = load i64, ptr %9, align 8, !tbaa !9
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = sub nsw i64 %14, 1
  %16 = icmp sle i64 %13, %15
  br i1 %16, label %17, label %45

17:                                               ; preds = %12
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %38, %17
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = sub nsw i64 %20, 1
  %22 = icmp sle i64 %19, %21
  br i1 %22, label %23, label %41

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %26, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = getelementptr inbounds double, ptr %29, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !12
  %33 = fcmp oeq double %32, 0.000000e+00
  br i1 %33, label %37, label %34

34:                                               ; preds = %23
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %11, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %34, %23
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %10, align 8, !tbaa !9
  br label %18, !llvm.loop !14

41:                                               ; preds = %18
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %9, align 8, !tbaa !9
  br label %12, !llvm.loop !16

45:                                               ; preds = %12
  %46 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %46
}

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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZN11alglib_impl8countnz2EPNS_9ae_matrixEllPNS_8ae_stateE(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %.not.not16 = icmp sgt i64 %1, 0
  %.not.not1213 = icmp sgt i64 %2, 0
  %or.cond = and i1 %.not.not16, %.not.not1213
  br i1 %or.cond, label %.preheader.lr.ph.split.us, label %._crit_edge19

.preheader.lr.ph.split.us:                        ; preds = %4
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %min.iters.check = icmp ult i64 %2, 4
  %n.vec = and i64 %2, 9223372036854775804
  %cmp.n = icmp eq i64 %n.vec, %2
  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 ], [ %.2.us.lcssa, %._crit_edge.us ]
  %.01117.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %25, %._crit_edge.us ]
  %7 = getelementptr inbounds ptr, ptr %6, i64 %.01117.us
  %8 = load ptr, ptr %7, align 8, !tbaa !8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.us
  %9 = 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> [ %9, %vector.ph ], [ %16, %vector.body ]
  %vec.phi23 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]
  %10 = getelementptr inbounds double, ptr %8, i64 %index
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %wide.load = load <2 x double>, ptr %10, align 8, !tbaa !10
  %wide.load24 = load <2 x double>, ptr %11, align 8, !tbaa !10
  %12 = fcmp une <2 x double> %wide.load, zeroinitializer
  %13 = fcmp une <2 x double> %wide.load24, zeroinitializer
  %14 = zext <2 x i1> %12 to <2 x i64>
  %15 = zext <2 x i1> %13 to <2 x i64>
  %16 = add <2 x i64> %vec.phi, %14
  %17 = add <2 x i64> %vec.phi23, %15
  %index.next = add nuw i64 %index, 4
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %17, %16
  %19 = 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 ], [ %19, %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 [ %.2.us, %scalar.ph ], [ %.115.us.ph, %scalar.ph.preheader ]
  %.01014.us = phi i64 [ %24, %scalar.ph ], [ %.01014.us.ph, %scalar.ph.preheader ]
  %20 = getelementptr inbounds double, ptr %8, i64 %.01014.us
  %21 = load double, ptr %20, align 8, !tbaa !10
  %22 = fcmp une double %21, 0.000000e+00
  %23 = zext i1 %22 to i64
  %.2.us = add nsw i64 %.115.us, %23
  %24 = add nuw nsw i64 %.01014.us, 1
  %exitcond.not = icmp eq i64 %24, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !16

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

._crit_edge19:                                    ; preds = %._crit_edge.us, %4
  %.0.lcssa = phi i64 [ 0, %4 ], [ %.2.us.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, !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, !14, !15}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !13, !15, !14}
!17 = distinct !{!17, !13}


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