; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Collision/Shape (CompoundShape)

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

%"struct.JPH::Shape::Stats" = type <{ i64, i32, [4 x i8] }>
%"class.JPH::CompoundShape" = type <{ %"class.JPH::Shape.base", [6 x i8], %"class.JPH::Vec3", %"class.JPH::AABox", %"class.JPH::Array.11", float, [4 x i8] }>
%"class.JPH::Shape.base" = type <{ ptr, %"class.JPH::RefTarget.10", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.10" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::Vec3" = type { %union.anon.7 }
%union.anon.7 = type { <4 x float> }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Array.11" = type { i64, i64, ptr }
%"struct.JPH::CompoundShape::SubShape" = type <{ %"class.JPH::RefConst.9", %"class.JPH::Float3", %"class.JPH::Float3", i32, i8, [3 x i8] }>
%"class.JPH::RefConst.9" = type { ptr }
%"class.JPH::Float3" = 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_ZNK3JPH13CompoundShape17GetStatsRecursiveERNS_12UnorderedSetIPKNS_5ShapeENS_4HashIS4_EESt8equal_toIS4_EEE(ptr noundef nonnull align 16 dereferenceable(108) %0, ptr noundef nonnull align 1 %1) unnamed_addr #3 align 2 {
  %3 = alloca %"struct.JPH::Shape::Stats", align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca { i64, i32 }, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %"struct.JPH::Shape::Stats", align 8
  %12 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call { i64, i32 } @_ZNK3JPH5Shape17GetStatsRecursiveERNS_12UnorderedSetIPKS0_NS_4HashIS3_EESt8equal_toIS3_EEE(ptr noundef nonnull align 8 dereferenceable(26) %13, ptr noundef nonnull align 1 %14)
  store { i64, i32 } %15, ptr %6, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %6, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %16 = getelementptr inbounds %"class.JPH::CompoundShape", ptr %13, i32 0, i32 4
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %17)
  store ptr %18, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %19)
  store ptr %20, ptr %9, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %46, %2
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp ne ptr %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %49

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %27, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.JPH::CompoundShape::SubShape", ptr %28, i32 0, i32 0
  %30 = call noundef ptr @_ZNK3JPH8RefConstINS_5ShapeEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %29)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %30, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %32, i64 30
  %34 = load ptr, ptr %33, align 8
  %35 = call { i64, i32 } %34(ptr noundef nonnull align 8 dereferenceable(26) %30, ptr noundef nonnull align 1 %31)
  store { i64, i32 } %35, ptr %12, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %12, i64 12, i1 false)
  %36 = getelementptr inbounds %"struct.JPH::Shape::Stats", ptr %11, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %"struct.JPH::Shape::Stats", ptr %3, i32 0, i32 0
  %39 = load i64, ptr %38, align 8, !tbaa !11
  %40 = add i64 %39, %37
  store i64 %40, ptr %38, align 8, !tbaa !11
  %41 = getelementptr inbounds %"struct.JPH::Shape::Stats", ptr %11, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = getelementptr inbounds %"struct.JPH::Shape::Stats", ptr %3, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = add i32 %44, %42
  store i32 %45, ptr %43, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %46

46:                                               ; preds = %26
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.JPH::CompoundShape::SubShape", ptr %47, i32 1
  store ptr %48, ptr %8, align 8, !tbaa !5
  br label %21

49:                                               ; preds = %25
  %50 = load { i64, i32 }, ptr %3, align 8
  ret { i64, i32 } %50
}

declare { i64, i32 } @_ZNK3JPH5Shape17GetStatsRecursiveERNS_12UnorderedSetIPKS0_NS_4HashIS3_EESt8equal_toIS3_EEE(ptr noundef nonnull align 8 dereferenceable(26), ptr noundef nonnull align 1) unnamed_addr #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN3JPH5Shape5StatsE", !13, i64 0, !14, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 8}


; 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 ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_ZNK3JPH13CompoundShape17GetStatsRecursiveERNS_12UnorderedSetIPKNS_5ShapeENS_4HashIS4_EESt8equal_toIS4_EEE(ptr noundef nonnull align 16 dereferenceable(108) %0, ptr noundef nonnull align 1 %1) unnamed_addr #1 align 2 {
  %3 = tail call { i64, i32 } @_ZNK3JPH5Shape17GetStatsRecursiveERNS_12UnorderedSetIPKS0_NS_4HashIS3_EESt8equal_toIS3_EEE(ptr noundef nonnull align 8 dereferenceable(26) %0, ptr noundef nonnull align 1 %1)
  %.fca.0.extract8 = extractvalue { i64, i32 } %3, 0
  %.fca.1.extract9 = extractvalue { i64, i32 } %3, 1
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = tail call noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = tail call noundef ptr @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %.not19 = icmp eq ptr %5, %6
  br i1 %.not19, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.sroa.015.0.lcssa = phi i64 [ %.fca.0.extract8, %2 ], [ %12, %.lr.ph ]
  %.sroa.417.0.lcssa = phi i32 [ %.fca.1.extract9, %2 ], [ %13, %.lr.ph ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.015.0.lcssa, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.417.0.lcssa, 1
  ret { i64, i32 } %.fca.1.insert

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.sroa.417.022 = phi i32 [ %13, %.lr.ph ], [ %.fca.1.extract9, %2 ]
  %.sroa.015.021 = phi i64 [ %12, %.lr.ph ], [ %.fca.0.extract8, %2 ]
  %.020 = phi ptr [ %14, %.lr.ph ], [ %5, %2 ]
  %7 = tail call noundef ptr @_ZNK3JPH8RefConstINS_5ShapeEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %.020)
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 240
  %10 = load ptr, ptr %9, align 8
  %11 = tail call { i64, i32 } %10(ptr noundef nonnull align 8 dereferenceable(26) %7, ptr noundef nonnull align 1 %1)
  %.fca.0.extract = extractvalue { i64, i32 } %11, 0
  %.fca.1.extract = extractvalue { i64, i32 } %11, 1
  %12 = add i64 %.fca.0.extract, %.sroa.015.021
  %13 = add i32 %.fca.1.extract, %.sroa.417.022
  %14 = getelementptr inbounds i8, ptr %.020, i64 40
  %.not = icmp eq ptr %14, %6
  br i1 %.not, label %._crit_edge, label %.lr.ph
}

declare { i64, i32 } @_ZNK3JPH5Shape17GetStatsRecursiveERNS_12UnorderedSetIPKS0_NS_4HashIS3_EESt8equal_toIS3_EEE(ptr noundef nonnull align 8 dereferenceable(26), ptr noundef nonnull align 1) unnamed_addr #2

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 = { 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 = { "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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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