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

; 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.b2ContactFilter = type { ptr }
%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 }
%struct.b2Vec2 = type { float, float }
%class.b2IntHashTable = type <{ ptr, i32, [4 x i8] }>
%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 }

@b2_defaultFilter = external dso_local global %class.b2ContactFilter, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16b2ContactManagerC2Ev(ptr noundef nonnull align 8 dereferenceable(184) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 0
  call void @_ZN12b2BroadPhaseC2Ev(ptr noundef nonnull align 8 dereferenceable(137) %6)
  %7 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 1
  store i32 0, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 2
  store ptr @b2_defaultFilter, ptr %8, align 8, !tbaa !19
  %9 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 3
  store ptr null, ptr %9, align 8, !tbaa !20
  %10 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 4
  store ptr null, ptr %10, align 8, !tbaa !21
  %11 = invoke noundef ptr @_Z7b2Alloci(i32 noundef 128)
          to label %12 unwind label %30

12:                                               ; preds = %1
  %13 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  store ptr %11, ptr %13, align 8, !tbaa !22
  %14 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !22
  %18 = getelementptr inbounds %class.b2Contact, ptr %17, i32 0, i32 2
  store ptr %15, ptr %18, align 8, !tbaa !23
  %19 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %21 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = getelementptr inbounds %class.b2Contact, ptr %22, i32 0, i32 1
  store ptr %20, ptr %23, align 8, !tbaa !27
  %24 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  %26 = getelementptr inbounds %class.b2Contact, ptr %25, i32 0, i32 3
  store ptr null, ptr %26, align 8, !tbaa !28
  %27 = getelementptr inbounds %class.b2ContactManager, ptr %5, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = getelementptr inbounds %class.b2Contact, ptr %28, i32 0, i32 4
  store ptr null, ptr %29, align 8, !tbaa !29
  ret void

30:                                               ; preds = %1
  %31 = landingpad { ptr, i32 }
          cleanup
  %32 = extractvalue { ptr, i32 } %31, 0
  store ptr %32, ptr %3, align 8
  %33 = extractvalue { ptr, i32 } %31, 1
  store i32 %33, ptr %4, align 4
  call void @_ZN12b2BroadPhaseD1Ev(ptr noundef nonnull align 8 dereferenceable(137) %6) #3
  br label %34

34:                                               ; preds = %30
  %35 = load ptr, ptr %3, align 8
  %36 = load i32, ptr %4, align 4
  %37 = insertvalue { ptr, i32 } poison, ptr %35, 0
  %38 = insertvalue { ptr, i32 } %37, i32 %36, 1
  resume { ptr, i32 } %38
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12b2BroadPhaseC2Ev(ptr noundef nonnull align 8 dereferenceable(137)) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z7b2Alloci(i32 noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN12b2BroadPhaseD1Ev(ptr noundef nonnull align 8 dereferenceable(137)) unnamed_addr #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 = { 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 #2 = { nounwind "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, !16, i64 144}
!10 = !{!"_ZTS16b2ContactManager", !11, i64 0, !16, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176}
!11 = !{!"_ZTS12b2BroadPhase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !6, i64 80, !6, i64 88, !6, i64 96, !16, i64 104, !16, i64 108, !17, i64 112, !16, i64 128, !16, i64 132, !18, i64 136}
!12 = !{!"_ZTS10b2TreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32}
!13 = !{!"_ZTS6b2AABB", !14, i64 0, !14, i64 8}
!14 = !{!"_ZTS6b2Vec2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !16, i64 8}
!18 = !{!"bool", !7, i64 0}
!19 = !{!10, !6, i64 152}
!20 = !{!10, !6, i64 160}
!21 = !{!10, !6, i64 168}
!22 = !{!10, !6, i64 176}
!23 = !{!24, !6, i64 16}
!24 = !{!"_ZTS9b2Contact", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !25, i64 40, !16, i64 104, !16, i64 108, !15, i64 112, !15, i64 116, !15, i64 120, !15, i64 124}
!25 = !{!"_ZTS10b2Manifold", !7, i64 0, !14, i64 40, !14, i64 48, !26, i64 56, !16, i64 60}
!26 = !{!"_ZTSN10b2Manifold4TypeE", !7, i64 0}
!27 = !{!24, !6, i64 8}
!28 = !{!24, !6, i64 24}
!29 = !{!24, !6, i64 32}


; 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.b2ContactFilter = type { ptr }

@b2_defaultFilter = external dso_local global %class.b2ContactFilter, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16b2ContactManagerC2Ev(ptr noundef nonnull align 8 dereferenceable(184) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN12b2BroadPhaseC2Ev(ptr noundef nonnull align 8 dereferenceable(137) %0)
  %2 = getelementptr inbounds i8, ptr %0, i64 144
  store i32 0, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr @b2_defaultFilter, ptr %3, align 8, !tbaa !18
  %4 = getelementptr inbounds i8, ptr %0, i64 160
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  %5 = invoke noundef ptr @_Z7b2Alloci(i32 noundef 128)
          to label %6 unwind label %11

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 176
  store ptr %5, ptr %7, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %5, ptr %8, align 8, !tbaa !20
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %5, ptr %9, align 8, !tbaa !24
  %10 = getelementptr inbounds i8, ptr %5, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, i8 0, i64 16, i1 false)
  ret void

11:                                               ; preds = %1
  %12 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN12b2BroadPhaseD1Ev(ptr noundef nonnull align 8 dereferenceable(137) %0) #4
  resume { ptr, i32 } %12
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12b2BroadPhaseC2Ev(ptr noundef nonnull align 8 dereferenceable(137)) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z7b2Alloci(i32 noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN12b2BroadPhaseD1Ev(ptr noundef nonnull align 8 dereferenceable(137)) unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { 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 #2 = { nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !15, i64 144}
!6 = !{!"_ZTS16b2ContactManager", !7, i64 0, !15, i64 144, !8, i64 152, !8, i64 160, !8, i64 168, !8, i64 176}
!7 = !{!"_ZTS12b2BroadPhase", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !11, i64 32, !8, i64 80, !8, i64 88, !8, i64 96, !15, i64 104, !15, i64 108, !16, i64 112, !15, i64 128, !15, i64 132, !17, i64 136}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTS10b2TreeNode", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !12, i64 32}
!12 = !{!"_ZTS6b2AABB", !13, i64 0, !13, i64 8}
!13 = !{!"_ZTS6b2Vec2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !9, i64 0}
!15 = !{!"int", !9, i64 0}
!16 = !{!"_ZTS14b2IntHashTable", !8, i64 0, !15, i64 8}
!17 = !{!"bool", !9, i64 0}
!18 = !{!6, !8, i64 152}
!19 = !{!6, !8, i64 176}
!20 = !{!21, !8, i64 16}
!21 = !{!"_ZTS9b2Contact", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !22, i64 40, !15, i64 104, !15, i64 108, !14, i64 112, !14, i64 116, !14, i64 120, !14, i64 124}
!22 = !{!"_ZTS10b2Manifold", !9, i64 0, !13, i64 40, !13, i64 48, !23, i64 56, !15, i64 60}
!23 = !{!"_ZTSN10b2Manifold4TypeE", !9, i64 0}
!24 = !{!21, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass