; 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::kdtreerequestbuffer" = type { %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", i64, double, i8, double, i64, %"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", double }
%"struct.alglib_impl::ae_vector" = type { 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 }
%"struct.alglib_impl::ae_matrix" = type { i64, i64, i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon.1 }
%union.anon.1 = type { ptr }
%"struct.alglib_impl::kdtree" = type { i64, i64, i64, i64, %"struct.alglib_impl::ae_matrix", %"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", %"struct.alglib_impl::kdtreerequestbuffer", i64 }

; 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 uwtable
define dso_local void @_ZN11alglib_impl22kdtreetsqueryresultsxyEPNS_6kdtreeEPNS_19kdtreerequestbufferEPNS_9ae_matrixEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %12, i32 0, i32 7
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

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

17:                                               ; preds = %4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %21, i32 0, i32 7
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = icmp slt i64 %20, %23
  br i1 %24, label %37, label %25

25:                                               ; preds = %17
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !18
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !19
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %32, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !21
  %35 = add nsw i64 %31, %34
  %36 = icmp slt i64 %28, %35
  br i1 %36, label %37, label %50

37:                                               ; preds = %25, %17
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %39, i32 0, i32 7
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !19
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %45, i32 0, i32 2
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = add nsw i64 %44, %47
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN11alglib_impl20ae_matrix_set_lengthEPNS_9ae_matrixEllPNS_8ae_stateE(ptr noundef %38, i64 noundef %41, i64 noundef %48, ptr noundef %49)
  br label %50

50:                                               ; preds = %37, %25
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %51, i32 0, i32 7
  %53 = load i64, ptr %52, align 8, !tbaa !9
  store i64 %53, ptr %10, align 8, !tbaa !22
  store i64 0, ptr %9, align 8, !tbaa !22
  br label %54

54:                                               ; preds = %93, %50
  %55 = load i64, ptr %9, align 8, !tbaa !22
  %56 = load i64, ptr %10, align 8, !tbaa !22
  %57 = sub nsw i64 %56, 1
  %58 = icmp sle i64 %55, %57
  br i1 %58, label %59, label %96

59:                                               ; preds = %54
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %60, i32 0, i32 6
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = load i64, ptr %9, align 8, !tbaa !22
  %64 = getelementptr inbounds ptr, ptr %62, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = getelementptr inbounds double, ptr %65, i64 0
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %67, i32 0, i32 4
  %69 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %68, i32 0, i32 6
  %70 = load ptr, ptr %69, align 8, !tbaa !23
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %71, i32 0, i32 8
  %73 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !23
  %75 = load i64, ptr %9, align 8, !tbaa !22
  %76 = getelementptr inbounds i64, ptr %74, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !22
  %78 = getelementptr inbounds ptr, ptr %70, i64 %77
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %80, i32 0, i32 1
  %82 = load i64, ptr %81, align 8, !tbaa !19
  %83 = getelementptr inbounds double, ptr %79, i64 %82
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %84, i32 0, i32 1
  %86 = load i64, ptr %85, align 8, !tbaa !19
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %87, i32 0, i32 2
  %89 = load i64, ptr %88, align 8, !tbaa !21
  %90 = add nsw i64 %86, %89
  %91 = sub nsw i64 %90, 1
  %92 = call noundef i64 @_ZN11alglib_impl8ae_v_lenEll(i64 noundef 0, i64 noundef %91)
  call void @_ZN11alglib_impl9ae_v_moveEPdlPKdll(ptr noundef %66, i64 noundef 1, ptr noundef %83, i64 noundef 1, i64 noundef %92)
  br label %93

93:                                               ; preds = %59
  %94 = load i64, ptr %9, align 8, !tbaa !22
  %95 = add nsw i64 %94, 1
  store i64 %95, ptr %9, align 8, !tbaa !22
  br label %54, !llvm.loop !24

96:                                               ; preds = %54
  store i32 0, ptr %11, align 4
  br label %97

97:                                               ; preds = %96, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %98 = load i32, ptr %11, 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
}

declare void @_ZN11alglib_impl9ae_v_moveEPdlPKdll(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef) #2

declare noundef i64 @_ZN11alglib_impl8ae_v_lenEll(i64 noundef, i64 noundef) #2

declare void @_ZN11alglib_impl20ae_matrix_set_lengthEPNS_9ae_matrixEllPNS_8ae_stateE(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 224}
!10 = !{!"_ZTSN11alglib_impl19kdtreerequestbufferE", !11, i64 0, !11, i64 64, !11, i64 128, !12, i64 192, !15, i64 200, !13, i64 208, !15, i64 216, !12, i64 224, !11, i64 232, !11, i64 296, !11, i64 360, !11, i64 424, !11, i64 488, !15, i64 552}
!11 = !{!"_ZTSN11alglib_impl9ae_vectorE", !12, i64 0, !12, i64 8, !13, i64 16, !14, i64 24, !7, i64 56}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"double", !7, i64 0}
!16 = !{!17, !12, i64 0}
!17 = !{!"_ZTSN11alglib_impl9ae_matrixE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !13, i64 32, !14, i64 40, !7, i64 72}
!18 = !{!17, !12, i64 8}
!19 = !{!20, !12, i64 8}
!20 = !{!"_ZTSN11alglib_impl6kdtreeE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !17, i64 32, !11, i64 112, !11, i64 176, !11, i64 240, !11, i64 304, !11, i64 368, !10, i64 432, !12, i64 992}
!21 = !{!20, !12, i64 16}
!22 = !{!12, !12, i64 0}
!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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl22kdtreetsqueryresultsxyEPNS_6kdtreeEPNS_19kdtreerequestbufferEPNS_9ae_matrixEPNS_8ae_stateE(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 224
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %4
  %9 = load i64, ptr %2, align 8, !tbaa !15
  %10 = icmp slt i64 %9, %6
  br i1 %10, label %._crit_edge, label %11

._crit_edge:                                      ; preds = %8
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !17
  %.phi.trans.insert25 = getelementptr inbounds i8, ptr %0, i64 16
  %.pre26 = load i64, ptr %.phi.trans.insert25, align 8, !tbaa !19
  %.pre28 = add nsw i64 %.pre26, %.pre
  br label %20

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !20
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !19
  %18 = add nsw i64 %17, %15
  %19 = icmp slt i64 %13, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %._crit_edge, %11
  %.pre-phi = phi i64 [ %.pre28, %._crit_edge ], [ %18, %11 ]
  tail call void @_ZN11alglib_impl20ae_matrix_set_lengthEPNS_9ae_matrixEllPNS_8ae_stateE(ptr noundef nonnull %2, i64 noundef %6, i64 noundef %.pre-phi, ptr noundef %3)
  %.pre27 = load i64, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %20, %11
  %22 = phi i64 [ %.pre27, %20 ], [ %6, %11 ]
  %.not.not23 = icmp sgt i64 %22, 0
  br i1 %.not.not23, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %21
  %23 = getelementptr inbounds i8, ptr %2, i64 72
  %24 = getelementptr inbounds i8, ptr %0, i64 104
  %25 = getelementptr inbounds i8, ptr %1, i64 288
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  br label %28

28:                                               ; preds = %.lr.ph, %28
  %.024 = phi i64 [ 0, %.lr.ph ], [ %44, %28 ]
  %29 = load ptr, ptr %23, align 8, !tbaa !21
  %30 = getelementptr inbounds ptr, ptr %29, i64 %.024
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = load ptr, ptr %24, align 8, !tbaa !21
  %33 = load ptr, ptr %25, align 8, !tbaa !21
  %34 = getelementptr inbounds i64, ptr %33, i64 %.024
  %35 = load i64, ptr %34, align 8, !tbaa !23
  %36 = getelementptr inbounds ptr, ptr %32, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !22
  %38 = load i64, ptr %26, align 8, !tbaa !17
  %39 = getelementptr inbounds double, ptr %37, i64 %38
  %40 = load i64, ptr %27, align 8, !tbaa !19
  %41 = add i64 %38, -1
  %42 = add i64 %41, %40
  %43 = tail call noundef i64 @_ZN11alglib_impl8ae_v_lenEll(i64 noundef 0, i64 noundef %42)
  tail call void @_ZN11alglib_impl9ae_v_moveEPdlPKdll(ptr noundef %31, i64 noundef 1, ptr noundef %39, i64 noundef 1, i64 noundef %43)
  %44 = add nuw nsw i64 %.024, 1
  %exitcond.not = icmp eq i64 %44, %22
  br i1 %exitcond.not, label %.loopexit, label %28, !llvm.loop !24

.loopexit:                                        ; preds = %28, %21, %4
  ret void
}

declare void @_ZN11alglib_impl9ae_v_moveEPdlPKdll(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare noundef i64 @_ZN11alglib_impl8ae_v_lenEll(i64 noundef, i64 noundef) local_unnamed_addr #1

declare void @_ZN11alglib_impl20ae_matrix_set_lengthEPNS_9ae_matrixEllPNS_8ae_stateE(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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, !8, i64 224}
!6 = !{!"_ZTSN11alglib_impl19kdtreerequestbufferE", !7, i64 0, !7, i64 64, !7, i64 128, !8, i64 192, !14, i64 200, !11, i64 208, !14, i64 216, !8, i64 224, !7, i64 232, !7, i64 296, !7, i64 360, !7, i64 424, !7, i64 488, !14, i64 552}
!7 = !{!"_ZTSN11alglib_impl9ae_vectorE", !8, i64 0, !8, i64 8, !11, i64 16, !12, i64 24, !9, i64 56}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"double", !9, i64 0}
!15 = !{!16, !8, i64 0}
!16 = !{!"_ZTSN11alglib_impl9ae_matrixE", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !11, i64 32, !12, i64 40, !9, i64 72}
!17 = !{!18, !8, i64 8}
!18 = !{!"_ZTSN11alglib_impl6kdtreeE", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !16, i64 32, !7, i64 112, !7, i64 176, !7, i64 240, !7, i64 304, !7, i64 368, !6, i64 432, !8, i64 992}
!19 = !{!18, !8, i64 16}
!20 = !{!16, !8, i64 8}
!21 = !{!9, !9, i64 0}
!22 = !{!13, !13, i64 0}
!23 = !{!8, !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass