; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib/kdtree (kdtree)

; 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._VlRand = type { [624 x i32], i32 }
%struct._VlKDForest = type { i32, ptr, i32, ptr, i32, ptr, ptr, i32, i32, [5 x %struct._VlKDTreeSplitDimension], i32, i32, ptr, i32, i32, ptr, i32, i32, i32, i32 }
%struct._VlKDTreeSplitDimension = type { i32, double, double }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [98 x i8], align 1
@__PRETTY_FUNCTION__.vl_kdforest_new = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @vl_kdforest_new(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct._VlRand, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %7 = call noalias ptr @malloc(i64 noundef 232) #6
  store ptr %7, ptr %5, align 8, !tbaa !9
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp uge i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 278, ptr noundef @__PRETTY_FUNCTION__.vl_kdforest_new) #7
  unreachable

12:                                               ; preds = %10
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp uge i32 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %17

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 279, ptr noundef @__PRETTY_FUNCTION__.vl_kdforest_new) #7
  unreachable

17:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 2500, ptr %6) #5
  call void @vl_rand_init(ptr noundef %6)
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct._VlKDForest, ptr %18, i32 0, i32 1
  store ptr %6, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct._VlKDForest, ptr %20, i32 0, i32 2
  store i32 2, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct._VlKDForest, ptr %22, i32 0, i32 4
  store i32 0, ptr %23, align 8, !tbaa !14
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct._VlKDForest, ptr %24, i32 0, i32 3
  store ptr null, ptr %25, align 8, !tbaa !15
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct._VlKDForest, ptr %27, i32 0, i32 0
  store i32 %26, ptr %28, align 8, !tbaa !16
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct._VlKDForest, ptr %30, i32 0, i32 7
  store i32 %29, ptr %31, align 8, !tbaa !17
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct._VlKDForest, ptr %32, i32 0, i32 6
  store ptr null, ptr %33, align 8, !tbaa !18
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct._VlKDForest, ptr %34, i32 0, i32 8
  store i32 1, ptr %35, align 4, !tbaa !19
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 1
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 1, i32 5
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._VlKDForest, ptr %40, i32 0, i32 11
  store i32 %39, ptr %41, align 4, !tbaa !20
  %42 = load ptr, ptr %5, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct._VlKDForest, ptr %42, i32 0, i32 10
  store i32 0, ptr %43, align 8, !tbaa !21
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct._VlKDForest, ptr %44, i32 0, i32 12
  store ptr null, ptr %45, align 8, !tbaa !22
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct._VlKDForest, ptr %46, i32 0, i32 13
  store i32 0, ptr %47, align 8, !tbaa !23
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct._VlKDForest, ptr %48, i32 0, i32 16
  store i32 0, ptr %49, align 8, !tbaa !24
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct._VlKDForest, ptr %50, i32 0, i32 15
  store ptr null, ptr %51, align 8, !tbaa !25
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct._VlKDForest, ptr %52, i32 0, i32 14
  store i32 0, ptr %53, align 4, !tbaa !26
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2500, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %54
}

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare void @vl_rand_init(ptr noundef) #4

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind "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 = { "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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 = !{!"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 8}
!12 = !{!"_VlKDForest", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !6, i64 60, !7, i64 64, !6, i64 184, !6, i64 188, !10, i64 192, !6, i64 200, !6, i64 204, !10, i64 208, !6, i64 216, !6, i64 220, !6, i64 224, !6, i64 228}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 32}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !6, i64 0}
!17 = !{!12, !6, i64 56}
!18 = !{!12, !10, i64 48}
!19 = !{!12, !6, i64 60}
!20 = !{!12, !6, i64 188}
!21 = !{!12, !6, i64 184}
!22 = !{!12, !10, i64 192}
!23 = !{!12, !6, i64 200}
!24 = !{!12, !6, i64 216}
!25 = !{!12, !10, i64 208}
!26 = !{!12, !6, i64 204}


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

%struct._VlRand = type { [624 x i32], i32 }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [98 x i8], align 1
@__PRETTY_FUNCTION__.vl_kdforest_new = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @vl_kdforest_new(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct._VlRand, align 4
  %4 = tail call noalias dereferenceable_or_null(232) ptr @malloc(i64 noundef 232) #6
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %5, label %6

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 278, ptr noundef nonnull @__PRETTY_FUNCTION__.vl_kdforest_new) #7
  unreachable

6:                                                ; preds = %2
  %.not21 = icmp eq i32 %1, 0
  br i1 %.not21, label %7, label %8

7:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 279, ptr noundef nonnull @__PRETTY_FUNCTION__.vl_kdforest_new) #7
  unreachable

8:                                                ; preds = %6
  call void @llvm.lifetime.start.p0(i64 2500, ptr nonnull %3) #8
  call void @vl_rand_init(ptr noundef nonnull %3) #8
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 2, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 0, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr null, ptr %12, align 8, !tbaa !13
  store i32 %0, ptr %4, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %4, i64 56
  store i32 %1, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %4, i64 48
  store ptr null, ptr %14, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %4, i64 60
  store i32 1, ptr %15, align 4, !tbaa !17
  %16 = icmp eq i32 %1, 1
  %17 = select i1 %16, i32 1, i32 5
  %18 = getelementptr inbounds i8, ptr %4, i64 188
  store i32 %17, ptr %18, align 4, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %4, i64 184
  store i32 0, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %4, i64 192
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %20, i8 0, i64 28, i1 false)
  call void @llvm.lifetime.end.p0(i64 2500, ptr nonnull %3) #8
  ret ptr %4
}

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

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @vl_rand_init(ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn nounwind "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 = { "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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, !10, i64 8}
!6 = !{!"_VlKDForest", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !7, i64 60, !8, i64 64, !7, i64 184, !7, i64 188, !10, i64 192, !7, i64 200, !7, i64 204, !10, i64 208, !7, i64 216, !7, i64 220, !7, i64 224, !7, i64 228}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 32}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !7, i64 56}
!16 = !{!6, !10, i64 48}
!17 = !{!6, !7, i64 60}
!18 = !{!6, !7, i64 188}
!19 = !{!6, !7, i64 184}


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