; LLVM IR from zig-gamedev/zphysics :: libs/Jolt/AABBTree (AABBTreeBuilder)

; 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.JPH::AABBTreeBuilder::Node" = type <{ %"class.JPH::AABox", %"class.JPH::Array", [2 x ptr], [8 x i8] }>
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }
%"class.JPH::Array" = type { i64, i64, 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72)) #1 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3JPH15AABBTreeBuilder4Node31GetTriangleCountPerNodeInternalERfRjS3_S3_(ptr noundef nonnull align 16 dereferenceable(72) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8
  %14 = call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72) %13)
  br i1 %14, label %15, label %30

15:                                               ; preds = %5
  %16 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %13, i32 0, i32 2
  %17 = getelementptr inbounds [2 x ptr], ptr %16, i64 0, i64 0
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZNK3JPH15AABBTreeBuilder4Node31GetTriangleCountPerNodeInternalERfRjS3_S3_(ptr noundef nonnull align 16 dereferenceable(72) %18, ptr noundef nonnull align 4 dereferenceable(4) %19, ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %22)
  %23 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %13, i32 0, i32 2
  %24 = getelementptr inbounds [2 x ptr], ptr %23, i64 0, i64 1
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZNK3JPH15AABBTreeBuilder4Node31GetTriangleCountPerNodeInternalERfRjS3_S3_(ptr noundef nonnull align 16 dereferenceable(72) %25, ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef nonnull align 4 dereferenceable(4) %27, ptr noundef nonnull align 4 dereferenceable(4) %28, ptr noundef nonnull align 4 dereferenceable(4) %29)
  br label %49

30:                                               ; preds = %5
  %31 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %13)
  %32 = uitofp i32 %31 to float
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load float, ptr %33, align 4, !tbaa !9
  %35 = fadd float %34, %32
  store float %35, ptr %33, align 4, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = add i32 %37, 1
  store i32 %38, ptr %36, align 4, !tbaa !11
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %40 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %13)
  store i32 %40, ptr %11, align 4, !tbaa !11
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %39, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %42, ptr %43, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %45 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %13)
  store i32 %45, ptr %12, align 4, !tbaa !11
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %44, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %47, ptr %48, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %49

49:                                               ; preds = %30, %15
  ret void
}

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 = { inlinehint 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 = { 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 #4 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3JPH15AABBTreeBuilder4Node31GetTriangleCountPerNodeInternalERfRjS3_S3_(ptr noundef nonnull align 16 dereferenceable(72) %0, ptr nocapture noundef nonnull align 4 dereferenceable(4) %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4) local_unnamed_addr #3 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = tail call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72) %0)
  br i1 %8, label %tailrecurse, label %tailrecurse._crit_edge

tailrecurse:                                      ; preds = %5, %tailrecurse
  %.tr19 = phi ptr [ %12, %tailrecurse ], [ %0, %5 ]
  %9 = getelementptr inbounds i8, ptr %.tr19, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void @_ZNK3JPH15AABBTreeBuilder4Node31GetTriangleCountPerNodeInternalERfRjS3_S3_(ptr noundef nonnull align 16 dereferenceable(72) %10, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %11 = getelementptr inbounds i8, ptr %.tr19, i64 64
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72) %12)
  br i1 %13, label %tailrecurse, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr.lcssa = phi ptr [ %0, %5 ], [ %12, %tailrecurse ]
  %14 = tail call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %.tr.lcssa)
  %15 = uitofp i32 %14 to float
  %16 = load float, ptr %1, align 4, !tbaa !9
  %17 = fadd float %16, %15
  store float %17, ptr %1, align 4, !tbaa !9
  %18 = load i32, ptr %2, align 4, !tbaa !11
  %19 = add i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %20 = tail call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %.tr.lcssa)
  store i32 %20, ptr %6, align 4, !tbaa !11
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %22 = load i32, ptr %21, align 4, !tbaa !11
  store i32 %22, ptr %3, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  %23 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %.tr.lcssa)
  store i32 %23, ptr %7, align 4, !tbaa !11
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %25 = load i32, ptr %24, align 4, !tbaa !11
  store i32 %25, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  ret void
}

attributes #0 = { mustprogress 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 = { inlinehint 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 = { 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 #4 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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