; LLVM IR from zig-gamedev/zphysics :: libs/Jolt/AABBTree (AABBTreeBuilder)

; 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.JPH::TriangleSplitter::Range" = type { i32, i32 }
%"class.JPH::AABBTreeBuilder" = type <{ ptr, i32, [4 x i8] }>
%"struct.JPH::AABBTreeBuilderStats" = type { %"struct.JPH::TriangleSplitter::Stats", float, i32, i32, i32, i32, i32, i32, i32, float, [4 x i8] }
%"struct.JPH::TriangleSplitter::Stats" = type <{ ptr, i32, [4 x i8] }>

; 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
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMinDepthEv(ptr noundef nonnull align 16 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMaxDepthEv(ptr noundef nonnull align 16 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node12GetNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetLeafNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3JPH15AABBTreeBuilder4Node23GetTriangleCountPerNodeERfRjS3_(ptr noundef nonnull align 16 dereferenceable(72), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH15AABBTreeBuilder4Node16CalculateSAHCostEff(ptr noundef nonnull align 16 dereferenceable(72), float noundef, float noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3JPH15AABBTreeBuilder5BuildERNS_20AABBTreeBuilderStatsE(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 8 dereferenceable(52) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.JPH::TriangleSplitter::Range", align 4
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %11 = getelementptr inbounds %"class.JPH::AABBTreeBuilder", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call i64 @_ZNK3JPH16TriangleSplitter15GetInitialRangeEv(ptr noundef nonnull align 8 dereferenceable(72) %12)
  store i64 %13, ptr %5, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %14 = call noundef ptr @_ZN3JPH15AABBTreeBuilder13BuildInternalERKNS_16TriangleSplitter5RangeE(ptr noundef nonnull align 8 dereferenceable(12) %10, ptr noundef nonnull align 4 dereferenceable(8) %5)
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZNK3JPH15AABBTreeBuilder4Node23GetTriangleCountPerNodeERfRjS3_(ptr noundef nonnull align 16 dereferenceable(72) %15, ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %16 = getelementptr inbounds %"class.JPH::AABBTreeBuilder", ptr %10, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %17, align 8, !tbaa !12
  %21 = getelementptr inbounds ptr, ptr %20, i64 2
  %22 = load ptr, ptr %21, align 8
  call void %22(ptr noundef nonnull align 8 dereferenceable(72) %17, ptr noundef nonnull align 8 dereferenceable(12) %19)
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call noundef float @_ZNK3JPH15AABBTreeBuilder4Node16CalculateSAHCostEff(ptr noundef nonnull align 16 dereferenceable(72) %23, float noundef 1.000000e+00, float noundef 1.000000e+00)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %25, i32 0, i32 1
  store float %24, ptr %26, align 8, !tbaa !14
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMinDepthEv(ptr noundef nonnull align 16 dereferenceable(72) %27)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %29, i32 0, i32 2
  store i32 %28, ptr %30, align 4, !tbaa !18
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMaxDepthEv(ptr noundef nonnull align 16 dereferenceable(72) %31)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %33, i32 0, i32 3
  store i32 %32, ptr %34, align 8, !tbaa !19
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node12GetNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72) %35)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %37, i32 0, i32 4
  store i32 %36, ptr %38, align 4, !tbaa !20
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetLeafNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72) %39)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %41, i32 0, i32 5
  store i32 %40, ptr %42, align 8, !tbaa !21
  %43 = getelementptr inbounds %"class.JPH::AABBTreeBuilder", ptr %10, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !22
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %45, i32 0, i32 6
  store i32 %44, ptr %46, align 4, !tbaa !23
  %47 = load i32, ptr %8, align 4, !tbaa !24
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %48, i32 0, i32 7
  store i32 %47, ptr %49, align 8, !tbaa !25
  %50 = load i32, ptr %9, align 4, !tbaa !24
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %51, i32 0, i32 8
  store i32 %50, ptr %52, align 4, !tbaa !26
  %53 = load float, ptr %7, align 4, !tbaa !27
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.JPH::AABBTreeBuilderStats", ptr %54, i32 0, i32 9
  store float %53, ptr %55, align 8, !tbaa !28
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret ptr %56
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNK3JPH16TriangleSplitter15GetInitialRangeEv(ptr noundef nonnull align 8 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN3JPH15AABBTreeBuilder13BuildInternalERKNS_16TriangleSplitter5RangeE(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(8)) #1 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 = { 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 0}
!10 = !{!"_ZTSN3JPH15AABBTreeBuilderE", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !8, i64 0}
!14 = !{!15, !17, i64 16}
!15 = !{!"_ZTSN3JPH20AABBTreeBuilderStatsE", !16, i64 0, !17, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !17, i64 48}
!16 = !{!"_ZTSN3JPH16TriangleSplitter5StatsE", !6, i64 0, !11, i64 8}
!17 = !{!"float", !7, i64 0}
!18 = !{!15, !11, i64 20}
!19 = !{!15, !11, i64 24}
!20 = !{!15, !11, i64 28}
!21 = !{!15, !11, i64 32}
!22 = !{!10, !11, i64 8}
!23 = !{!15, !11, i64 36}
!24 = !{!11, !11, i64 0}
!25 = !{!15, !11, i64 40}
!26 = !{!15, !11, i64 44}
!27 = !{!17, !17, i64 0}
!28 = !{!15, !17, i64 48}


; 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.JPH::TriangleSplitter::Range" = type { i32, i32 }

; 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
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMinDepthEv(ptr noundef nonnull align 16 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMaxDepthEv(ptr noundef nonnull align 16 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node12GetNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetLeafNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3JPH15AABBTreeBuilder4Node23GetTriangleCountPerNodeERfRjS3_(ptr noundef nonnull align 16 dereferenceable(72), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH15AABBTreeBuilder4Node16CalculateSAHCostEff(ptr noundef nonnull align 16 dereferenceable(72), float noundef, float noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3JPH15AABBTreeBuilder5BuildERNS_20AABBTreeBuilderStatsE(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 8 dereferenceable(52) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %"struct.JPH::TriangleSplitter::Range", align 8
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = tail call i64 @_ZNK3JPH16TriangleSplitter15GetInitialRangeEv(ptr noundef nonnull align 8 dereferenceable(72) %7)
  store i64 %8, ptr %3, align 8
  %9 = call noundef ptr @_ZN3JPH15AABBTreeBuilder13BuildInternalERKNS_16TriangleSplitter5RangeE(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  call void @_ZNK3JPH15AABBTreeBuilder4Node23GetTriangleCountPerNodeERfRjS3_(ptr noundef nonnull align 16 dereferenceable(72) %9, ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load ptr, ptr %12, align 8
  call void %13(ptr noundef nonnull align 8 dereferenceable(72) %10, ptr noundef nonnull align 8 dereferenceable(12) %1)
  %14 = call noundef float @_ZNK3JPH15AABBTreeBuilder4Node16CalculateSAHCostEff(ptr noundef nonnull align 16 dereferenceable(72) %9, float noundef 1.000000e+00, float noundef 1.000000e+00)
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  store float %14, ptr %15, align 8, !tbaa !13
  %16 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMinDepthEv(ptr noundef nonnull align 16 dereferenceable(72) %9)
  %17 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %16, ptr %17, align 4, !tbaa !17
  %18 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node11GetMaxDepthEv(ptr noundef nonnull align 16 dereferenceable(72) %9)
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  store i32 %18, ptr %19, align 8, !tbaa !18
  %20 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node12GetNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72) %9)
  %21 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 %20, ptr %21, align 4, !tbaa !19
  %22 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetLeafNodeCountEv(ptr noundef nonnull align 16 dereferenceable(72) %9)
  %23 = getelementptr inbounds i8, ptr %1, i64 32
  store i32 %22, ptr %23, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !21
  %26 = getelementptr inbounds i8, ptr %1, i64 36
  store i32 %25, ptr %26, align 4, !tbaa !22
  %27 = load i32, ptr %5, align 4, !tbaa !23
  %28 = getelementptr inbounds i8, ptr %1, i64 40
  store i32 %27, ptr %28, align 8, !tbaa !24
  %29 = load i32, ptr %6, align 4, !tbaa !23
  %30 = getelementptr inbounds i8, ptr %1, i64 44
  store i32 %29, ptr %30, align 4, !tbaa !25
  %31 = load float, ptr %4, align 4, !tbaa !26
  %32 = getelementptr inbounds i8, ptr %1, i64 48
  store float %31, ptr %32, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret ptr %9
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNK3JPH16TriangleSplitter15GetInitialRangeEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN3JPH15AABBTreeBuilder13BuildInternalERKNS_16TriangleSplitter5RangeE(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 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 = { 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 0}
!6 = !{!"_ZTSN3JPH15AABBTreeBuilderE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !9, i64 0}
!13 = !{!14, !16, i64 16}
!14 = !{!"_ZTSN3JPH20AABBTreeBuilderStatsE", !15, i64 0, !16, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !16, i64 48}
!15 = !{!"_ZTSN3JPH16TriangleSplitter5StatsE", !7, i64 0, !10, i64 8}
!16 = !{!"float", !8, i64 0}
!17 = !{!14, !10, i64 20}
!18 = !{!14, !10, i64 24}
!19 = !{!14, !10, i64 28}
!20 = !{!14, !10, i64 32}
!21 = !{!6, !10, i64 8}
!22 = !{!14, !10, i64 36}
!23 = !{!10, !10, i64 0}
!24 = !{!14, !10, i64 40}
!25 = !{!14, !10, i64 44}
!26 = !{!16, !16, i64 0}
!27 = !{!14, !16, i64 48}


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