; LLVM IR from atlantis13579/Riemann :: Src/Collision/DynamicAABBTree.ll (ZNK7Riemann15DynamicAABBTree20CalculateVolumeRatioEv)

; 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.Riemann::DynamicAABBTree" = type <{ i32, [4 x i8], %"class.std::vector", i32, i32, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Riemann::DynamicAABBTree::Node, std::allocator<Riemann::DynamicAABBTree::Node>>::_Vector_impl" }
%"struct.std::_Vector_base<Riemann::DynamicAABBTree::Node, std::allocator<Riemann::DynamicAABBTree::Node>>::_Vector_impl" = type { %"struct.std::_Vector_base<Riemann::DynamicAABBTree::Node, std::allocator<Riemann::DynamicAABBTree::Node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Riemann::DynamicAABBTree::Node, std::allocator<Riemann::DynamicAABBTree::Node>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.Riemann::DynamicAABBTree::Node" = type <{ %union.anon, %"class.Maths::TAABB3", i32, i32, i32, ptr, i8, [7 x i8] }>
%union.anon = type { i32 }
%"class.Maths::TAABB3" = type { %"class.Maths::TVector3", %"class.Maths::TVector3" }
%"class.Maths::TVector3" = type { float, float, float }

; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK5Maths6TAABB3IfE9GetVolumeEv(ptr noundef nonnull align 4 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZNK7Riemann15DynamicAABBTree20CalculateVolumeRatioEv(ptr noundef nonnull align 8 dereferenceable(44) %0) #3 align 2 {
  %2 = alloca float, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  %11 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  br label %56

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %16 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 2
  %17 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %16, i64 noundef %19) #4
  store ptr %20, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.Riemann::DynamicAABBTree::Node", ptr %21, i32 0, i32 1
  %23 = call noundef float @_ZNK5Maths6TAABB3IfE9GetVolumeEv(ptr noundef nonnull align 4 dereferenceable(24) %22)
  store float %23, ptr %5, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store float 0.000000e+00, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %24

24:                                               ; preds = %49, %15
  %25 = load i32, ptr %7, align 4, !tbaa !18
  %26 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 4
  %27 = load i32, ptr %26, align 4, !tbaa !19
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %24
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %52

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %31 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 2
  %32 = load i32, ptr %7, align 4, !tbaa !18
  %33 = sext i32 %32 to i64
  %34 = call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %33) #4
  store ptr %34, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.Riemann::DynamicAABBTree::Node", ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 4, !tbaa !20
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %30
  store i32 4, ptr %8, align 4
  br label %46

40:                                               ; preds = %30
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.Riemann::DynamicAABBTree::Node", ptr %41, i32 0, i32 1
  %43 = call noundef float @_ZNK5Maths6TAABB3IfE9GetVolumeEv(ptr noundef nonnull align 4 dereferenceable(24) %42)
  %44 = load float, ptr %6, align 4, !tbaa !16
  %45 = fadd float %44, %43
  store float %45, ptr %6, align 4, !tbaa !16
  store i32 0, ptr %8, align 4
  br label %46

46:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %47 = load i32, ptr %8, align 4
  switch i32 %47, label %58 [
    i32 0, label %48
    i32 4, label %49
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48, %46
  %50 = load i32, ptr %7, align 4, !tbaa !18
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !18
  br label %24, !llvm.loop !25

52:                                               ; preds = %29
  %53 = load float, ptr %6, align 4, !tbaa !16
  %54 = load float, ptr %5, align 4, !tbaa !16
  %55 = fdiv float %53, %54
  store float %55, ptr %2, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %56

56:                                               ; preds = %52, %14
  %57 = load float, ptr %2, align 4
  ret float %57

58:                                               ; preds = %46
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 #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, !11, i64 0}
!10 = !{!"_ZTSN7Riemann15DynamicAABBTreeE", !11, i64 0, !12, i64 8, !11, i64 32, !11, i64 36, !11, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !7, i64 0}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !11, i64 36}
!20 = !{!21, !11, i64 36}
!21 = !{!"_ZTSN7Riemann15DynamicAABBTree4NodeE", !7, i64 0, !22, i64 4, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !24, i64 48}
!22 = !{!"_ZTSN5Maths6TAABB3IfEE", !23, i64 0, !23, i64 12}
!23 = !{!"_ZTSN5Maths8TVector3IfEE", !17, i64 0, !17, i64 4, !17, i64 8}
!24 = !{!"bool", !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK5Maths6TAABB3IfE9GetVolumeEv(ptr noundef nonnull align 4 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZNK7Riemann15DynamicAABBTree20CalculateVolumeRatioEv(ptr noundef nonnull align 8 dereferenceable(44) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = icmp eq i32 %2, -1
  br i1 %3, label %26, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = sext i32 %2 to i64
  %7 = tail call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %6) #2
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = tail call noundef float @_ZNK5Maths6TAABB3IfE9GetVolumeEv(ptr noundef nonnull align 4 dereferenceable(24) %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %22, %4
  %.011.lcssa = phi float [ 0.000000e+00, %4 ], [ %.1, %22 ]
  %13 = fdiv float %.011.lcssa, %9
  br label %26

.lr.ph:                                           ; preds = %4, %22
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 0, %4 ]
  %.01113 = phi float [ %.1, %22 ], [ 0.000000e+00, %4 ]
  %14 = tail call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #2
  %15 = getelementptr inbounds i8, ptr %14, i64 36
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %22, label %18

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %14, i64 4
  %20 = tail call noundef float @_ZNK5Maths6TAABB3IfE9GetVolumeEv(ptr noundef nonnull align 4 dereferenceable(24) %19)
  %21 = fadd float %.01113, %20
  br label %22

22:                                               ; preds = %.lr.ph, %18
  %.1 = phi float [ %21, %18 ], [ %.01113, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %10, align 4, !tbaa !15
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !22

26:                                               ; preds = %1, %._crit_edge
  %.0 = phi float [ %13, %._crit_edge ], [ 0.000000e+00, %1 ]
  ret float %.0
}

attributes #0 = { 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 = { 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 #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 = !{!"_ZTSN7Riemann15DynamicAABBTreeE", !7, i64 0, !10, i64 8, !7, i64 32, !7, i64 36, !7, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 36}
!16 = !{!17, !7, i64 36}
!17 = !{!"_ZTSN7Riemann15DynamicAABBTree4NodeE", !8, i64 0, !18, i64 4, !7, i64 28, !7, i64 32, !7, i64 36, !14, i64 40, !21, i64 48}
!18 = !{!"_ZTSN5Maths6TAABB3IfEE", !19, i64 0, !19, i64 12}
!19 = !{!"_ZTSN5Maths8TVector3IfEE", !20, i64 0, !20, i64 4, !20, i64 8}
!20 = !{!"float", !8, i64 0}
!21 = !{!"bool", !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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