; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Collision/BroadPhase (QuadTree)

; 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::AssertLastParam" = type { i8 }
%"class.JPH::BodyID" = type { i32 }
%"class.JPH::QuadTree::NodeID" = type { i32 }
%"struct.JPH::QuadTree::AddState" = type { %"class.JPH::QuadTree::NodeID", %"class.JPH::AABox" }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon.1 }
%union.anon.1 = type { <4 x float> }

@.str.1 = external hidden unnamed_addr constant [99 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [13 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: 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 uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH8QuadTree6NodeID6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4)) #3 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3JPH8QuadTree12ValidateTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERKNS1_INS0_8TrackingENS4_IS9_EEEEjj(ptr noundef nonnull align 64 dereferenceable(81), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local i32 @_ZN3JPH8QuadTree9BuildTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERNS1_INS0_8TrackingENS4_IS9_EEEEPNS0_6NodeIDEijRNS_5AABoxE(ptr noundef nonnull align 64 dereferenceable(81), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 16 dereferenceable(32)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH8QuadTree16AddBodiesPrepareERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERNS1_INS0_8TrackingENS4_IS9_EEEEPNS_6BodyIDEiRNS0_8AddStateE(ptr noundef nonnull align 64 dereferenceable(81) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %3, i32 noundef %4, ptr noundef nonnull align 16 dereferenceable(48) %5) #4 align 2 {
  %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 ptr, align 8
  %13 = alloca %"struct.JPH::AssertLastParam", align 1
  %14 = alloca %"struct.JPH::AssertLastParam", align 1
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca %"class.JPH::BodyID", align 4
  %18 = alloca %"class.JPH::QuadTree::NodeID", align 4
  %19 = alloca %"class.JPH::QuadTree::NodeID", align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8
  br label %21

21:                                               ; preds = %6
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %27, label %24

24:                                               ; preds = %21
  %25 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.24, ptr noundef @.str.1, i32 noundef 824)
  br i1 %25, label %26, label %27

26:                                               ; preds = %24
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !11
  br label %27

27:                                               ; preds = %26, %24, %21
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.25, ptr noundef @.str.1, i32 noundef 825)
  br i1 %33, label %34, label %35

34:                                               ; preds = %32
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !12
  br label %35

35:                                               ; preds = %34, %32, %29
  br label %36

36:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %37, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %"class.JPH::BodyID", ptr %38, i64 %40
  store ptr %41, ptr %16, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %53, %36
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = load ptr, ptr %16, align 8, !tbaa !5
  %45 = icmp ult ptr %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %56

47:                                               ; preds = %42
  %48 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %48, i64 4, i1 false), !tbaa.struct !13
  %49 = getelementptr inbounds %"class.JPH::BodyID", ptr %17, i32 0, i32 0
  %50 = load i32, ptr %49, align 4
  %51 = call i32 @_ZN3JPH8QuadTree6NodeID11sFromBodyIDENS_6BodyIDE(i32 %50)
  %52 = getelementptr inbounds %"class.JPH::QuadTree::NodeID", ptr %18, i32 0, i32 0
  store i32 %51, ptr %52, align 4
  br label %53

53:                                               ; preds = %47
  %54 = load ptr, ptr %15, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.JPH::BodyID", ptr %54, i32 1
  store ptr %55, ptr %15, align 8, !tbaa !5
  br label %42, !llvm.loop !14

56:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.JPH::QuadTree::AddState", ptr %61, i32 0, i32 1
  %63 = call i32 @_ZN3JPH8QuadTree9BuildTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERNS1_INS0_8TrackingENS4_IS9_EEEEPNS0_6NodeIDEijRNS_5AABoxE(ptr noundef nonnull align 64 dereferenceable(81) %20, ptr noundef nonnull align 8 dereferenceable(24) %57, ptr noundef nonnull align 8 dereferenceable(24) %58, ptr noundef %59, i32 noundef %60, i32 noundef 0, ptr noundef nonnull align 16 dereferenceable(32) %62)
  %64 = getelementptr inbounds %"class.JPH::QuadTree::NodeID", ptr %19, i32 0, i32 0
  store i32 %63, ptr %64, align 4
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.JPH::QuadTree::AddState", ptr %65, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %66, ptr align 4 %19, i64 4, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.JPH::QuadTree::AddState", ptr %67, i32 0, i32 0
  %69 = call noundef zeroext i1 @_ZNK3JPH8QuadTree6NodeID6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %68)
  br i1 %69, label %70, label %77

70:                                               ; preds = %56
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.JPH::QuadTree::AddState", ptr %73, i32 0, i32 0
  %75 = call noundef i32 @_ZNK3JPH8QuadTree6NodeID12GetNodeIndexEv(ptr noundef nonnull align 4 dereferenceable(4) %74)
  %76 = load i32, ptr %11, align 4, !tbaa !9
  call void @_ZNK3JPH8QuadTree12ValidateTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERKNS1_INS0_8TrackingENS4_IS9_EEEEjj(ptr noundef nonnull align 64 dereferenceable(81) %20, ptr noundef nonnull align 8 dereferenceable(24) %71, ptr noundef nonnull align 8 dereferenceable(24) %72, i32 noundef %75, i32 noundef %76)
  br label %77

77:                                               ; preds = %70, %56
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i32 @_ZN3JPH8QuadTree6NodeID11sFromBodyIDENS_6BodyIDE(i32) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = { 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 = !{i64 2158743656}
!12 = !{i64 2158743987}
!13 = !{i64 0, i64 4, !9}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

%"class.JPH::BodyID" = type { i32 }

@.str.1 = external hidden unnamed_addr constant [99 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH8QuadTree6NodeID6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH8QuadTree6NodeID12GetNodeIndexEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3JPH8QuadTree12ValidateTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERKNS1_INS0_8TrackingENS4_IS9_EEEEjj(ptr noundef nonnull align 64 dereferenceable(81), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local i32 @_ZN3JPH8QuadTree9BuildTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERNS1_INS0_8TrackingENS4_IS9_EEEEPNS0_6NodeIDEijRNS_5AABoxE(ptr noundef nonnull align 64 dereferenceable(81), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 16 dereferenceable(32)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH8QuadTree16AddBodiesPrepareERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERNS1_INS0_8TrackingENS4_IS9_EEEEPNS_6BodyIDEiRNS0_8AddStateE(ptr noundef nonnull align 64 dereferenceable(81) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %3, i32 noundef %4, ptr noundef nonnull align 16 dereferenceable(48) %5) local_unnamed_addr #2 align 2 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %7, label %10

7:                                                ; preds = %6
  %8 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.1, i32 noundef 824)
  br i1 %8, label %9, label %10

9:                                                ; preds = %7
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !5
  br label %10

10:                                               ; preds = %9, %7, %6
  %11 = icmp sgt i32 %4, 0
  br i1 %11, label %.lr.ph.preheader, label %12

12:                                               ; preds = %10
  %13 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.25, ptr noundef nonnull @.str.1, i32 noundef 825)
  br i1 %13, label %14, label %._crit_edge

14:                                               ; preds = %12
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !6
  br label %._crit_edge

.lr.ph.preheader:                                 ; preds = %10
  %15 = zext nneg i32 %4 to i64
  %16 = getelementptr inbounds %"class.JPH::BodyID", ptr %3, i64 %15
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %14, %12
  %17 = getelementptr inbounds i8, ptr %5, i64 16
  %18 = tail call i32 @_ZN3JPH8QuadTree9BuildTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERNS1_INS0_8TrackingENS4_IS9_EEEEPNS0_6NodeIDEijRNS_5AABoxE(ptr noundef nonnull align 64 dereferenceable(81) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %3, i32 noundef %4, i32 noundef 0, ptr noundef nonnull align 16 dereferenceable(32) %17)
  store i32 %18, ptr %5, align 16, !tbaa !7
  %19 = tail call noundef zeroext i1 @_ZNK3JPH8QuadTree6NodeID6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %5)
  br i1 %19, label %23, label %25

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.022 = phi ptr [ %21, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.sroa.02.0.copyload = load i32, ptr %.022, align 4, !tbaa !7
  %20 = tail call i32 @_ZN3JPH8QuadTree6NodeID11sFromBodyIDENS_6BodyIDE(i32 %.sroa.02.0.copyload)
  %21 = getelementptr inbounds i8, ptr %.022, i64 4
  %22 = icmp ult ptr %21, %16
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !11

23:                                               ; preds = %._crit_edge
  %24 = tail call noundef i32 @_ZNK3JPH8QuadTree6NodeID12GetNodeIndexEv(ptr noundef nonnull align 4 dereferenceable(4) %5)
  tail call void @_ZNK3JPH8QuadTree12ValidateTreeERKNS_5ArrayIPNS_4BodyENS_12STLAllocatorIS3_EEEERKNS1_INS0_8TrackingENS4_IS9_EEEEjj(ptr noundef nonnull align 64 dereferenceable(81) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, i32 noundef %24, i32 noundef %4)
  br label %25

25:                                               ; preds = %23, %._crit_edge
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i32 @_ZN3JPH8QuadTree6NodeID11sFromBodyIDENS_6BodyIDE(i32) local_unnamed_addr #0 align 2

attributes #0 = { 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 #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 = { 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 = { 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 = !{i64 2158743656}
!6 = !{i64 2158743987}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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