; LLVM IR from begeekmyfriend/kdtree :: kdtree (kdtree_init)

; 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, double, ptr, ptr }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @coord_passed_reset(ptr noundef) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @coord_index_reset(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @kdtree_init(i32 noundef %0) #2 {
  %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 %61

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 10
  store i32 0, ptr %18, align 4, !tbaa !19
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul i64 %20, 8
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.kdtree, ptr %22, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !18
  %25 = mul i64 %21, %24
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.kdtree, ptr %27, i32 0, i32 3
  store ptr %26, ptr %28, align 8, !tbaa !20
  %29 = load ptr, ptr %3, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.kdtree, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !18
  %32 = mul i64 8, %31
  %33 = call noalias ptr @malloc(i64 noundef %32) #5
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.kdtree, ptr %34, i32 0, i32 4
  store ptr %33, ptr %35, align 8, !tbaa !21
  %36 = load ptr, ptr %3, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.kdtree, ptr %36, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !18
  %39 = mul i64 8, %38
  %40 = call noalias ptr @malloc(i64 noundef %39) #5
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.kdtree, ptr %41, i32 0, i32 5
  store ptr %40, ptr %42, align 8, !tbaa !22
  %43 = load ptr, ptr %3, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.kdtree, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !18
  %46 = mul i64 1, %45
  %47 = call noalias ptr @malloc(i64 noundef %46) #5
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.kdtree, ptr %48, i32 0, i32 6
  store ptr %47, ptr %49, align 8, !tbaa !23
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.kdtree, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !18
  %53 = mul i64 1, %52
  %54 = call noalias ptr @malloc(i64 noundef %53) #5
  %55 = load ptr, ptr %3, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.kdtree, ptr %55, i32 0, i32 7
  store ptr %54, ptr %56, align 8, !tbaa !24
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  call void @coord_index_reset(ptr noundef %57)
  %58 = load ptr, ptr %3, align 8, !tbaa !9
  call void @coord_table_reset(ptr noundef %58)
  %59 = load ptr, ptr %3, align 8, !tbaa !9
  call void @coord_deleted_reset(ptr noundef %59)
  %60 = load ptr, ptr %3, align 8, !tbaa !9
  call void @coord_passed_reset(ptr noundef %60)
  br label %61

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @coord_table_reset(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @coord_deleted_reset(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"kdtree", !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 = !{!"knn_list", !10, i64 0, !15, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!"double", !7, i64 0}
!16 = !{!12, !6, i64 96}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !13, i64 16}
!19 = !{!12, !6, i64 100}
!20 = !{!12, !10, i64 24}
!21 = !{!12, !10, i64 32}
!22 = !{!12, !10, i64 40}
!23 = !{!12, !10, i64 48}
!24 = !{!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 nounwind uwtable
declare hidden void @coord_passed_reset(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @kdtree_init(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 %20, 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 100
  store i32 0, ptr %7, align 4, !tbaa !17
  %8 = sext i32 %0 to i64
  %9 = shl nsw i64 %8, 19
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #3
  %11 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %10, ptr %11, align 8, !tbaa !18
  %12 = tail call noalias dereferenceable_or_null(524288) ptr @malloc(i64 noundef 524288) #3
  %13 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %12, ptr %13, align 8, !tbaa !19
  %14 = tail call noalias dereferenceable_or_null(524288) ptr @malloc(i64 noundef 524288) #3
  %15 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %14, ptr %15, align 8, !tbaa !20
  %16 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #3
  %17 = getelementptr inbounds i8, ptr %2, i64 48
  store ptr %16, ptr %17, align 8, !tbaa !21
  %18 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #3
  %19 = getelementptr inbounds i8, ptr %2, i64 56
  store ptr %18, ptr %19, align 8, !tbaa !22
  tail call void @coord_index_reset(ptr noundef nonnull %2)
  tail call void @coord_table_reset(ptr noundef nonnull %2)
  tail call void @coord_deleted_reset(ptr noundef nonnull %2)
  tail call void @coord_passed_reset(ptr noundef nonnull %2)
  br label %20

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

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

attributes #0 = { inlinehint 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 = { 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 = !{!"kdtree", !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/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"knn_list", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!"double", !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, !13, i64 100}
!18 = !{!6, !7, i64 24}
!19 = !{!6, !7, i64 32}
!20 = !{!6, !7, i64 40}
!21 = !{!6, !7, i64 48}
!22 = !{!6, !7, i64 56}


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