; LLVM IR from atlantis13579/Riemann :: Src/CollisionPrimitive/ConvexMesh.ll (ZNK7Riemann10ConvexMesh21ComputeBoundingVolumeEv)

; 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.Maths::TAABB3" = type { %"class.Maths::TVector3", %"class.Maths::TVector3" }
%"class.Maths::TVector3" = type { float, float, float }
%"class.Riemann::ConvexMesh" = type { ptr, ptr, ptr, ptr, i16, i16, i16, i16, %"class.std::vector", %"class.Maths::TAABB3" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_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 void @_ZNK7Riemann10ConvexMesh21ComputeBoundingVolumeEv(ptr dead_on_unwind noalias writable sret(%"class.Maths::TAABB3") align 4 %0, ptr noundef nonnull align 8 dereferenceable(88) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8
  call void @_ZN5Maths6TAABB3IfEC2Ev(ptr noundef nonnull align 4 dereferenceable(24) %0)
  call void @_ZN5Maths6TAABB3IfE8SetEmptyEv(ptr noundef nonnull align 4 dereferenceable(24) %0)
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %7

7:                                                ; preds = %22, %2
  %8 = load i16, ptr %5, align 2, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %6, i32 0, i32 4
  %11 = load i16, ptr %10, align 8, !tbaa !11
  %12 = zext i16 %11 to i32
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  br label %25

15:                                               ; preds = %7
  %16 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %6, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !20
  %18 = load i16, ptr %5, align 2, !tbaa !9
  %19 = zext i16 %18 to i64
  %20 = getelementptr inbounds %"class.Maths::TVector3", ptr %17, i64 %19
  %21 = call noundef nonnull align 4 dereferenceable(24) ptr @_ZN5Maths6TAABB3IfE11EncapsulateERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(12) %20)
  br label %22

22:                                               ; preds = %15
  %23 = load i16, ptr %5, align 2, !tbaa !9
  %24 = add i16 %23, 1
  store i16 %24, ptr %5, align 2, !tbaa !9
  br label %7, !llvm.loop !21

25:                                               ; preds = %14
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Maths6TAABB3IfEC2Ev(ptr noundef nonnull align 4 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Maths6TAABB3IfE8SetEmptyEv(ptr noundef nonnull align 4 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(24) ptr @_ZN5Maths6TAABB3IfE11EncapsulateERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(12)) #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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"_ZTSN7Riemann10ConvexMeshE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 34, !10, i64 36, !10, i64 38, !13, i64 40, !17, i64 64}
!13 = !{!"_ZTSSt6vectorIcSaIcEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIcSaIcEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSN5Maths6TAABB3IfEE", !18, i64 0, !18, i64 12}
!18 = !{!"_ZTSN5Maths8TVector3IfEE", !19, i64 0, !19, i64 4, !19, i64 8}
!19 = !{!"float", !7, i64 0}
!20 = !{!12, !6, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%"class.Maths::TAABB3" = type { %"class.Maths::TVector3", %"class.Maths::TVector3" }
%"class.Maths::TVector3" = type { float, float, float }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7Riemann10ConvexMesh21ComputeBoundingVolumeEv(ptr dead_on_unwind noalias nonnull writable sret(%"class.Maths::TAABB3") align 4 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(88) %1) local_unnamed_addr #0 align 2 {
  tail call void @_ZN5Maths6TAABB3IfEC2Ev(ptr noundef nonnull align 4 dereferenceable(24) %0)
  tail call void @_ZN5Maths6TAABB3IfE8SetEmptyEv(ptr noundef nonnull align 4 dereferenceable(24) %0)
  %3 = getelementptr inbounds i8, ptr %1, i64 32
  %4 = load i16, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i16 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %5 = load ptr, ptr %1, align 8, !tbaa !18
  %6 = getelementptr inbounds %"class.Maths::TVector3", ptr %5, i64 %indvars.iv
  %7 = tail call noundef nonnull align 4 dereferenceable(24) ptr @_ZN5Maths6TAABB3IfE11EncapsulateERKNS_8TVector3IfEE(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(12) %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i16, ptr %3, align 8, !tbaa !5
  %9 = zext i16 %8 to i64
  %10 = icmp ult i64 %indvars.iv.next, %9
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !19
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Maths6TAABB3IfEC2Ev(ptr noundef nonnull align 4 dereferenceable(24)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Maths6TAABB3IfE8SetEmptyEv(ptr noundef nonnull align 4 dereferenceable(24)) local_unnamed_addr #0 align 2

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

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, !10, i64 32}
!6 = !{!"_ZTSN7Riemann10ConvexMeshE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 34, !10, i64 36, !10, i64 38, !11, i64 40, !15, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"_ZTSSt6vectorIcSaIcEE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIcSaIcEE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!"_ZTSN5Maths6TAABB3IfEE", !16, i64 0, !16, i64 12}
!16 = !{!"_ZTSN5Maths8TVector3IfEE", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"float", !8, i64 0}
!18 = !{!6, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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