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

; 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.kdtree = type { ptr, i64, i64, ptr, ptr, ptr, ptr, ptr, %struct.knn_list, i32, i32 }
%struct.knn_list = type { ptr, float, ptr, ptr }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL18coord_passed_resetP6kdtree(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11kdtree_initi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %4 = call noalias ptr @malloc(i64 noundef 104) #5
  store ptr %4, ptr %3, align 8, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !9
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %77

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.kdtree, ptr %8, i32 0, i32 0
  store ptr null, ptr %9, align 8, !tbaa !11
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.kdtree, ptr %11, i32 0, i32 9
  store i32 %10, ptr %12, align 8, !tbaa !16
  %13 = load ptr, ptr %3, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.kdtree, ptr %13, i32 0, i32 1
  store i64 0, ptr %14, align 8, !tbaa !17
  %15 = load ptr, ptr %3, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.kdtree, ptr %15, i32 0, i32 2
  store i64 65536, ptr %16, align 8, !tbaa !18
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.kdtree, ptr %17, i32 0, i32 8
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.kdtree, ptr %19, i32 0, i32 8
  %21 = getelementptr inbounds %struct.knn_list, ptr %20, i32 0, i32 3
  store ptr %18, ptr %21, align 8, !tbaa !19
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.kdtree, ptr %22, i32 0, i32 8
  %24 = load ptr, ptr %3, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.kdtree, ptr %24, i32 0, i32 8
  %26 = getelementptr inbounds %struct.knn_list, ptr %25, i32 0, i32 2
  store ptr %23, ptr %26, align 8, !tbaa !20
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.kdtree, ptr %27, i32 0, i32 8
  %29 = getelementptr inbounds %struct.knn_list, ptr %28, i32 0, i32 0
  store ptr null, ptr %29, align 8, !tbaa !21
  %30 = load ptr, ptr %3, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.kdtree, ptr %30, i32 0, i32 8
  %32 = getelementptr inbounds %struct.knn_list, ptr %31, i32 0, i32 1
  store float 0.000000e+00, ptr %32, align 8, !tbaa !22
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.kdtree, ptr %33, i32 0, i32 10
  store i32 0, ptr %34, align 4, !tbaa !23
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = mul i64 %36, 4
  %38 = load ptr, ptr %3, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.kdtree, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !18
  %41 = mul i64 %37, %40
  %42 = call noalias ptr @malloc(i64 noundef %41) #5
  %43 = load ptr, ptr %3, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.kdtree, ptr %43, i32 0, i32 3
  store ptr %42, ptr %44, align 8, !tbaa !24
  %45 = load ptr, ptr %3, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.kdtree, ptr %45, i32 0, i32 2
  %47 = load i64, ptr %46, align 8, !tbaa !18
  %48 = mul i64 8, %47
  %49 = call noalias ptr @malloc(i64 noundef %48) #5
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.kdtree, ptr %50, i32 0, i32 4
  store ptr %49, ptr %51, align 8, !tbaa !25
  %52 = load ptr, ptr %3, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.kdtree, ptr %52, i32 0, i32 2
  %54 = load i64, ptr %53, align 8, !tbaa !18
  %55 = mul i64 8, %54
  %56 = call noalias ptr @malloc(i64 noundef %55) #5
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.kdtree, ptr %57, i32 0, i32 5
  store ptr %56, ptr %58, align 8, !tbaa !26
  %59 = load ptr, ptr %3, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.kdtree, ptr %59, i32 0, i32 2
  %61 = load i64, ptr %60, align 8, !tbaa !18
  %62 = mul i64 1, %61
  %63 = call noalias ptr @malloc(i64 noundef %62) #5
  %64 = load ptr, ptr %3, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.kdtree, ptr %64, i32 0, i32 6
  store ptr %63, ptr %65, align 8, !tbaa !27
  %66 = load ptr, ptr %3, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.kdtree, ptr %66, i32 0, i32 2
  %68 = load i64, ptr %67, align 8, !tbaa !18
  %69 = mul i64 1, %68
  %70 = call noalias ptr @malloc(i64 noundef %69) #5
  %71 = load ptr, ptr %3, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.kdtree, ptr %71, i32 0, i32 7
  store ptr %70, ptr %72, align 8, !tbaa !28
  %73 = load ptr, ptr %3, align 8, !tbaa !9
  call void @_ZL17coord_index_resetP6kdtree(ptr noundef %73)
  %74 = load ptr, ptr %3, align 8, !tbaa !9
  call void @_ZL17coord_table_resetP6kdtree(ptr noundef %74)
  %75 = load ptr, ptr %3, align 8, !tbaa !9
  call void @_ZL19coord_deleted_resetP6kdtree(ptr noundef %75)
  %76 = load ptr, ptr %3, align 8, !tbaa !9
  call void @_ZL18coord_passed_resetP6kdtree(ptr noundef %76)
  br label %77

77:                                               ; preds = %7, %1
  %78 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %78
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL17coord_index_resetP6kdtree(ptr noundef) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL17coord_table_resetP6kdtree(ptr noundef) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL19coord_deleted_resetP6kdtree(ptr noundef) #0

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(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 }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6kdtree", !10, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !14, i64 64, !6, i64 96, !6, i64 100}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTS8knn_list", !10, i64 0, !15, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!"float", !7, i64 0}
!16 = !{!12, !6, i64 96}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !13, i64 16}
!19 = !{!12, !10, i64 88}
!20 = !{!12, !10, i64 80}
!21 = !{!12, !10, i64 64}
!22 = !{!12, !15, i64 72}
!23 = !{!12, !6, i64 100}
!24 = !{!12, !10, i64 24}
!25 = !{!12, !10, i64 32}
!26 = !{!12, !10, i64 40}
!27 = !{!12, !10, i64 48}
!28 = !{!12, !10, i64 56}


; 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: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL18coord_passed_resetP6kdtree(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z11kdtree_initi(i32 noundef %0) local_unnamed_addr #1 {
  %2 = tail call noalias dereferenceable_or_null(104) ptr @malloc(i64 noundef 104) #3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %24, label %3

3:                                                ; preds = %1
  store ptr null, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 96
  store i32 %0, ptr %4, align 8, !tbaa !14
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 0, ptr %5, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %2, i64 16
  store i64 65536, ptr %6, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %2, i64 64
  %8 = getelementptr inbounds i8, ptr %2, i64 88
  store ptr %7, ptr %8, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %2, i64 80
  store ptr %7, ptr %9, align 8, !tbaa !18
  store ptr null, ptr %7, align 8, !tbaa !19
  %10 = getelementptr inbounds i8, ptr %2, i64 72
  store float 0.000000e+00, ptr %10, align 8, !tbaa !20
  %11 = getelementptr inbounds i8, ptr %2, i64 100
  store i32 0, ptr %11, align 4, !tbaa !21
  %12 = sext i32 %0 to i64
  %13 = shl nsw i64 %12, 18
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #3
  %15 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %14, ptr %15, align 8, !tbaa !22
  %16 = tail call noalias dereferenceable_or_null(524288) ptr @malloc(i64 noundef 524288) #3
  %17 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %16, ptr %17, align 8, !tbaa !23
  %18 = tail call noalias dereferenceable_or_null(524288) ptr @malloc(i64 noundef 524288) #3
  %19 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %18, ptr %19, align 8, !tbaa !24
  %20 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #3
  %21 = getelementptr inbounds i8, ptr %2, i64 48
  store ptr %20, ptr %21, align 8, !tbaa !25
  %22 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #3
  %23 = getelementptr inbounds i8, ptr %2, i64 56
  store ptr %22, ptr %23, align 8, !tbaa !26
  tail call void @_ZL17coord_index_resetP6kdtree(ptr noundef nonnull %2)
  tail call void @_ZL17coord_table_resetP6kdtree(ptr noundef nonnull %2)
  tail call void @_ZL19coord_deleted_resetP6kdtree(ptr noundef nonnull %2)
  tail call void @_ZL18coord_passed_resetP6kdtree(ptr noundef nonnull %2)
  br label %24

24:                                               ; preds = %3, %1
  ret ptr %2
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL17coord_index_resetP6kdtree(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL17coord_table_resetP6kdtree(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL19coord_deleted_resetP6kdtree(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

!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 = !{!"_ZTS6kdtree", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !11, i64 64, !13, i64 96, !13, i64 100}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_ZTS8knn_list", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!"float", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !13, i64 96}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !10, i64 16}
!17 = !{!6, !7, i64 88}
!18 = !{!6, !7, i64 80}
!19 = !{!6, !7, i64 64}
!20 = !{!6, !12, i64 72}
!21 = !{!6, !13, i64 100}
!22 = !{!6, !7, i64 24}
!23 = !{!6, !7, i64 32}
!24 = !{!6, !7, i64 40}
!25 = !{!6, !7, i64 48}
!26 = !{!6, !7, i64 56}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass