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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalEff(ptr noundef nonnull align 16 dereferenceable(72) %0, float noundef %1, float noundef %2) #2 align 2 {
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %5, align 8
  %9 = call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72) %8)
  br i1 %9, label %10, label %28

10:                                               ; preds = %3
  %11 = load float, ptr %6, align 4, !tbaa !9
  %12 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %8, i32 0, i32 0
  %13 = call noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32) %12)
  %14 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %8, i32 0, i32 2
  %15 = getelementptr inbounds [2 x ptr], ptr %14, i64 0, i64 0
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load float, ptr %6, align 4, !tbaa !9
  %18 = load float, ptr %7, align 4, !tbaa !9
  %19 = call noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalEff(ptr noundef nonnull align 16 dereferenceable(72) %16, float noundef %17, float noundef %18)
  %20 = call float @llvm.fmuladd.f32(float %11, float %13, float %19)
  %21 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %8, i32 0, i32 2
  %22 = getelementptr inbounds [2 x ptr], ptr %21, i64 0, i64 1
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load float, ptr %6, align 4, !tbaa !9
  %25 = load float, ptr %7, align 4, !tbaa !9
  %26 = call noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalEff(ptr noundef nonnull align 16 dereferenceable(72) %23, float noundef %24, float noundef %25)
  %27 = fadd float %20, %26
  store float %27, ptr %4, align 4
  br label %36

28:                                               ; preds = %3
  %29 = load float, ptr %7, align 4, !tbaa !9
  %30 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %8, i32 0, i32 0
  %31 = call noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32) %30)
  %32 = fmul float %29, %31
  %33 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %8)
  %34 = uitofp i32 %33 to float
  %35 = fmul float %32, %34
  store float %35, ptr %4, align 4
  br label %36

36:                                               ; preds = %28, %10
  %37 = load float, ptr %4, align 4
  ret float %37
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

attributes #0 = { 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 #1 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalEff(ptr noundef nonnull align 16 dereferenceable(72) %0, float noundef %1, float noundef %2) local_unnamed_addr #2 align 2 {
  %4 = tail call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(72) %0)
  %5 = tail call noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32) %0)
  br i1 %4, label %6, label %common.ret

common.ret8:                                      ; preds = %6, %common.ret
  %common.ret8.op = phi float [ %18, %common.ret ], [ %14, %6 ]
  ret float %common.ret8.op

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalEff(ptr noundef nonnull align 16 dereferenceable(72) %8, float noundef %1, float noundef %2)
  %10 = tail call float @llvm.fmuladd.f32(float %1, float %5, float %9)
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = load ptr, ptr %11, align 16, !tbaa !5
  %13 = tail call noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalEff(ptr noundef nonnull align 16 dereferenceable(72) %12, float noundef %1, float noundef %2)
  %14 = fadd float %10, %13
  br label %common.ret8

common.ret:                                       ; preds = %3
  %15 = fmul float %5, %2
  %16 = tail call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(72) %0)
  %17 = uitofp i32 %16 to float
  %18 = fmul float %15, %17
  br label %common.ret8
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

attributes #0 = { 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 #1 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}


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