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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14b2IntHashTable4GrowEv(ptr noundef nonnull align 8 dereferenceable(12) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %10 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = mul nsw i32 %11, 2
  store i32 %12, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %13 = load i32, ptr %3, align 4, !tbaa !12
  %14 = sext i32 %13 to i64
  %15 = mul i64 %14, 8
  %16 = trunc i64 %15 to i32
  %17 = call noundef ptr @_Z7b2Alloci(i32 noundef %16)
  store ptr %17, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %18

18:                                               ; preds = %80, %1
  %19 = load i32, ptr %5, align 4, !tbaa !12
  %20 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %83

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %25 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %5, align 4, !tbaa !12
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %58, %24
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %61

35:                                               ; preds = %32
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.b2MapNode, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = call noundef i32 @_Z4hashj(i32 noundef %38)
  %40 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = and i32 %39, %41
  %43 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = icmp eq i32 %42, %44
  br i1 %45, label %46, label %55

46:                                               ; preds = %35
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.b2MapNode, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %49, ptr %50, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.b2MapNode, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !16
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %54, ptr %8, align 8, !tbaa !5
  br label %58

55:                                               ; preds = %35
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.b2MapNode, ptr %56, i32 0, i32 2
  store ptr %57, ptr %6, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %55, %46
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  store ptr %60, ptr %7, align 8, !tbaa !5
  br label %32, !llvm.loop !17

61:                                               ; preds = %32
  %62 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = load i32, ptr %5, align 4, !tbaa !12
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i32, ptr %5, align 4, !tbaa !12
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  store ptr %67, ptr %71, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !12
  %75 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !9
  %77 = add nsw i32 %74, %76
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds ptr, ptr %73, i64 %78
  store ptr %72, ptr %79, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %80

80:                                               ; preds = %61
  %81 = load i32, ptr %5, align 4, !tbaa !12
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !12
  br label %18, !llvm.loop !19

83:                                               ; preds = %23
  %84 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  call void @_Z6b2FreePv(ptr noundef %85)
  %86 = load i32, ptr %3, align 4, !tbaa !12
  %87 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 1
  store i32 %86, ptr %87, align 8, !tbaa !9
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %class.b2IntHashTable, ptr %9, i32 0, i32 0
  store ptr %88, ptr %89, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4hashj(i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 8}
!10 = !{!"_ZTS14b2IntHashTable", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTS9b2MapNode", !11, i64 0, !11, i64 4, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z7b2Alloci(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14b2IntHashTable4GrowEv(ptr nocapture noundef nonnull align 8 dereferenceable(12) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = shl i32 %3, 4
  %5 = tail call noundef ptr @_Z7b2Alloci(i32 noundef %4)
  %6 = load i32, ptr %2, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph33, label %._crit_edge34

._crit_edge34:                                    ; preds = %._crit_edge, %1
  %8 = shl nsw i32 %3, 1
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @_Z6b2FreePv(ptr noundef %9)
  store i32 %8, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr %0, align 8, !tbaa !11
  ret void

.lr.ph33:                                         ; preds = %1, %._crit_edge
  %10 = phi i32 [ %22, %._crit_edge ], [ %6, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %1 ]
  %11 = load ptr, ptr %0, align 8, !tbaa !11
  %12 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv
  %.02226 = load ptr, ptr %12, align 8, !tbaa !12
  %.not27 = icmp eq ptr %.02226, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph33, %21
  %.02230 = phi ptr [ %.022, %21 ], [ %.02226, %.lr.ph33 ]
  %.029 = phi ptr [ %.1, %21 ], [ null, %.lr.ph33 ]
  %.02328 = phi ptr [ %.124, %21 ], [ %12, %.lr.ph33 ]
  %13 = load i32, ptr %.02230, align 8, !tbaa !13
  %14 = tail call noundef i32 @_Z4hashj(i32 noundef %13)
  %15 = load i32, ptr %2, align 8, !tbaa !5
  %16 = and i32 %15, %14
  %17 = icmp eq i32 %16, %15
  %18 = getelementptr inbounds i8, ptr %.02230, i64 8
  br i1 %17, label %19, label %21

19:                                               ; preds = %.lr.ph
  %20 = load ptr, ptr %18, align 8, !tbaa !15
  store ptr %20, ptr %.02328, align 8, !tbaa !12
  store ptr %.029, ptr %18, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %.lr.ph, %19
  %.124 = phi ptr [ %.02328, %19 ], [ %18, %.lr.ph ]
  %.1 = phi ptr [ %.02230, %19 ], [ %.029, %.lr.ph ]
  %.022 = load ptr, ptr %.124, align 8, !tbaa !12
  %.not = icmp eq ptr %.022, null
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %21
  %.pre = load ptr, ptr %0, align 8, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds ptr, ptr %.pre, i64 %indvars.iv
  %.pre36 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph33
  %22 = phi i32 [ %10, %.lr.ph33 ], [ %15, %._crit_edge.loopexit ]
  %23 = phi ptr [ null, %.lr.ph33 ], [ %.pre36, %._crit_edge.loopexit ]
  %.0.lcssa = phi ptr [ null, %.lr.ph33 ], [ %.1, %._crit_edge.loopexit ]
  %24 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv
  store ptr %23, ptr %24, align 8, !tbaa !12
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = add nsw i32 %22, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds ptr, ptr %5, i64 %27
  store ptr %.0.lcssa, ptr %28, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = sext i32 %22 to i64
  %30 = icmp slt i64 %indvars.iv.next, %29
  br i1 %30, label %.lr.ph33, label %._crit_edge34, !llvm.loop !18
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4hashj(i32 noundef) local_unnamed_addr #2

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 = { 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, !10, i64 8}
!6 = !{!"_ZTS14b2IntHashTable", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS9b2MapNode", !10, i64 0, !10, i64 4, !7, i64 8}
!15 = !{!14, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass