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

; 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.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 }
%class.b2Contact = type { ptr, ptr, ptr, ptr, ptr, %struct.b2Manifold, i32, i32, float, float, float, float }
%struct.b2Manifold = type { [2 x %struct.b2ManifoldPoint], %struct.b2Vec2, %struct.b2Vec2, i32, i32 }
%struct.b2ManifoldPoint = type { %struct.b2Vec2, float, float, %union.b2ContactID }
%union.b2ContactID = type { i32 }
%class.b2Body = type { i32, i16, i32, %struct.b2Transform, %struct.b2Transform, %struct.b2Sweep, %struct.b2Vec2, float, %struct.b2Vec2, float, ptr, ptr, ptr, ptr, i32, ptr, ptr, i32, i32, float, float, float, float, float, float, float, float, %struct.b2BodyUserData }
%struct.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Rot = type { float, float }
%struct.b2Sweep = type { %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, float, float, float }
%struct.b2BodyUserData = type { i64 }

; 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
define dso_local void @_ZN7b2World18RemoveDeadContactsEv(ptr noundef nonnull align 8 dereferenceable(103352) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %8 = getelementptr inbounds %class.b2World, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %57, %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %61

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !23
  br label %15

15:                                               ; preds = %53, %14
  %16 = load i32, ptr %5, align 4, !tbaa !23
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call noundef i32 @_ZN6b2Body15GetContactCountEv(ptr noundef nonnull align 8 dereferenceable(208) %17)
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %56

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !23
  %24 = call noundef ptr @_ZN6b2Body10GetContactEi(ptr noundef nonnull align 8 dereferenceable(208) %22, i32 noundef %23)
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.b2Contact, ptr %25, i32 0, i32 6
  %27 = load i32, ptr %26, align 8, !tbaa !24
  %28 = and i32 %27, 2
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %52

30:                                               ; preds = %21
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.b2Body, ptr %31, i32 0, i32 17
  %33 = load i32, ptr %32, align 8, !tbaa !28
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %32, align 8, !tbaa !28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.b2Body, ptr %35, i32 0, i32 16
  %37 = load ptr, ptr %36, align 8, !tbaa !37
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.b2Body, ptr %38, i32 0, i32 17
  %40 = load i32, ptr %39, align 8, !tbaa !28
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %37, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %class.b2Body, ptr %44, i32 0, i32 16
  %46 = load ptr, ptr %45, align 8, !tbaa !37
  %47 = load i32, ptr %5, align 4, !tbaa !23
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  store ptr %43, ptr %49, align 8, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !23
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %5, align 4, !tbaa !23
  br label %52

52:                                               ; preds = %30, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !23
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !23
  br label %15, !llvm.loop !38

56:                                               ; preds = %20
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %class.b2Body, ptr %58, i32 0, i32 12
  %60 = load ptr, ptr %59, align 8, !tbaa !40
  store ptr %60, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !41

61:                                               ; preds = %13
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6b2Body10GetContactEi(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef) #2 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 = { 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 = { 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 103248}
!10 = !{!"_ZTS7b2World", !11, i64 0, !13, i64 128, !14, i64 103064, !6, i64 103248, !6, i64 103256, !6, i64 103264, !6, i64 103272, !12, i64 103280, !12, i64 103284, !18, i64 103288, !21, i64 103296, !6, i64 103304, !6, i64 103312, !19, i64 103320, !21, i64 103324, !21, i64 103325, !21, i64 103326, !21, i64 103327, !21, i64 103328, !21, i64 103329, !21, i64 103330, !21, i64 103331, !22, i64 103332}
!11 = !{!"_ZTS16b2BlockAllocator", !6, i64 0, !12, i64 8, !12, i64 12, !7, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS16b2StackAllocator", !7, i64 0, !12, i64 102400, !12, i64 102404, !12, i64 102408, !7, i64 102416, !12, i64 102928}
!14 = !{!"_ZTS16b2ContactManager", !15, i64 0, !12, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176}
!15 = !{!"_ZTS12b2BroadPhase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !16, i64 32, !6, i64 80, !6, i64 88, !6, i64 96, !12, i64 104, !12, i64 108, !20, i64 112, !12, i64 128, !12, i64 132, !21, i64 136}
!16 = !{!"_ZTS10b2TreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !17, i64 32}
!17 = !{!"_ZTS6b2AABB", !18, i64 0, !18, i64 8}
!18 = !{!"_ZTS6b2Vec2", !19, i64 0, !19, i64 4}
!19 = !{!"float", !7, i64 0}
!20 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !12, i64 8}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"_ZTS9b2Profile", !19, i64 0, !19, i64 4, !19, i64 8, !19, i64 12, !19, i64 16}
!23 = !{!12, !12, i64 0}
!24 = !{!25, !12, i64 104}
!25 = !{!"_ZTS9b2Contact", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !26, i64 40, !12, i64 104, !12, i64 108, !19, i64 112, !19, i64 116, !19, i64 120, !19, i64 124}
!26 = !{!"_ZTS10b2Manifold", !7, i64 0, !18, i64 40, !18, i64 48, !27, i64 56, !12, i64 60}
!27 = !{!"_ZTSN10b2Manifold4TypeE", !7, i64 0}
!28 = !{!29, !12, i64 160}
!29 = !{!"_ZTS6b2Body", !30, i64 0, !31, i64 4, !12, i64 8, !32, i64 12, !32, i64 28, !34, i64 44, !18, i64 80, !19, i64 88, !18, i64 92, !19, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !6, i64 144, !6, i64 152, !12, i64 160, !12, i64 164, !19, i64 168, !19, i64 172, !19, i64 176, !19, i64 180, !19, i64 184, !19, i64 188, !19, i64 192, !19, i64 196, !35, i64 200}
!30 = !{!"_ZTS10b2BodyType", !7, i64 0}
!31 = !{!"short", !7, i64 0}
!32 = !{!"_ZTS11b2Transform", !18, i64 0, !33, i64 8}
!33 = !{!"_ZTS5b2Rot", !19, i64 0, !19, i64 4}
!34 = !{!"_ZTS7b2Sweep", !18, i64 0, !18, i64 8, !18, i64 16, !19, i64 24, !19, i64 28, !19, i64 32}
!35 = !{!"_ZTS14b2BodyUserData", !36, i64 0}
!36 = !{!"long", !7, i64 0}
!37 = !{!29, !6, i64 152}
!38 = distinct !{!38, !39}
!39 = !{!"llvm.loop.mustprogress"}
!40 = !{!29, !6, i64 120}
!41 = distinct !{!41, !39}


; 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: mustprogress nounwind uwtable
define dso_local void @_ZN7b2World18RemoveDeadContactsEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(103352) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 103248
  %.016 = load ptr, ptr %2, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge19, label %.preheader

.preheader:                                       ; preds = %1, %._crit_edge
  %.018 = phi ptr [ %.0, %._crit_edge ], [ %.016, %1 ]
  %3 = tail call noundef i32 @_ZN6b2Body15GetContactCountEv(ptr noundef nonnull align 8 dereferenceable(208) %.018)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %5 = getelementptr inbounds i8, ptr %.018, i64 160
  %6 = getelementptr inbounds i8, ptr %.018, i64 152
  br label %8

._crit_edge19:                                    ; preds = %._crit_edge, %1
  ret void

._crit_edge:                                      ; preds = %24, %.preheader
  %7 = getelementptr inbounds i8, ptr %.018, i64 120
  %.0 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge19, label %.preheader, !llvm.loop !9

8:                                                ; preds = %.lr.ph, %24
  %.01415 = phi i32 [ 0, %.lr.ph ], [ %25, %24 ]
  %9 = tail call noundef ptr @_ZN6b2Body10GetContactEi(ptr noundef nonnull align 8 dereferenceable(208) %.018, i32 noundef %.01415)
  %10 = getelementptr inbounds i8, ptr %9, i64 104
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = and i32 %11, 2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %24

14:                                               ; preds = %8
  %15 = load i32, ptr %5, align 8, !tbaa !18
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %5, align 8, !tbaa !18
  %17 = load ptr, ptr %6, align 8, !tbaa !27
  %18 = sext i32 %16 to i64
  %19 = getelementptr inbounds ptr, ptr %17, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = sext i32 %.01415 to i64
  %22 = getelementptr inbounds ptr, ptr %17, i64 %21
  store ptr %20, ptr %22, align 8, !tbaa !5
  %23 = add nsw i32 %.01415, -1
  br label %24

24:                                               ; preds = %14, %8
  %.1 = phi i32 [ %23, %14 ], [ %.01415, %8 ]
  %25 = add nsw i32 %.1, 1
  %26 = tail call noundef i32 @_ZN6b2Body15GetContactCountEv(ptr noundef nonnull align 8 dereferenceable(208) %.018)
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %8, label %._crit_edge, !llvm.loop !28
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6b2Body10GetContactEi(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef) local_unnamed_addr #1 align 2

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !17, i64 104}
!12 = !{!"_ZTS9b2Contact", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !17, i64 104, !17, i64 108, !15, i64 112, !15, i64 116, !15, i64 120, !15, i64 124}
!13 = !{!"_ZTS10b2Manifold", !7, i64 0, !14, i64 40, !14, i64 48, !16, i64 56, !17, i64 60}
!14 = !{!"_ZTS6b2Vec2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTSN10b2Manifold4TypeE", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!19, !17, i64 160}
!19 = !{!"_ZTS6b2Body", !20, i64 0, !21, i64 4, !17, i64 8, !22, i64 12, !22, i64 28, !24, i64 44, !14, i64 80, !15, i64 88, !14, i64 92, !15, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !17, i64 136, !6, i64 144, !6, i64 152, !17, i64 160, !17, i64 164, !15, i64 168, !15, i64 172, !15, i64 176, !15, i64 180, !15, i64 184, !15, i64 188, !15, i64 192, !15, i64 196, !25, i64 200}
!20 = !{!"_ZTS10b2BodyType", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!"_ZTS11b2Transform", !14, i64 0, !23, i64 8}
!23 = !{!"_ZTS5b2Rot", !15, i64 0, !15, i64 4}
!24 = !{!"_ZTS7b2Sweep", !14, i64 0, !14, i64 8, !14, i64 16, !15, i64 24, !15, i64 28, !15, i64 32}
!25 = !{!"_ZTS14b2BodyUserData", !26, i64 0}
!26 = !{!"long", !7, i64 0}
!27 = !{!19, !6, i64 152}
!28 = distinct !{!28, !10}


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