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

; 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.Riemann::RayCastOption" = type { i32, [4 x i8], %"struct.Riemann::RayCastCache", i8, float, i32, %"struct.Riemann::CollisionData", ptr }
%"struct.Riemann::RayCastCache" = type <{ ptr, %"class.Riemann::StaticStack", [4 x i8] }>
%"class.Riemann::StaticStack" = type { i32, [32 x i32] }
%"struct.Riemann::CollisionData" = type { i32, i32, i32, i32 }
%class.Ray3 = type { %"class.Maths::TVector3", %"class.Maths::TVector3" }
%"class.Maths::TVector3" = type { float, float, float }
%"struct.Riemann::RayCastResult" = type <{ i8, [3 x i8], float, float, %"class.Maths::TVector3", %"class.Maths::TVector3", [4 x i8], ptr, %"class.std::vector.0", i32, [4 x i8] }>
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<Riemann::Geometry *, std::allocator<Riemann::Geometry *>>::_Vector_impl" }
%"struct.std::_Vector_base<Riemann::Geometry *, std::allocator<Riemann::Geometry *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Riemann::Geometry *, std::allocator<Riemann::Geometry *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Riemann::Geometry *, std::allocator<Riemann::Geometry *>>::_Vector_impl_data" = type { ptr, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Riemann20RayIntersectCacheObjERK4Ray3PKNS_13RayCastOptionEPNS_13RayCastResultE(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.Riemann::RayCastOption", ptr %11, i32 0, i32 2
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.Riemann::RayCastCache", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %51

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.Riemann::RayCastCache", ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.Ray3, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.Ray3, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %20, align 8, !tbaa !13
  %28 = getelementptr inbounds ptr, ptr %27, i64 2
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef zeroext i1 %29(ptr noundef nonnull align 8 dereferenceable(204) %20, ptr noundef nonnull align 4 dereferenceable(12) %22, ptr noundef nonnull align 4 dereferenceable(12) %24, ptr noundef %25, ptr noundef %26)
  %31 = zext i1 %30 to i8
  store i8 %31, ptr %9, align 1, !tbaa !15
  %32 = load i8, ptr %9, align 1, !tbaa !15, !range !17, !noundef !18
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %47

34:                                               ; preds = %17
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.Riemann::RayCastResult", ptr %35, i32 0, i32 0
  store i8 1, ptr %36, align 8, !tbaa !19
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.Riemann::RayCastCache", ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.Riemann::RayCastResult", ptr %40, i32 0, i32 7
  store ptr %39, ptr %41, align 8, !tbaa !27
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.Riemann::RayCastResult", ptr %42, i32 0, i32 2
  %44 = load float, ptr %43, align 4, !tbaa !28
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.Riemann::RayCastResult", ptr %45, i32 0, i32 3
  store float %44, ptr %46, align 8, !tbaa !29
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %48

47:                                               ; preds = %17
  store i32 0, ptr %10, align 4
  br label %48

48:                                               ; preds = %47, %34
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  %49 = load i32, ptr %10, align 4
  switch i32 %49, label %52 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50, %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %52

52:                                               ; preds = %51, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %53 = load i1, ptr %4, align 1
  ret i1 %53
}

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 = !{!"_ZTSN7Riemann12RayCastCacheE", !6, i64 0, !11, i64 8}
!11 = !{!"_ZTSN7Riemann11StaticStackIjLi32EEE", !12, i64 0, !7, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !16, i64 0}
!20 = !{!"_ZTSN7Riemann13RayCastResultE", !16, i64 0, !21, i64 4, !21, i64 8, !22, i64 12, !22, i64 24, !6, i64 40, !23, i64 48, !12, i64 72}
!21 = !{!"float", !7, i64 0}
!22 = !{!"_ZTSN5Maths8TVector3IfEE", !21, i64 0, !21, i64 4, !21, i64 8}
!23 = !{!"_ZTSSt6vectorIPN7Riemann8GeometryESaIS2_EE", !24, i64 0}
!24 = !{!"_ZTSSt12_Vector_baseIPN7Riemann8GeometryESaIS2_EE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIPN7Riemann8GeometryESaIS2_EE12_Vector_implE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIPN7Riemann8GeometryESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!27 = !{!20, !6, i64 40}
!28 = !{!20, !21, i64 4}
!29 = !{!20, !21, i64 8}


; 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 uwtable
define dso_local noundef zeroext i1 @_ZN7Riemann20RayIntersectCacheObjERK4Ray3PKNS_13RayCastOptionEPNS_13RayCastResultE(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.critedge, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load ptr, ptr %5, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8
  %11 = tail call noundef zeroext i1 %10(ptr noundef nonnull align 8 dereferenceable(204) %5, ptr noundef nonnull align 4 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(12) %7, ptr noundef nonnull %1, ptr noundef %2)
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %6
  store i8 1, ptr %2, align 8, !tbaa !14
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %13, ptr %14, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %2, i64 4
  %16 = load float, ptr %15, align 4, !tbaa !24
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  store float %16, ptr %17, align 8, !tbaa !25
  br label %.critedge

.critedge:                                        ; preds = %3, %6, %12
  %.1 = phi i1 [ true, %12 ], [ false, %6 ], [ false, %3 ]
  ret i1 %.1
}

attributes #0 = { 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" }

!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 = !{!"_ZTSN7Riemann12RayCastCacheE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN7Riemann11StaticStackIjLi32EEE", !11, i64 0, !8, i64 4}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !9, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTSN7Riemann13RayCastResultE", !16, i64 0, !17, i64 4, !17, i64 8, !18, i64 12, !18, i64 24, !7, i64 40, !19, i64 48, !11, i64 72}
!16 = !{!"bool", !8, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = !{!"_ZTSN5Maths8TVector3IfEE", !17, i64 0, !17, i64 4, !17, i64 8}
!19 = !{!"_ZTSSt6vectorIPN7Riemann8GeometryESaIS2_EE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseIPN7Riemann8GeometryESaIS2_EE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIPN7Riemann8GeometryESaIS2_EE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIPN7Riemann8GeometryESaIS2_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!23 = !{!15, !7, i64 40}
!24 = !{!15, !17, i64 4}
!25 = !{!15, !17, i64 8}


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