; 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 double @_ZN11alglib_impl11xdebugr2sumEPNS_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 double, 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 double 0.000000e+00, ptr %7, align 8, !tbaa !9
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %8

8:                                                ; preds = %39, %2
  %9 = load i64, ptr %5, align 8, !tbaa !11
  %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 !13
  %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 !11
  br label %16

16:                                               ; preds = %35, %15
  %17 = load i64, ptr %6, align 8, !tbaa !11
  %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 !17
  %21 = sub nsw i64 %20, 1
  %22 = icmp sle i64 %17, %21
  br i1 %22, label %23, label %38

23:                                               ; preds = %16
  %24 = load double, 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 !18
  %28 = load i64, ptr %5, align 8, !tbaa !11
  %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 !11
  %32 = getelementptr inbounds double, ptr %30, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = fadd double %24, %33
  store double %34, ptr %7, align 8, !tbaa !9
  br label %35

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

38:                                               ; preds = %16
  br label %39

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

42:                                               ; preds = %8
  %43 = load double, 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 double %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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSN11alglib_impl9ae_matrixE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !15, i64 32, !16, i64 40, !7, i64 72}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!14, !12, i64 8}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 double @_ZN11alglib_impl11xdebugr2sumEPNS_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
  %xtraiter = and i64 %5, 7
  %8 = icmp ult i64 %5, 8
  %unroll_iter = and i64 %5, 9223372036854775800
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %.018.us = phi double [ 0.000000e+00, %.preheader.lr.ph.split.us ], [ %.lcssa, %._crit_edge.us ]
  %.01117.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %47, %._crit_edge.us ]
  %9 = getelementptr inbounds ptr, ptr %7, i64 %.01117.us
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.115.us = phi double [ %41, %.preheader.us.new ], [ %.018.us, %.preheader.us ]
  %.01014.us = phi i64 [ %42, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.7, %.preheader.us.new ], [ 0, %.preheader.us ]
  %11 = getelementptr inbounds double, ptr %10, i64 %.01014.us
  %12 = load double, ptr %11, align 8, !tbaa !16
  %13 = fadd double %.115.us, %12
  %14 = or disjoint i64 %.01014.us, 1
  %15 = getelementptr inbounds double, ptr %10, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !16
  %17 = fadd double %13, %16
  %18 = or disjoint i64 %.01014.us, 2
  %19 = getelementptr inbounds double, ptr %10, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !16
  %21 = fadd double %17, %20
  %22 = or disjoint i64 %.01014.us, 3
  %23 = getelementptr inbounds double, ptr %10, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !16
  %25 = fadd double %21, %24
  %26 = or disjoint i64 %.01014.us, 4
  %27 = getelementptr inbounds double, ptr %10, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !16
  %29 = fadd double %25, %28
  %30 = or disjoint i64 %.01014.us, 5
  %31 = getelementptr inbounds double, ptr %10, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = fadd double %29, %32
  %34 = or disjoint i64 %.01014.us, 6
  %35 = getelementptr inbounds double, ptr %10, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !16
  %37 = fadd double %33, %36
  %38 = or disjoint i64 %.01014.us, 7
  %39 = getelementptr inbounds double, ptr %10, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !16
  %41 = fadd double %37, %40
  %42 = add nuw nsw i64 %.01014.us, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !18

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa.ph = phi double [ poison, %.preheader.us ], [ %41, %.preheader.us.new ]
  %.115.us.unr = phi double [ %.018.us, %.preheader.us ], [ %41, %.preheader.us.new ]
  %.01014.us.unr = phi i64 [ 0, %.preheader.us ], [ %42, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.115.us.epil = phi double [ %45, %.epil.preheader ], [ %.115.us.unr, %._crit_edge.us.unr-lcssa ]
  %.01014.us.epil = phi i64 [ %46, %.epil.preheader ], [ %.01014.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %43 = getelementptr inbounds double, ptr %10, i64 %.01014.us.epil
  %44 = load double, ptr %43, align 8, !tbaa !16
  %45 = fadd double %.115.us.epil, %44
  %46 = add nuw nsw i64 %.01014.us.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !20

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %45, %.epil.preheader ]
  %47 = add nuw nsw i64 %.01117.us, 1
  %exitcond22.not = icmp eq i64 %47, %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 double [ 0.000000e+00, %2 ], [ 0.000000e+00, %.preheader.lr.ph ], [ %.lcssa, %._crit_edge.us ]
  ret double %.0.lcssa
}

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

!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 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !19}


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