; LLVM IR from mtsamis/box2d-optimized :: src/collision/b2_broad_phase.ll (ZN12b2BroadPhase15UpdateNoRebuildEP9b2Fixture)

; 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.b2BroadPhase = type <{ ptr, ptr, ptr, ptr, %struct.b2TreeNode, ptr, ptr, ptr, i32, i32, %class.b2IntHashTable, i32, i32, i8, [7 x i8] }>
%struct.b2TreeNode = type { ptr, ptr, ptr, ptr, %struct.b2AABB }
%struct.b2AABB = type { %struct.b2Vec2, %struct.b2Vec2 }
%struct.b2Vec2 = type { float, float }
%class.b2IntHashTable = type <{ ptr, i32, [4 x i8] }>
%struct.b2MapNode = type { i32, i32, 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN14b2IntHashTable3GetEP9b2Fixture(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) #1 align 2

; 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) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNK9b2Fixture7GetAABBEv(ptr noundef nonnull align 8 dereferenceable(84)) #3 align 2

declare void @_ZN9b2Fixture10UpdateAABBEv(ptr noundef nonnull align 8 dereferenceable(84)) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN12b2BroadPhase15UpdateNoRebuildEP9b2Fixture(ptr noundef nonnull align 8 dereferenceable(137) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %11 = getelementptr inbounds %class.b2BroadPhase, ptr %10, i32 0, i32 10
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call noundef ptr @_ZN14b2IntHashTable3GetEP9b2Fixture(ptr noundef nonnull align 8 dereferenceable(12) %11, ptr noundef %12)
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %57

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.b2MapNode, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %22, ptr %8, align 4, !tbaa !12
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN9b2Fixture10UpdateAABBEv(ptr noundef nonnull align 8 dereferenceable(84) %23)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK9b2Fixture7GetAABBEv(ptr noundef nonnull align 8 dereferenceable(84) %24)
  %26 = getelementptr inbounds %class.b2BroadPhase, ptr %10, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %8, align 4, !tbaa !12
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.b2TreeNode, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.b2TreeNode, ptr %30, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %31, ptr align 4 %25, i64 16, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %32 = getelementptr inbounds %class.b2BroadPhase, ptr %10, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %8, align 4, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.b2TreeNode, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.b2TreeNode, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !23
  store ptr %38, ptr %9, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %42, %18
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %56

42:                                               ; preds = %39
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.b2TreeNode, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.b2TreeNode, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  %48 = getelementptr inbounds %struct.b2TreeNode, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.b2TreeNode, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !25
  %52 = getelementptr inbounds %struct.b2TreeNode, ptr %51, i32 0, i32 4
  call void @_ZN6b2AABB7CombineERKS_S1_(ptr noundef nonnull align 4 dereferenceable(16) %44, ptr noundef nonnull align 4 dereferenceable(16) %48, ptr noundef nonnull align 4 dereferenceable(16) %52)
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.b2TreeNode, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !23
  store ptr %55, ptr %9, align 8, !tbaa !5
  br label %39, !llvm.loop !26

56:                                               ; preds = %39
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %57

57:                                               ; preds = %56, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %58 = load i1, ptr %3, align 1
  ret i1 %58
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6b2AABB7CombineERKS_S1_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 #6 = { 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, !11, i64 4}
!10 = !{!"_ZTS9b2MapNode", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS12b2BroadPhase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !6, i64 80, !6, i64 88, !6, i64 96, !11, i64 104, !11, i64 108, !19, i64 112, !11, i64 128, !11, i64 132, !20, i64 136}
!15 = !{!"_ZTS10b2TreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !16, i64 32}
!16 = !{!"_ZTS6b2AABB", !17, i64 0, !17, i64 8}
!17 = !{!"_ZTS6b2Vec2", !18, i64 0, !18, i64 4}
!18 = !{!"float", !7, i64 0}
!19 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !11, i64 8}
!20 = !{!"bool", !7, i64 0}
!21 = !{i64 0, i64 4, !22, i64 4, i64 4, !22, i64 8, i64 4, !22, i64 12, i64 4, !22}
!22 = !{!18, !18, i64 0}
!23 = !{!15, !6, i64 16}
!24 = !{!15, !6, i64 0}
!25 = !{!15, !6, i64 8}
!26 = distinct !{!26, !27}
!27 = !{!"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"

%struct.b2TreeNode = type { ptr, ptr, ptr, ptr, %struct.b2AABB }
%struct.b2AABB = type { %struct.b2Vec2, %struct.b2Vec2 }
%struct.b2Vec2 = type { float, float }

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN14b2IntHashTable3GetEP9b2Fixture(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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 nonnull align 4 dereferenceable(16) ptr @_ZNK9b2Fixture7GetAABBEv(ptr noundef nonnull align 8 dereferenceable(84)) local_unnamed_addr #2 align 2

declare void @_ZN9b2Fixture10UpdateAABBEv(ptr noundef nonnull align 8 dereferenceable(84)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN12b2BroadPhase15UpdateNoRebuildEP9b2Fixture(ptr noundef nonnull align 8 dereferenceable(137) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 112
  %4 = tail call noundef ptr @_ZN14b2IntHashTable3GetEP9b2Fixture(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef %1)
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %.loopexit

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !9
  tail call void @_ZN9b2Fixture10UpdateAABBEv(ptr noundef nonnull align 8 dereferenceable(84) %1)
  %10 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK9b2Fixture7GetAABBEv(ptr noundef nonnull align 8 dereferenceable(84) %1)
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = sext i32 %9 to i64
  %13 = getelementptr inbounds %struct.b2TreeNode, ptr %11, i64 %12, i32 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef nonnull align 4 dereferenceable(16) %10, i64 16, i1 false), !tbaa.struct !20
  %14 = load ptr, ptr %0, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.b2TreeNode, ptr %14, i64 %12, i32 2
  %.015 = load ptr, ptr %15, align 8, !tbaa !22
  %.not16 = icmp eq ptr %.015, null
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.017 = phi ptr [ %.0, %.lr.ph ], [ %.015, %7 ]
  %16 = getelementptr inbounds i8, ptr %.017, i64 32
  %17 = load ptr, ptr %.017, align 8, !tbaa !23
  %18 = getelementptr inbounds i8, ptr %17, i64 32
  %19 = getelementptr inbounds i8, ptr %.017, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %20, i64 32
  tail call void @_ZN6b2AABB7CombineERKS_S1_(ptr noundef nonnull align 4 dereferenceable(16) %16, ptr noundef nonnull align 4 dereferenceable(16) %18, ptr noundef nonnull align 4 dereferenceable(16) %21)
  %22 = getelementptr inbounds i8, ptr %.017, i64 16
  %.0 = load ptr, ptr %22, align 8, !tbaa !22
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !25

.loopexit:                                        ; preds = %.lr.ph, %7, %2
  ret i1 %6
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6b2AABB7CombineERKS_S1_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #4 align 2

attributes #0 = { 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 = { mustprogress 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 = { "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"="64" "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"_ZTS9b2MapNode", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTS12b2BroadPhase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !6, i64 80, !6, i64 88, !6, i64 96, !11, i64 104, !11, i64 108, !18, i64 112, !11, i64 128, !11, i64 132, !19, i64 136}
!14 = !{!"_ZTS10b2TreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32}
!15 = !{!"_ZTS6b2AABB", !16, i64 0, !16, i64 8}
!16 = !{!"_ZTS6b2Vec2", !17, i64 0, !17, i64 4}
!17 = !{!"float", !7, i64 0}
!18 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !11, i64 8}
!19 = !{!"bool", !7, i64 0}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21, i64 8, i64 4, !21, i64 12, i64 4, !21}
!21 = !{!17, !17, i64 0}
!22 = !{!14, !6, i64 16}
!23 = !{!14, !6, i64 0}
!24 = !{!14, !6, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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