; 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::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 }
%"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 }

; 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_impl24kdtreetsqueryresultstagsEPNS_6kdtreeEPNS_19kdtreerequestbufferEPNS_9ae_vectorEPNS_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 %63

17:                                               ; preds = %4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.alglib_impl::ae_vector", 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 %25, label %31

25:                                               ; preds = %17
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %27, i32 0, i32 7
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN11alglib_impl20ae_vector_set_lengthEPNS_9ae_vectorElPNS_8ae_stateE(ptr noundef %26, i64 noundef %29, ptr noundef %30)
  br label %31

31:                                               ; preds = %25, %17
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %32, i32 0, i32 7
  %34 = load i64, ptr %33, align 8, !tbaa !9
  store i64 %34, ptr %10, align 8, !tbaa !17
  store i64 0, ptr %9, align 8, !tbaa !17
  br label %35

35:                                               ; preds = %59, %31
  %36 = load i64, ptr %9, align 8, !tbaa !17
  %37 = load i64, ptr %10, align 8, !tbaa !17
  %38 = sub nsw i64 %37, 1
  %39 = icmp sle i64 %36, %38
  br i1 %39, label %40, label %62

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.alglib_impl::kdtree", ptr %41, i32 0, i32 5
  %43 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.alglib_impl::kdtreerequestbuffer", ptr %45, i32 0, i32 8
  %47 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = load i64, ptr %9, align 8, !tbaa !17
  %50 = getelementptr inbounds i64, ptr %48, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !17
  %52 = getelementptr inbounds i64, ptr %44, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !17
  %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 !18
  %57 = load i64, ptr %9, align 8, !tbaa !17
  %58 = getelementptr inbounds i64, ptr %56, i64 %57
  store i64 %53, ptr %58, align 8, !tbaa !17
  br label %59

59:                                               ; preds = %40
  %60 = load i64, ptr %9, align 8, !tbaa !17
  %61 = add nsw i64 %60, 1
  store i64 %61, ptr %9, align 8, !tbaa !17
  br label %35, !llvm.loop !19

62:                                               ; preds = %35
  store i32 0, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %64 = load i32, ptr %11, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
    i32 1, label %65
  ]

65:                                               ; preds = %63, %63
  ret void

66:                                               ; preds = %63
  unreachable
}

declare void @_ZN11alglib_impl20ae_vector_set_lengthEPNS_9ae_vectorElPNS_8ae_stateE(ptr 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 = !{!11, !12, i64 0}
!17 = !{!12, !12, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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_impl24kdtreetsqueryresultstagsEPNS_6kdtreeEPNS_19kdtreerequestbufferEPNS_9ae_vectorEPNS_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 %11, label %12

11:                                               ; preds = %8
  tail call void @_ZN11alglib_impl20ae_vector_set_lengthEPNS_9ae_vectorElPNS_8ae_stateE(ptr noundef nonnull %2, i64 noundef %6, ptr noundef %3)
  %.pre = load i64, ptr %5, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %11, %8
  %13 = phi i64 [ %.pre, %11 ], [ %6, %8 ]
  %.not.not15 = icmp sgt i64 %13, 0
  br i1 %.not.not15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %12
  %14 = getelementptr inbounds i8, ptr %0, i64 168
  %15 = getelementptr inbounds i8, ptr %1, i64 288
  %16 = getelementptr inbounds i8, ptr %2, i64 56
  %xtraiter = and i64 %13, 1
  %17 = icmp eq i64 %13, 1
  br i1 %17, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %13, 9223372036854775806
  br label %18

18:                                               ; preds = %18, %.lr.ph.new
  %.016 = phi i64 [ 0, %.lr.ph.new ], [ %36, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %19 = load ptr, ptr %14, align 8, !tbaa !16
  %20 = load ptr, ptr %15, align 8, !tbaa !16
  %21 = getelementptr inbounds i64, ptr %20, i64 %.016
  %22 = load i64, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds i64, ptr %19, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = load ptr, ptr %16, align 8, !tbaa !16
  %26 = getelementptr inbounds i64, ptr %25, i64 %.016
  store i64 %24, ptr %26, align 8, !tbaa !17
  %27 = or disjoint i64 %.016, 1
  %28 = load ptr, ptr %14, align 8, !tbaa !16
  %29 = load ptr, ptr %15, align 8, !tbaa !16
  %30 = getelementptr inbounds i64, ptr %29, i64 %27
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = getelementptr inbounds i64, ptr %28, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %16, align 8, !tbaa !16
  %35 = getelementptr inbounds i64, ptr %34, i64 %27
  store i64 %33, ptr %35, align 8, !tbaa !17
  %36 = add nuw nsw i64 %.016, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %18, !llvm.loop !18

.loopexit.loopexit.unr-lcssa:                     ; preds = %18, %.lr.ph
  %.016.unr = phi i64 [ 0, %.lr.ph ], [ %36, %18 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %37 = load ptr, ptr %14, align 8, !tbaa !16
  %38 = load ptr, ptr %15, align 8, !tbaa !16
  %39 = getelementptr inbounds i64, ptr %38, i64 %.016.unr
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = getelementptr inbounds i64, ptr %37, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !17
  %43 = load ptr, ptr %16, align 8, !tbaa !16
  %44 = getelementptr inbounds i64, ptr %43, i64 %.016.unr
  store i64 %42, ptr %44, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %12, %4
  ret void
}

declare void @_ZN11alglib_impl20ae_vector_set_lengthEPNS_9ae_vectorElPNS_8ae_stateE(ptr 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 = !{!7, !8, i64 0}
!16 = !{!9, !9, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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