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

; 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 }

@.str.1 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1
@__PRETTY_FUNCTION__._ZNK7Riemann15DynamicAABBTree13ComputeHeightEi = external hidden unnamed_addr constant [55 x i8], align 1

; 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 zeroext i1 @_ZNK7Riemann15DynamicAABBTree4Node6IsLeafEv(ptr noundef nonnull align 8 dereferenceable(49)) #2 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEi(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1) #4 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp sle i32 0, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp slt i32 %14, %16
  br label %18

18:                                               ; preds = %13, %2
  %19 = phi i1 [ false, %2 ], [ %17, %13 ]
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  br label %23

21:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 963, ptr noundef @__PRETTY_FUNCTION__._ZNK7Riemann15DynamicAABBTree13ComputeHeightEi) #5
  unreachable

22:                                               ; No predecessors!
  br label %23

23:                                               ; preds = %22, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %24 = getelementptr inbounds %"class.Riemann::DynamicAABBTree", ptr %10, i32 0, i32 2
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %26) #6
  store ptr %27, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree4Node6IsLeafEv(ptr noundef nonnull align 8 dereferenceable(49) %28)
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

31:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.Riemann::DynamicAABBTree::Node", ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = call noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEi(ptr noundef nonnull align 8 dereferenceable(44) %10, i32 noundef %34)
  store i32 %35, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.Riemann::DynamicAABBTree::Node", ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 8, !tbaa !23
  %39 = call noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEi(ptr noundef nonnull align 8 dereferenceable(44) %10, i32 noundef %38)
  store i32 %39, ptr %9, align 4, !tbaa !9
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = add nsw i32 1, %41
  store i32 %42, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %43

43:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %44 = load i32, ptr %3, align 4
  ret i32 %44
}

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 = { noreturn nounwind "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 = { 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 #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 36}
!12 = !{!"_ZTSN7Riemann15DynamicAABBTreeE", !10, i64 0, !13, i64 8, !10, i64 32, !10, i64 36, !10, i64 40}
!13 = !{!"_ZTSSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIN7Riemann15DynamicAABBTree4NodeESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!18, !10, i64 28}
!18 = !{!"_ZTSN7Riemann15DynamicAABBTree4NodeE", !7, i64 0, !19, i64 4, !10, i64 28, !10, i64 32, !10, i64 36, !6, i64 40, !22, i64 48}
!19 = !{!"_ZTSN5Maths6TAABB3IfEE", !20, i64 0, !20, i64 12}
!20 = !{!"_ZTSN5Maths8TVector3IfEE", !21, i64 0, !21, i64 4, !21, i64 8}
!21 = !{!"float", !7, i64 0}
!22 = !{!"bool", !7, i64 0}
!23 = !{!18, !10, 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"

@.str.1 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1
@__PRETTY_FUNCTION__._ZNK7Riemann15DynamicAABBTree13ComputeHeightEi = external hidden unnamed_addr constant [55 x i8], align 1

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

; Function Attrs: mustprogress 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) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree4Node6IsLeafEv(ptr noundef nonnull align 8 dereferenceable(49)) local_unnamed_addr #2 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEi(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = icmp sgt i32 %1, -1
  %6 = getelementptr inbounds i8, ptr %0, i64 36
  %7 = load i32, ptr %6, align 4
  %8 = icmp sgt i32 %7, %1
  %or.cond = select i1 %5, i1 %8, i1 false
  br i1 %or.cond, label %9, label %.critedge

.critedge:                                        ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 963, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK7Riemann15DynamicAABBTree13ComputeHeightEi) #4
  unreachable

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = zext nneg i32 %1 to i64
  %12 = tail call noundef nonnull align 8 dereferenceable(49) ptr @_ZNKSt6vectorIN7Riemann15DynamicAABBTree4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %11) #5
  %13 = tail call noundef zeroext i1 @_ZNK7Riemann15DynamicAABBTree4Node6IsLeafEv(ptr noundef nonnull align 8 dereferenceable(49) %12)
  br i1 %13, label %common.ret10, label %14

common.ret10:                                     ; preds = %9, %14
  %common.ret10.op = phi i32 [ %23, %14 ], [ 0, %9 ]
  ret i32 %common.ret10.op

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %15 = getelementptr inbounds i8, ptr %12, i64 28
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = tail call noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEi(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %16)
  store i32 %17, ptr %3, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  %18 = getelementptr inbounds i8, ptr %12, i64 32
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = tail call noundef i32 @_ZNK7Riemann15DynamicAABBTree13ComputeHeightEi(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %19)
  store i32 %20, ptr %4, align 4, !tbaa !15
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = add nsw i32 %22, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  br label %common.ret10
}

attributes #0 = { mustprogress 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 = { noreturn nounwind "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 = { noreturn nounwind }
attributes #5 = { 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, !12, i64 28}
!6 = !{!"_ZTSN7Riemann15DynamicAABBTree4NodeE", !7, i64 0, !9, i64 4, !12, i64 28, !12, i64 32, !12, i64 36, !13, i64 40, !14, i64 48}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"_ZTSN5Maths6TAABB3IfEE", !10, i64 0, !10, i64 12}
!10 = !{!"_ZTSN5Maths8TVector3IfEE", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"float", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!6, !12, i64 32}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass