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

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree8ValidateEv(ptr noundef nonnull align 8 dereferenceable(44) %0) #2 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = call noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree17ValidateRecursiveEi(ptr noundef nonnull align 8 dereferenceable(44) %7, i32 noundef %9)
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %57

12:                                               ; preds = %1
  %13 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = call noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree13ValidateAABBsEi(ptr noundef nonnull align 8 dereferenceable(44) %7, i32 noundef %14)
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i1 false, ptr %2, align 1
  br label %57

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %18 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 5
  %19 = load i32, ptr %18, align 8, !tbaa !17
  store i32 %19, ptr %5, align 4, !tbaa !16
  br label %20

20:                                               ; preds = %32, %17
  %21 = load i32, ptr %5, align 4, !tbaa !16
  %22 = icmp ne i32 %21, -1
  br i1 %22, label %23, label %41

23:                                               ; preds = %20
  %24 = load i32, ptr %5, align 4, !tbaa !16
  %25 = icmp sle i32 0, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = load i32, ptr %5, align 4, !tbaa !16
  %28 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 4
  %29 = load i32, ptr %28, align 4, !tbaa !18
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %26, %23
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %56

32:                                               ; preds = %26
  %33 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 2
  %34 = load i32, ptr %5, align 4, !tbaa !16
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef %35) #3
  %37 = getelementptr inbounds %"struct.Riemann::DynamicAABBTree::Node", ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !19
  store i32 %38, ptr %5, align 4, !tbaa !16
  %39 = load i32, ptr %4, align 4, !tbaa !16
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !16
  br label %20, !llvm.loop !20

41:                                               ; preds = %20
  %42 = call noundef i32 @_ZNK7Riemann15DynamicAABBTree9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(44) %7)
  %43 = call noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEv(ptr noundef nonnull align 8 dereferenceable(44) %7)
  %44 = icmp ne i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %56

46:                                               ; preds = %41
  %47 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !22
  %49 = load i32, ptr %4, align 4, !tbaa !16
  %50 = add nsw i32 %48, %49
  %51 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %7, i32 0, i32 4
  %52 = load i32, ptr %51, align 4, !tbaa !18
  %53 = icmp ne i32 %50, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %46
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %56

55:                                               ; preds = %46
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %56

56:                                               ; preds = %55, %54, %45, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %57

57:                                               ; preds = %56, %16, %11
  %58 = load i1, ptr %2, align 1
  ret i1 %58
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree17ValidateRecursiveEi(ptr noundef nonnull align 8 dereferenceable(44), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree13ValidateAABBsEi(ptr noundef nonnull align 8 dereferenceable(44), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Riemann15DynamicAABBTree9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(44)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEv(ptr noundef nonnull align 8 dereferenceable(44)) #2 align 2

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 = { 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, !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 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 40}
!18 = !{!10, !11, i64 36}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !11, i64 32}


; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree8ValidateEv(ptr noundef nonnull align 8 dereferenceable(44) %0) local_unnamed_addr #1 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = tail call noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree17ValidateRecursiveEi(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %2)
  br i1 %3, label %4, label %.loopexit

4:                                                ; preds = %1
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = tail call noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree13ValidateAABBsEi(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %5)
  br i1 %6, label %7, label %.loopexit

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %.014 = load i32, ptr %8, align 8, !tbaa !15
  %.not15 = icmp eq i32 %.014, -1
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %9 = getelementptr inbounds i8, ptr %0, i64 36
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  br label %11

11:                                               ; preds = %.lr.ph, %15
  %.017 = phi i32 [ %.014, %.lr.ph ], [ %.0, %15 ]
  %.0716 = phi i32 [ 0, %.lr.ph ], [ %18, %15 ]
  %12 = icmp sgt i32 %.017, -1
  %13 = load i32, ptr %9, align 4
  %14 = icmp slt i32 %.017, %13
  %or.cond = select i1 %12, i1 %14, i1 false
  br i1 %or.cond, label %15, label %.loopexit

15:                                               ; preds = %11
  %16 = zext nneg i32 %.017 to i64
  %17 = tail call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %16) #2
  %18 = add nuw nsw i32 %.0716, 1
  %.0 = load i32, ptr %17, align 8, !tbaa !15
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !16

._crit_edge:                                      ; preds = %15, %7
  %.07.lcssa = phi i32 [ 0, %7 ], [ %18, %15 ]
  %19 = tail call noundef i32 @_ZNK7Riemann15DynamicAABBTree9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  %20 = tail call noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  %.not9 = icmp eq i32 %19, %20
  br i1 %.not9, label %21, label %.loopexit

21:                                               ; preds = %._crit_edge
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = add nsw i32 %23, %.07.lcssa
  %25 = getelementptr inbounds i8, ptr %0, i64 36
  %26 = load i32, ptr %25, align 4, !tbaa !19
  %.not10 = icmp eq i32 %24, %26
  br label %.loopexit

.loopexit:                                        ; preds = %11, %._crit_edge, %21, %4, %1
  %.1 = phi i1 [ false, %1 ], [ false, %4 ], [ false, %._crit_edge ], [ %.not10, %21 ], [ false, %11 ]
  ret i1 %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree17ValidateRecursiveEi(ptr noundef nonnull align 8 dereferenceable(44), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree13ValidateAABBsEi(ptr noundef nonnull align 8 dereferenceable(44), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Riemann15DynamicAABBTree9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(44)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEv(ptr noundef nonnull align 8 dereferenceable(44)) local_unnamed_addr #1 align 2

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 = { 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 = !{!"_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 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 32}
!19 = !{!6, !7, i64 36}


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