; LLVM IR from jrouwe/JoltPhysics :: 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", i32, i32, [2 x i32] }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(48)) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 16 dereferenceable(48) ptr @_ZNK3JPH5ArrayINS_15AABBTreeBuilder4NodeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(48)) #0 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 @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalERKNS_5ArrayIS1_NS_12STLAllocatorIS1_EEEEff(ptr noundef nonnull align 16 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, float noundef %2, float noundef %3) #2 align 2 {
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store float %2, ptr %8, align 4, !tbaa !9
  store float %3, ptr %9, align 4, !tbaa !9
  %10 = load ptr, ptr %6, align 8
  %11 = call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(48) %10)
  br i1 %11, label %12, label %38

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

38:                                               ; preds = %4
  %39 = load float, ptr %9, align 4, !tbaa !9
  %40 = getelementptr inbounds %"class.JPH::AABBTreeBuilder::Node", ptr %10, i32 0, i32 0
  %41 = call noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32) %40)
  %42 = fmul float %39, %41
  %43 = call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(48) %10)
  %44 = uitofp i32 %43 to float
  %45 = fmul float %42, %44
  store float %45, ptr %5, align 4
  br label %46

46:                                               ; preds = %38, %12
  %47 = load float, ptr %5, align 4
  ret float %47
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 16 dereferenceable(48) ptr @_ZNK3JPH5ArrayINS_15AABBTreeBuilder4NodeENS_12STLAllocatorIS2_EEEixEm(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 i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(48)) local_unnamed_addr #0 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 @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalERKNS_5ArrayIS1_NS_12STLAllocatorIS1_EEEEff(ptr noundef nonnull align 16 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, float noundef %2, float noundef %3) local_unnamed_addr #2 align 2 {
  %5 = tail call noundef zeroext i1 @_ZNK3JPH15AABBTreeBuilder4Node11HasChildrenEv(ptr noundef nonnull align 16 dereferenceable(48) %0)
  %6 = tail call noundef float @_ZNK3JPH5AABox14GetSurfaceAreaEv(ptr noundef nonnull align 16 dereferenceable(32) %0)
  br i1 %5, label %7, label %common.ret

common.ret12:                                     ; preds = %7, %common.ret
  %common.ret12.op = phi float [ %23, %common.ret ], [ %19, %7 ]
  ret float %common.ret12.op

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = tail call noundef nonnull align 16 dereferenceable(48) ptr @_ZNK3JPH5ArrayINS_15AABBTreeBuilder4NodeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %10)
  %12 = tail call noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalERKNS_5ArrayIS1_NS_12STLAllocatorIS1_EEEEff(ptr noundef nonnull align 16 dereferenceable(48) %11, ptr noundef nonnull align 8 dereferenceable(24) %1, float noundef %2, float noundef %3)
  %13 = tail call float @llvm.fmuladd.f32(float %2, float %6, float %12)
  %14 = getelementptr inbounds i8, ptr %0, i64 44
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = tail call noundef nonnull align 16 dereferenceable(48) ptr @_ZNK3JPH5ArrayINS_15AABBTreeBuilder4NodeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %16)
  %18 = tail call noundef float @_ZNK3JPH15AABBTreeBuilder4Node24CalculateSAHCostInternalERKNS_5ArrayIS1_NS_12STLAllocatorIS1_EEEEff(ptr noundef nonnull align 16 dereferenceable(48) %17, ptr noundef nonnull align 8 dereferenceable(24) %1, float noundef %2, float noundef %3)
  %19 = fadd float %13, %18
  br label %common.ret12

common.ret:                                       ; preds = %4
  %20 = fmul float %6, %3
  %21 = tail call noundef i32 @_ZNK3JPH15AABBTreeBuilder4Node16GetTriangleCountEv(ptr noundef nonnull align 16 dereferenceable(48) %0)
  %22 = uitofp i32 %21 to float
  %23 = fmul float %20, %22
  br label %common.ret12
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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