; LLVM IR from MaverickPeter/MR_SLAM :: Mapping/src/global_manager/src/kdtree.ll (Z17kdtree_knn_resultP6kdtree)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl" }
%"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl" = type { %"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl_data" }
%"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.kdresult = type { float, i64 }
%struct.kdtree = type { ptr, i64, i64, ptr, ptr, ptr, ptr, ptr, %struct.knn_list, i32, i32 }
%struct.knn_list = type { ptr, float, ptr, ptr }
%struct.kdnode = type { i64, ptr, ptr, ptr, i32 }

; 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 @_Z17kdtree_knn_resultP6kdtree(ptr dead_on_unwind noalias writable sret(%"class.std::vector") align 8 %0, ptr noundef %1) #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca %struct.kdresult, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i1 false, ptr %6, align 1
  call void @_ZNSt6vectorI8kdresultSaIS0_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.kdtree, ptr %11, i32 0, i32 8
  %13 = getelementptr inbounds %struct.knn_list, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %58, %2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.kdtree, ptr %17, i32 0, i32 8
  %19 = icmp ne ptr %16, %18
  br i1 %19, label %20, label %62

20:                                               ; preds = %15
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %55, %20
  %22 = load i32, ptr %5, align 4, !tbaa !15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.kdtree, ptr %23, i32 0, i32 9
  %25 = load i32, ptr %24, align 8, !tbaa !16
  %26 = icmp slt i32 %22, %25
  br i1 %26, label %27, label %58

27:                                               ; preds = %21
  %28 = load i32, ptr %5, align 4, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.kdtree, ptr %29, i32 0, i32 9
  %31 = load i32, ptr %30, align 8, !tbaa !16
  %32 = sub nsw i32 %31, 1
  %33 = icmp eq i32 %28, %32
  br i1 %33, label %34, label %53

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.knn_list, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct.kdnode, ptr %37, i32 0, i32 0
  %39 = load i64, ptr %38, align 8, !tbaa !18
  %40 = getelementptr inbounds %struct.kdresult, ptr %8, i32 0, i32 1
  store i64 %39, ptr %40, align 8, !tbaa !20
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.knn_list, ptr %41, i32 0, i32 1
  %43 = load float, ptr %42, align 8, !tbaa !22
  %44 = invoke noundef float @_ZSt4sqrtf(float noundef %43)
          to label %45 unwind label %49

45:                                               ; preds = %34
  %46 = getelementptr inbounds %struct.kdresult, ptr %8, i32 0, i32 0
  store float %44, ptr %46, align 8, !tbaa !23
  %47 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI8kdresultSaIS0_EE12emplace_backIJRS0_EEES4_DpOT_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(16) %8)
          to label %48 unwind label %49

48:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %54

49:                                               ; preds = %45, %34
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %9, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @_ZNSt6vectorI8kdresultSaIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %66

53:                                               ; preds = %27
  br label %54

54:                                               ; preds = %53, %48
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %5, align 4, !tbaa !15
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !15
  br label %21, !llvm.loop !24

58:                                               ; preds = %21
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.knn_list, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !26
  store ptr %61, ptr %7, align 8, !tbaa !5
  br label %15, !llvm.loop !27

62:                                               ; preds = %15
  store i1 true, ptr %6, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %63 = load i1, ptr %6, align 1
  br i1 %63, label %65, label %64

64:                                               ; preds = %62
  call void @_ZNSt6vectorI8kdresultSaIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  br label %65

65:                                               ; preds = %64, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void

66:                                               ; preds = %49
  %67 = load ptr, ptr %9, align 8
  %68 = load i32, ptr %10, align 4
  %69 = insertvalue { ptr, i32 } poison, ptr %67, 0
  %70 = insertvalue { ptr, i32 } %69, i32 %68, 1
  resume { ptr, i32 } %70
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorI8kdresultSaIS0_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) #3

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI8kdresultSaIS0_EE12emplace_backIJRS0_EEES4_DpOT_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorI8kdresultSaIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 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 = { 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 #3 = { inlinehint 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 #4 = { 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, !6, i64 88}
!10 = !{!"_ZTS6kdtree", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !12, i64 64, !14, i64 96, !14, i64 100}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTS8knn_list", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"float", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!10, !14, i64 96}
!17 = !{!12, !6, i64 0}
!18 = !{!19, !11, i64 0}
!19 = !{!"_ZTS6kdnode", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!20 = !{!21, !11, i64 8}
!21 = !{!"_ZTS8kdresult", !13, i64 0, !11, i64 8}
!22 = !{!12, !13, i64 8}
!23 = !{!21, !13, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!12, !6, i64 24}
!27 = distinct !{!27, !25}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl" }
%"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl" = type { %"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl_data" }
%"struct.std::_Vector_base<kdresult, std::allocator<kdresult>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.kdresult = type { float, i64 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @_Z17kdtree_knn_resultP6kdtree(ptr dead_on_unwind noalias nonnull writable sret(%"class.std::vector") align 8 %0, ptr noundef readonly %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.kdresult, align 8
  tail call void @_ZNSt6vectorI8kdresultSaIS0_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %4 = getelementptr inbounds i8, ptr %1, i64 64
  %5 = getelementptr inbounds i8, ptr %1, i64 88
  %.01316 = load ptr, ptr %5, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.01316, %4
  br i1 %.not17, label %._crit_edge19, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 96
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  %8 = load i32, ptr %6, align 8, !tbaa !11
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader, label %._crit_edge19

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %10 = phi i32 [ %32, %._crit_edge ], [ %8, %.preheader.lr.ph ]
  %11 = phi i32 [ %33, %._crit_edge ], [ %8, %.preheader.lr.ph ]
  %.01318 = phi ptr [ %.013, %._crit_edge ], [ %.01316, %.preheader.lr.ph ]
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %.01318, i64 8
  br label %14

14:                                               ; preds = %.lr.ph, %28
  %15 = phi i32 [ %10, %.lr.ph ], [ %29, %28 ]
  %16 = phi i32 [ %11, %.lr.ph ], [ %29, %28 ]
  %.015 = phi i32 [ 0, %.lr.ph ], [ %30, %28 ]
  %17 = add nsw i32 %16, -1
  %18 = icmp eq i32 %.015, %17
  br i1 %18, label %19, label %28

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %20 = load ptr, ptr %.01318, align 8, !tbaa !15
  %21 = load i64, ptr %20, align 8, !tbaa !16
  store i64 %21, ptr %7, align 8, !tbaa !18
  %22 = load float, ptr %13, align 8, !tbaa !20
  %23 = call noundef float @_ZSt4sqrtf(float noundef %22)
  store float %23, ptr %3, align 8, !tbaa !21
  %24 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI8kdresultSaIS0_EE12emplace_backIJRS0_EEES4_DpOT_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(16) %3)
          to label %25 unwind label %26

25:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  %.pre = load i32, ptr %6, align 8, !tbaa !11
  br label %28

26:                                               ; preds = %19
  %27 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @_ZNSt6vectorI8kdresultSaIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  resume { ptr, i32 } %27

28:                                               ; preds = %25, %14
  %29 = phi i32 [ %.pre, %25 ], [ %15, %14 ]
  %30 = add nuw nsw i32 %.015, 1
  %31 = icmp slt i32 %30, %29
  br i1 %31, label %14, label %._crit_edge, !llvm.loop !22

._crit_edge:                                      ; preds = %28, %.preheader
  %32 = phi i32 [ %10, %.preheader ], [ %29, %28 ]
  %33 = phi i32 [ %11, %.preheader ], [ %29, %28 ]
  %34 = getelementptr inbounds i8, ptr %.01318, i64 24
  %.013 = load ptr, ptr %34, align 8, !tbaa !5
  %.not = icmp eq ptr %.013, %4
  br i1 %.not, label %._crit_edge19, label %.preheader, !llvm.loop !24

._crit_edge19:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorI8kdresultSaIS0_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) local_unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI8kdresultSaIS0_EE12emplace_backIJRS0_EEES4_DpOT_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorI8kdresultSaIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

attributes #0 = { mustprogress 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 = { 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 #3 = { inlinehint 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 #4 = { 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, !7, i64 24}
!6 = !{!"_ZTS8knn_list", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!12, !14, i64 96}
!12 = !{!"_ZTS6kdtree", !7, i64 0, !13, i64 8, !13, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !6, i64 64, !14, i64 96, !14, i64 100}
!13 = !{!"long", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !13, i64 0}
!17 = !{!"_ZTS6kdnode", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !14, i64 32}
!18 = !{!19, !13, i64 8}
!19 = !{!"_ZTS8kdresult", !10, i64 0, !13, i64 8}
!20 = !{!6, !10, i64 8}
!21 = !{!19, !10, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23, !25}
!25 = !{!"llvm.loop.unswitch.partial.disable"}


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