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

; 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] }>

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__._ZN12b2BroadPhaseC2Ei = external hidden unnamed_addr constant [34 x i8], align 1

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12b2BroadPhaseC2Ei(ptr noundef nonnull align 8 dereferenceable(137) %0, i32 noundef %1) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 4
  call void @_ZN10b2TreeNodeC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %8)
  %9 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 10
  %10 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN14b2IntHashTableC1Ei(ptr noundef nonnull align 8 dereferenceable(12) %9, i32 noundef %10)
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %16

14:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 97, ptr noundef @__PRETTY_FUNCTION__._ZN12b2BroadPhaseC2Ei) #3
  unreachable

15:                                               ; No predecessors!
  br label %16

16:                                               ; preds = %15, %13
  %17 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 12
  store i32 0, ptr %17, align 4, !tbaa !11
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 11
  store i32 %18, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 13
  store i8 0, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 3
  store ptr null, ptr %21, align 8, !tbaa !21
  %22 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 5
  store ptr null, ptr %22, align 8, !tbaa !22
  %23 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 6
  store ptr null, ptr %23, align 8, !tbaa !23
  %24 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 7
  store ptr null, ptr %24, align 8, !tbaa !24
  %25 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 11
  %26 = load i32, ptr %25, align 8, !tbaa !19
  %27 = sext i32 %26 to i64
  %28 = mul i64 %27, 8
  %29 = trunc i64 %28 to i32
  %30 = invoke noundef ptr @_Z7b2Alloci(i32 noundef %29)
          to label %31 unwind label %43

31:                                               ; preds = %16
  %32 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 1
  store ptr %30, ptr %32, align 8, !tbaa !25
  %33 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 11
  %34 = load i32, ptr %33, align 8, !tbaa !19
  %35 = mul nsw i32 %34, 2
  %36 = sext i32 %35 to i64
  %37 = mul i64 %36, 48
  %38 = trunc i64 %37 to i32
  %39 = invoke noundef ptr @_Z7b2Alloci(i32 noundef %38)
          to label %40 unwind label %43

40:                                               ; preds = %31
  %41 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !26
  %42 = getelementptr inbounds %class.b2BroadPhase, ptr %7, i32 0, i32 9
  store i32 -1, ptr %42, align 4, !tbaa !27
  ret void

43:                                               ; preds = %31, %16
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %5, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %6, align 4
  call void @_ZN14b2IntHashTableD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %9) #4
  br label %47

47:                                               ; preds = %43
  %48 = load ptr, ptr %5, align 8
  %49 = load i32, ptr %6, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare void @_ZN14b2IntHashTableC1Ei(ptr, i32)

declare void @_ZN14b2IntHashTableD1Ev(ptr)

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 = { 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 = { noreturn 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 = { noreturn nounwind }
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, !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 = !{!12, !10, i64 132}
!12 = !{!"_ZTS12b2BroadPhase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !10, i64 108, !17, i64 112, !10, i64 128, !10, i64 132, !18, i64 136}
!13 = !{!"_ZTS10b2TreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!14 = !{!"_ZTS6b2AABB", !15, i64 0, !15, i64 8}
!15 = !{!"_ZTS6b2Vec2", !16, i64 0, !16, i64 4}
!16 = !{!"float", !7, i64 0}
!17 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !10, i64 8}
!18 = !{!"bool", !7, i64 0}
!19 = !{!12, !10, i64 128}
!20 = !{!12, !18, i64 136}
!21 = !{!12, !6, i64 24}
!22 = !{!12, !6, i64 80}
!23 = !{!12, !6, i64 88}
!24 = !{!12, !6, i64 96}
!25 = !{!12, !6, i64 8}
!26 = !{!12, !6, i64 0}
!27 = !{!12, !10, i64 108}


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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__._ZN12b2BroadPhaseC2Ei = external hidden unnamed_addr constant [34 x i8], align 1

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12b2BroadPhaseC2Ei(ptr noundef nonnull align 8 dereferenceable(137) %0, i32 noundef %1) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @_ZN10b2TreeNodeC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %3)
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  tail call void @_ZN14b2IntHashTableC1Ei(ptr noundef nonnull align 8 dereferenceable(12) %4, i32 noundef %1)
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 97, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN12b2BroadPhaseC2Ei) #4
  unreachable

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 132
  store i32 0, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 %1, ptr %9, align 8, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 136
  store i8 0, ptr %10, align 8, !tbaa !18
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr null, ptr %11, align 8, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  %13 = shl i32 %1, 3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %12, i8 0, i64 24, i1 false)
  %14 = invoke noundef ptr @_Z7b2Alloci(i32 noundef %13)
          to label %15 unwind label %22

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %14, ptr %16, align 8, !tbaa !20
  %17 = load i32, ptr %9, align 8, !tbaa !17
  %18 = mul i32 %17, 96
  %19 = invoke noundef ptr @_Z7b2Alloci(i32 noundef %18)
          to label %20 unwind label %22

20:                                               ; preds = %15
  store ptr %19, ptr %0, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %0, i64 108
  store i32 -1, ptr %21, align 4, !tbaa !22
  ret void

22:                                               ; preds = %15, %7
  %23 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN14b2IntHashTableD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %4) #5
  resume { ptr, i32 } %23
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @_ZN14b2IntHashTableC1Ei(ptr, i32) local_unnamed_addr

declare void @_ZN14b2IntHashTableD1Ev(ptr) local_unnamed_addr

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


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