; LLVM IR from atlantis13579/Riemann :: Src/Collision/AABBTree.ll (ZNK7Riemann8AABBTree14IntersectPointERKN5Maths8TVector3IfEE)

; 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::AABBTree" = type { ptr, i32, ptr }
%"struct.Riemann::CacheFriendlyAABBTree" = type { %"class.Maths::TAABB3", 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann21CacheFriendlyAABBTree6IsLeafEv(ptr noundef nonnull align 4 dereferenceable(28)) #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree11GetLeftNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree12GetRightNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7Riemann8AABBTree14IntersectPointERKN5Maths8TVector3IfEE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = getelementptr inbounds %"class.Riemann::AABBTree", ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %20, label %15

15:                                               ; preds = %2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.Riemann::CacheFriendlyAABBTree", ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %17, ptr noundef nonnull align 4 dereferenceable(12) %18)
  br i1 %19, label %21, label %20

20:                                               ; preds = %15, %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %71

21:                                               ; preds = %15
  br label %22

22:                                               ; preds = %68, %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %70

25:                                               ; preds = %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call noundef zeroext i1 @_ZNK7Riemann21CacheFriendlyAABBTree6IsLeafEv(ptr noundef nonnull align 4 dereferenceable(28) %26)
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.Riemann::AABBTree", ptr %10, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = call noundef ptr @_ZNK7Riemann21CacheFriendlyAABBTree18GetGeometryIndicesEPi(ptr noundef nonnull align 4 dereferenceable(28) %29, ptr noundef %31)
  %33 = load i32, ptr %32, align 4, !tbaa !13
  store i32 %33, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %71

34:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %"class.Riemann::AABBTree", ptr %10, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = call noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree11GetLeftNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28) %35, ptr noundef %37)
  store ptr %38, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.Riemann::AABBTree", ptr %10, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = call noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree12GetRightNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28) %39, ptr noundef %41)
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %52

45:                                               ; preds = %34
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.Riemann::CacheFriendlyAABBTree", ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %47, ptr noundef nonnull align 4 dereferenceable(12) %48)
  br i1 %49, label %50, label %52

50:                                               ; preds = %45
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %51, ptr %6, align 8, !tbaa !5
  store i32 2, ptr %7, align 4
  br label %68, !llvm.loop !14

52:                                               ; preds = %45, %34
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %62

55:                                               ; preds = %52
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.Riemann::CacheFriendlyAABBTree", ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = call noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %57, ptr noundef nonnull align 4 dereferenceable(12) %58)
  br i1 %59, label %60, label %62

60:                                               ; preds = %55
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %61, ptr %6, align 8, !tbaa !5
  store i32 2, ptr %7, align 4
  br label %68, !llvm.loop !14

62:                                               ; preds = %55, %52
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %"class.Riemann::AABBTree", ptr %10, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !12
  %66 = call noundef ptr @_ZNK7Riemann21CacheFriendlyAABBTree18GetGeometryIndicesEPi(ptr noundef nonnull align 4 dereferenceable(28) %63, ptr noundef %65)
  %67 = load i32, ptr %66, align 4, !tbaa !13
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %68

68:                                               ; preds = %62, %60, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %69 = load i32, ptr %7, align 4
  switch i32 %69, label %71 [
    i32 2, label %22
  ]

70:                                               ; preds = %22
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %71

71:                                               ; preds = %70, %68, %28, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %72 = load i32, ptr %3, align 4
  ret i32 %72
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(12)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7Riemann21CacheFriendlyAABBTree18GetGeometryIndicesEPi(ptr noundef nonnull align 4 dereferenceable(28), ptr noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 16}
!10 = !{!"_ZTSN7Riemann8AABBTreeE", !6, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann21CacheFriendlyAABBTree6IsLeafEv(ptr noundef nonnull align 4 dereferenceable(28)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree11GetLeftNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree12GetRightNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK7Riemann8AABBTree14IntersectPointERKN5Maths8TVector3IfEE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %23, label %6

6:                                                ; preds = %2
  %7 = tail call noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %4, ptr noundef nonnull align 4 dereferenceable(12) %1)
  br i1 %7, label %.preheader, label %23

.preheader:                                       ; preds = %6
  %8 = tail call noundef zeroext i1 @_ZNK7Riemann21CacheFriendlyAABBTree6IsLeafEv(ptr noundef nonnull align 4 dereferenceable(28) %4)
  br i1 %8, label %.sink.split, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %18
  %.01930 = phi ptr [ %.120, %18 ], [ %4, %.preheader ]
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = tail call noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree11GetLeftNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28) %.01930, ptr noundef %9)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = tail call noundef ptr @_ZN7Riemann21CacheFriendlyAABBTree12GetRightNodeEPS0_(ptr noundef nonnull align 4 dereferenceable(28) %.01930, ptr noundef %11)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %15, label %13

13:                                               ; preds = %.lr.ph
  %14 = tail call noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %10, ptr noundef nonnull align 4 dereferenceable(12) %1)
  br i1 %14, label %18, label %15, !llvm.loop !11

15:                                               ; preds = %13, %.lr.ph
  %.not25 = icmp eq ptr %12, null
  br i1 %.not25, label %.sink.split, label %16

16:                                               ; preds = %15
  %17 = tail call noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %12, ptr noundef nonnull align 4 dereferenceable(12) %1)
  br i1 %17, label %18, label %.sink.split, !llvm.loop !11

18:                                               ; preds = %16, %13
  %.120 = phi ptr [ %10, %13 ], [ %12, %16 ]
  %19 = tail call noundef zeroext i1 @_ZNK7Riemann21CacheFriendlyAABBTree6IsLeafEv(ptr noundef nonnull align 4 dereferenceable(28) %.120)
  br i1 %19, label %.sink.split, label %.lr.ph

.sink.split:                                      ; preds = %16, %15, %18, %.preheader
  %.01930.lcssa.sink = phi ptr [ %4, %.preheader ], [ %.120, %18 ], [ %.01930, %15 ], [ %.01930, %16 ]
  %20 = load ptr, ptr %0, align 8, !tbaa !13
  %21 = tail call noundef ptr @_ZNK7Riemann21CacheFriendlyAABBTree18GetGeometryIndicesEPi(ptr noundef nonnull align 4 dereferenceable(28) %.01930.lcssa.sink, ptr noundef %20)
  %22 = load i32, ptr %21, align 4, !tbaa !14
  br label %23

23:                                               ; preds = %.sink.split, %2, %6
  %.2 = phi i32 [ -1, %6 ], [ -1, %2 ], [ %22, %.sink.split ]
  ret i32 %.2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5Maths6TAABB3IfE8IsInsideERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7Riemann21CacheFriendlyAABBTree18GetGeometryIndicesEPi(ptr noundef nonnull align 4 dereferenceable(28), ptr noundef) local_unnamed_addr #0 align 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 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" }

!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 16}
!6 = !{!"_ZTSN7Riemann8AABBTreeE", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 0}
!14 = !{!10, !10, i64 0}


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