; 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_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%union.anon = 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 void @_ZN11alglib_impl12tagheappushiEPNS_9ae_vectorES1_PldlPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3, i64 noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store double %3, ptr %10, align 8, !tbaa !9
  store i64 %4, ptr %11, align 8, !tbaa !11
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %6
  store i32 1, ptr %16, align 4
  br label %97

21:                                               ; preds = %6
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %40

25:                                               ; preds = %21
  %26 = load double, ptr %10, align 8, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds double, ptr %29, i64 0
  store double %26, ptr %30, align 8, !tbaa !9
  %31 = load i64, ptr %11, align 8, !tbaa !11
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = getelementptr inbounds i64, ptr %34, i64 0
  store i64 %31, ptr %35, align 8, !tbaa !11
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = add nsw i64 %37, 1
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %38, ptr %39, align 8, !tbaa !11
  store i32 1, ptr %16, align 4
  br label %97

40:                                               ; preds = %21
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i64, ptr %41, align 8, !tbaa !11
  store i64 %42, ptr %13, align 8, !tbaa !11
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = add nsw i64 %44, 1
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %45, ptr %46, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %83, %40
  %48 = load i64, ptr %13, align 8, !tbaa !11
  %49 = icmp sgt i64 %48, 0
  br i1 %49, label %50, label %84

50:                                               ; preds = %47
  %51 = load i64, ptr %13, align 8, !tbaa !11
  %52 = sub nsw i64 %51, 1
  %53 = sdiv i64 %52, 2
  store i64 %53, ptr %14, align 8, !tbaa !11
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = load i64, ptr %14, align 8, !tbaa !11
  %58 = getelementptr inbounds double, ptr %56, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !9
  store double %59, ptr %15, align 8, !tbaa !9
  %60 = load double, ptr %15, align 8, !tbaa !9
  %61 = load double, ptr %10, align 8, !tbaa !9
  %62 = fcmp olt double %60, %61
  br i1 %62, label %63, label %82

63:                                               ; preds = %50
  %64 = load double, ptr %15, align 8, !tbaa !9
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load i64, ptr %13, align 8, !tbaa !11
  %69 = getelementptr inbounds double, ptr %67, i64 %68
  store double %64, ptr %69, align 8, !tbaa !9
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %70, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load i64, ptr %14, align 8, !tbaa !11
  %74 = getelementptr inbounds i64, ptr %72, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !11
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %76, i32 0, i32 4
  %78 = load ptr, ptr %77, align 8, !tbaa !13
  %79 = load i64, ptr %13, align 8, !tbaa !11
  %80 = getelementptr inbounds i64, ptr %78, i64 %79
  store i64 %75, ptr %80, align 8, !tbaa !11
  %81 = load i64, ptr %14, align 8, !tbaa !11
  store i64 %81, ptr %13, align 8, !tbaa !11
  br label %83

82:                                               ; preds = %50
  br label %84

83:                                               ; preds = %63
  br label %47, !llvm.loop !14

84:                                               ; preds = %82, %47
  %85 = load double, ptr %10, align 8, !tbaa !9
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %86, i32 0, i32 4
  %88 = load ptr, ptr %87, align 8, !tbaa !13
  %89 = load i64, ptr %13, align 8, !tbaa !11
  %90 = getelementptr inbounds double, ptr %88, i64 %89
  store double %85, ptr %90, align 8, !tbaa !9
  %91 = load i64, ptr %11, align 8, !tbaa !11
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %92, i32 0, i32 4
  %94 = load ptr, ptr %93, align 8, !tbaa !13
  %95 = load i64, ptr %13, align 8, !tbaa !11
  %96 = getelementptr inbounds i64, ptr %94, i64 %95
  store i64 %91, ptr %96, align 8, !tbaa !11
  store i32 0, ptr %16, align 4
  br label %97

97:                                               ; preds = %84, %25, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %98 = load i32, ptr %16, align 4
  switch i32 %98, label %100 [
    i32 0, label %99
    i32 1, label %99
  ]

99:                                               ; preds = %97, %97
  ret void

100:                                              ; preds = %97
  unreachable
}

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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN11alglib_impl12tagheappushiEPNS_9ae_vectorES1_PldlPNS_8ae_stateE(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, double noundef %3, i64 noundef %4, ptr nocapture noundef readnone %5) local_unnamed_addr #0 {
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = icmp slt i64 %7, 0
  br i1 %8, label %39, label %9

9:                                                ; preds = %6
  %10 = icmp eq i64 %7, 0
  %11 = getelementptr inbounds i8, ptr %1, i64 56
  br i1 %10, label %12, label %.lr.ph

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store double %3, ptr %14, align 8, !tbaa !10
  %15 = load ptr, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %15, align 8, !tbaa !5
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr %2, align 8, !tbaa !5
  br label %39

.lr.ph:                                           ; preds = %9
  %18 = add nuw nsw i64 %7, 1
  store i64 %18, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  br label %20

20:                                               ; preds = %.lr.ph, %27
  %.032 = phi i64 [ %7, %.lr.ph ], [ %22, %27 ]
  %21 = add nsw i64 %.032, -1
  %22 = lshr i64 %21, 1
  %23 = load ptr, ptr %19, align 8, !tbaa !9
  %24 = getelementptr inbounds double, ptr %23, i64 %22
  %25 = load double, ptr %24, align 8, !tbaa !10
  %26 = fcmp olt double %25, %3
  br i1 %26, label %27, label %._crit_edge

27:                                               ; preds = %20
  %28 = getelementptr inbounds double, ptr %23, i64 %.032
  store double %25, ptr %28, align 8, !tbaa !10
  %29 = load ptr, ptr %11, align 8, !tbaa !9
  %30 = getelementptr inbounds i64, ptr %29, i64 %22
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds i64, ptr %29, i64 %.032
  store i64 %31, ptr %32, align 8, !tbaa !5
  %.not = icmp ult i64 %21, 2
  br i1 %.not, label %._crit_edge, label %20, !llvm.loop !12

._crit_edge:                                      ; preds = %27, %20
  %.0.lcssa.ph = phi i64 [ %22, %27 ], [ %.032, %20 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 56
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds double, ptr %34, i64 %.0.lcssa.ph
  store double %3, ptr %35, align 8, !tbaa !10
  %36 = getelementptr inbounds i8, ptr %1, i64 56
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds i64, ptr %37, i64 %.0.lcssa.ph
  store i64 %4, ptr %38, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %6, %._crit_edge, %12
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass