; LLVM IR from mtsamis/box2d-optimized :: src/dynamics/b2_world.ll (ZN7b2World9QueryAABBEP15b2QueryCallbackRK6b2AABB)

; 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.b2WorldQueryWrapper = type { ptr, ptr }
%class.b2World = type { %class.b2BlockAllocator, %class.b2StackAllocator, %class.b2ContactManager, ptr, ptr, ptr, ptr, i32, i32, %struct.b2Vec2, i8, ptr, ptr, float, i8, i8, i8, i8, i8, i8, i8, i8, %struct.b2Profile }
%class.b2BlockAllocator = type { ptr, i32, i32, [14 x ptr] }
%class.b2StackAllocator = type <{ [102400 x i8], i32, i32, i32, [4 x i8], [32 x %struct.b2StackEntry], i32, [4 x i8] }>
%struct.b2StackEntry = type { ptr, i32, i8 }
%class.b2ContactManager = type { %class.b2BroadPhase, i32, ptr, ptr, ptr, ptr }
%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 }
%class.b2IntHashTable = type <{ ptr, i32, [4 x i8] }>
%struct.b2Vec2 = type { float, float }
%struct.b2Profile = type { float, float, 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN16b2ParticleSystem7GetNextEv(ptr noundef nonnull align 8 dereferenceable(632)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7b2World9QueryAABBEP15b2QueryCallbackRK6b2AABB(ptr noundef nonnull align 8 dereferenceable(103352) %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(16) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.b2WorldQueryWrapper, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %10 = getelementptr inbounds %class.b2World, ptr %9, i32 0, i32 2
  %11 = getelementptr inbounds %class.b2ContactManager, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct.b2WorldQueryWrapper, ptr %7, i32 0, i32 0
  store ptr %11, ptr %12, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.b2WorldQueryWrapper, ptr %7, i32 0, i32 1
  store ptr %13, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %class.b2World, ptr %9, i32 0, i32 2
  %16 = getelementptr inbounds %class.b2ContactManager, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN12b2BroadPhase5QueryI19b2WorldQueryWrapperEEvPT_RK6b2AABB(ptr noundef nonnull align 8 dereferenceable(137) %16, ptr noundef %7, ptr noundef nonnull align 4 dereferenceable(16) %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %18 = getelementptr inbounds %class.b2World, ptr %9, i32 0, i32 6
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  store ptr %19, ptr %8, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %36, %3
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %39

24:                                               ; preds = %20
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %25, align 8, !tbaa !26
  %28 = getelementptr inbounds ptr, ptr %27, i64 4
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef zeroext i1 %29(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef %26)
  br i1 %30, label %31, label %35

31:                                               ; preds = %24
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZNK16b2ParticleSystem9QueryAABBEP15b2QueryCallbackRK6b2AABB(ptr noundef nonnull align 8 dereferenceable(632) %32, ptr noundef %33, ptr noundef nonnull align 4 dereferenceable(16) %34)
  br label %35

35:                                               ; preds = %31, %24
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call noundef ptr @_ZN16b2ParticleSystem7GetNextEv(ptr noundef nonnull align 8 dereferenceable(632) %37)
  store ptr %38, ptr %8, align 8, !tbaa !5
  br label %20, !llvm.loop !28

39:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN12b2BroadPhase5QueryI19b2WorldQueryWrapperEEvPT_RK6b2AABB(ptr noundef nonnull align 8 dereferenceable(137), ptr noundef, ptr noundef nonnull align 4 dereferenceable(16)) #3 align 2

declare void @_ZNK16b2ParticleSystem9QueryAABBEP15b2QueryCallbackRK6b2AABB(ptr noundef nonnull align 8 dereferenceable(632), ptr noundef, ptr noundef nonnull align 4 dereferenceable(16)) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS19b2WorldQueryWrapper", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 103272}
!13 = !{!"_ZTS7b2World", !14, i64 0, !16, i64 128, !17, i64 103064, !6, i64 103248, !6, i64 103256, !6, i64 103264, !6, i64 103272, !15, i64 103280, !15, i64 103284, !21, i64 103288, !24, i64 103296, !6, i64 103304, !6, i64 103312, !22, i64 103320, !24, i64 103324, !24, i64 103325, !24, i64 103326, !24, i64 103327, !24, i64 103328, !24, i64 103329, !24, i64 103330, !24, i64 103331, !25, i64 103332}
!14 = !{!"_ZTS16b2BlockAllocator", !6, i64 0, !15, i64 8, !15, i64 12, !7, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTS16b2StackAllocator", !7, i64 0, !15, i64 102400, !15, i64 102404, !15, i64 102408, !7, i64 102416, !15, i64 102928}
!17 = !{!"_ZTS16b2ContactManager", !18, i64 0, !15, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176}
!18 = !{!"_ZTS12b2BroadPhase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !19, i64 32, !6, i64 80, !6, i64 88, !6, i64 96, !15, i64 104, !15, i64 108, !23, i64 112, !15, i64 128, !15, i64 132, !24, i64 136}
!19 = !{!"_ZTS10b2TreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !20, i64 32}
!20 = !{!"_ZTS6b2AABB", !21, i64 0, !21, i64 8}
!21 = !{!"_ZTS6b2Vec2", !22, i64 0, !22, i64 4}
!22 = !{!"float", !7, i64 0}
!23 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !15, i64 8}
!24 = !{!"bool", !7, i64 0}
!25 = !{!"_ZTS9b2Profile", !22, i64 0, !22, i64 4, !22, i64 8, !22, i64 12, !22, i64 16}
!26 = !{!27, !27, i64 0}
!27 = !{!"vtable pointer", !8, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"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.b2WorldQueryWrapper = type { ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7b2World9QueryAABBEP15b2QueryCallbackRK6b2AABB(ptr noundef nonnull align 8 dereferenceable(103352) %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(16) %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %struct.b2WorldQueryWrapper, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 103064
  store ptr %5, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %1, ptr %6, align 8, !tbaa !10
  call void @_ZN12b2BroadPhase5QueryI19b2WorldQueryWrapperEEvPT_RK6b2AABB(ptr noundef nonnull align 8 dereferenceable(137) %5, ptr noundef nonnull %4, ptr noundef nonnull align 4 dereferenceable(16) %2)
  %7 = getelementptr inbounds i8, ptr %0, i64 103272
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not10 = icmp eq ptr %8, null
  br i1 %.not10, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %14, %3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  ret void

.lr.ph:                                           ; preds = %3, %14
  %.011 = phi ptr [ %15, %14 ], [ %8, %3 ]
  %9 = load ptr, ptr %1, align 8, !tbaa !25
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = load ptr, ptr %10, align 8
  %12 = call noundef zeroext i1 %11(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %.011)
  br i1 %12, label %13, label %14

13:                                               ; preds = %.lr.ph
  call void @_ZNK16b2ParticleSystem9QueryAABBEP15b2QueryCallbackRK6b2AABB(ptr noundef nonnull align 8 dereferenceable(632) %.011, ptr noundef nonnull %1, ptr noundef nonnull align 4 dereferenceable(16) %2)
  br label %14

14:                                               ; preds = %.lr.ph, %13
  %15 = call noundef ptr @_ZN16b2ParticleSystem7GetNextEv(ptr noundef nonnull align 8 dereferenceable(632) %.011)
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !27
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN12b2BroadPhase5QueryI19b2WorldQueryWrapperEEvPT_RK6b2AABB(ptr noundef nonnull align 8 dereferenceable(137), ptr noundef, ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #3 align 2

declare void @_ZNK16b2ParticleSystem9QueryAABBEP15b2QueryCallbackRK6b2AABB(ptr noundef nonnull align 8 dereferenceable(632), ptr noundef, ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS19b2WorldQueryWrapper", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !7, i64 103272}
!12 = !{!"_ZTS7b2World", !13, i64 0, !15, i64 128, !16, i64 103064, !7, i64 103248, !7, i64 103256, !7, i64 103264, !7, i64 103272, !14, i64 103280, !14, i64 103284, !20, i64 103288, !23, i64 103296, !7, i64 103304, !7, i64 103312, !21, i64 103320, !23, i64 103324, !23, i64 103325, !23, i64 103326, !23, i64 103327, !23, i64 103328, !23, i64 103329, !23, i64 103330, !23, i64 103331, !24, i64 103332}
!13 = !{!"_ZTS16b2BlockAllocator", !7, i64 0, !14, i64 8, !14, i64 12, !8, i64 16}
!14 = !{!"int", !8, i64 0}
!15 = !{!"_ZTS16b2StackAllocator", !8, i64 0, !14, i64 102400, !14, i64 102404, !14, i64 102408, !8, i64 102416, !14, i64 102928}
!16 = !{!"_ZTS16b2ContactManager", !17, i64 0, !14, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176}
!17 = !{!"_ZTS12b2BroadPhase", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !18, i64 32, !7, i64 80, !7, i64 88, !7, i64 96, !14, i64 104, !14, i64 108, !22, i64 112, !14, i64 128, !14, i64 132, !23, i64 136}
!18 = !{!"_ZTS10b2TreeNode", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !19, i64 32}
!19 = !{!"_ZTS6b2AABB", !20, i64 0, !20, i64 8}
!20 = !{!"_ZTS6b2Vec2", !21, i64 0, !21, i64 4}
!21 = !{!"float", !8, i64 0}
!22 = !{!"_ZTS14b2IntHashTable", !7, i64 0, !14, i64 8}
!23 = !{!"bool", !8, i64 0}
!24 = !{!"_ZTS9b2Profile", !21, i64 0, !21, i64 4, !21, i64 8, !21, i64 12, !21, i64 16}
!25 = !{!26, !26, i64 0}
!26 = !{!"vtable pointer", !9, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


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