; LLVM IR from nbdd0121/GenerationalGC :: Handle.ll (ZN6norlit2gc6detail11HandleGroup8AllocateEv)

; 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.norlit::gc::detail::HandleGroup" = type { %"class.norlit::gc::Object.base", %"class.std::bitset", ptr, i64, [984 x ptr] }
%"class.norlit::gc::Object.base" = type <{ ptr, %union.anon, i8, i8, i8 }>
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr }
%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [16 x 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 noundef ptr @_ZN6norlit2gc6detail11HandleGroup8AllocateEv(ptr noundef nonnull align 8 dereferenceable(8048) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %28, %1
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 984
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %31

13:                                               ; preds = %9
  %14 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 1
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = call noundef zeroext i1 @_ZNKSt6bitsetILm984EE4testEm(ptr noundef nonnull align 8 dereferenceable(128) %14, i64 noundef %15)
  br i1 %16, label %27, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 1
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = call noundef nonnull align 8 dereferenceable(128) ptr @_ZNSt6bitsetILm984EE3setEmb(ptr noundef nonnull align 8 dereferenceable(128) %18, i64 noundef %19, i1 noundef zeroext true)
  %21 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 3
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = add i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !11
  %24 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 4
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds [984 x ptr], ptr %24, i64 0, i64 %25
  store ptr %26, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %31

27:                                               ; preds = %13
  br label %28

28:                                               ; preds = %27
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = add i64 %29, 1
  store i64 %30, ptr %4, align 8, !tbaa !9
  br label %9, !llvm.loop !18

31:                                               ; preds = %17, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %32 = load i32, ptr %5, align 4
  switch i32 %32, label %56 [
    i32 2, label %33
    i32 1, label %49
  ]

33:                                               ; preds = %31
  %34 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = icmp ne ptr %35, null
  br i1 %36, label %45, label %37

37:                                               ; preds = %33
  %38 = call noundef ptr @_ZN6norlit2gc6detail11HandleGroupnwEm(i64 noundef 8048)
  invoke void @_ZN6norlit2gc6detail11HandleGroupC1Ev(ptr noundef nonnull align 8 dereferenceable(8048) %38)
          to label %39 unwind label %41

39:                                               ; preds = %37
  %40 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 2
  store ptr %38, ptr %40, align 8, !tbaa !20
  br label %45

41:                                               ; preds = %37
  %42 = landingpad { ptr, i32 }
          cleanup
  %43 = extractvalue { ptr, i32 } %42, 0
  store ptr %43, ptr %6, align 8
  %44 = extractvalue { ptr, i32 } %42, 1
  store i32 %44, ptr %7, align 4
  call void @_ZN6norlit2gc6detail11HandleGroupdlEPv(ptr noundef %38) #3
  br label %51

45:                                               ; preds = %39, %33
  %46 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %8, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  %48 = call noundef ptr @_ZN6norlit2gc6detail11HandleGroup8AllocateEv(ptr noundef nonnull align 8 dereferenceable(8048) %47)
  store ptr %48, ptr %2, align 8
  br label %49

49:                                               ; preds = %45, %31
  %50 = load ptr, ptr %2, align 8
  ret ptr %50

51:                                               ; preds = %41
  %52 = load ptr, ptr %6, align 8
  %53 = load i32, ptr %7, align 4
  %54 = insertvalue { ptr, i32 } poison, ptr %52, 0
  %55 = insertvalue { ptr, i32 } %54, i32 %53, 1
  resume { ptr, i32 } %55

56:                                               ; preds = %31
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm984EE4testEm(ptr noundef nonnull align 8 dereferenceable(128), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(128) ptr @_ZNSt6bitsetILm984EE3setEmb(ptr noundef nonnull align 8 dereferenceable(128), i64 noundef, i1 noundef zeroext) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN6norlit2gc6detail11HandleGroupnwEm(i64 noundef) #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc6detail11HandleGroupdlEPv(ptr noundef) #2 align 2

declare void @_ZN6norlit2gc6detail11HandleGroupC1Ev(ptr)

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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 168}
!12 = !{!"_ZTSN6norlit2gc6detail11HandleGroupE", !13, i64 0, !16, i64 32, !6, i64 160, !10, i64 168, !7, i64 176}
!13 = !{!"_ZTSN6norlit2gc6ObjectE", !7, i64 8, !14, i64 24, !15, i64 25, !7, i64 26}
!14 = !{!"_ZTSN6norlit2gc5SpaceE", !7, i64 0}
!15 = !{!"_ZTSN6norlit2gc6StatusE", !7, i64 0}
!16 = !{!"_ZTSSt6bitsetILm984EE", !17, i64 0}
!17 = !{!"_ZTSSt12_Base_bitsetILm16EE", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !6, i64 160}


; 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 uwtable
define dso_local noundef nonnull ptr @_ZN6norlit2gc6detail11HandleGroup8AllocateEv(ptr noundef nonnull align 8 dereferenceable(8048) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %1
  %.tr = phi ptr [ %0, %1 ], [ %.tr.be, %tailrecurse.backedge ]
  %2 = getelementptr inbounds i8, ptr %.tr, i64 32
  br label %3

3:                                                ; preds = %tailrecurse, %5
  %.0918 = phi i64 [ 0, %tailrecurse ], [ %6, %5 ]
  %4 = tail call noundef zeroext i1 @_ZNKSt6bitsetILm984EE4testEm(ptr noundef nonnull align 8 dereferenceable(128) %2, i64 noundef %.0918)
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = add nuw nsw i64 %.0918, 1
  %exitcond.not = icmp eq i64 %6, 984
  br i1 %exitcond.not, label %14, label %3, !llvm.loop !5

7:                                                ; preds = %3
  %8 = tail call noundef nonnull align 8 dereferenceable(128) ptr @_ZNSt6bitsetILm984EE3setEmb(ptr noundef nonnull align 8 dereferenceable(128) %2, i64 noundef %.0918, i1 noundef zeroext true)
  %9 = getelementptr inbounds i8, ptr %.tr, i64 168
  %10 = load i64, ptr %9, align 8, !tbaa !7
  %11 = add i64 %10, 1
  store i64 %11, ptr %9, align 8, !tbaa !7
  %12 = getelementptr inbounds i8, ptr %.tr, i64 176
  %13 = getelementptr inbounds [984 x ptr], ptr %12, i64 0, i64 %.0918
  ret ptr %13

14:                                               ; preds = %5
  %15 = getelementptr inbounds i8, ptr %.tr, i64 160
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %17, label %tailrecurse.backedge

17:                                               ; preds = %14
  %18 = tail call noundef ptr @_ZN6norlit2gc6detail11HandleGroupnwEm(i64 noundef 8048)
  invoke void @_ZN6norlit2gc6detail11HandleGroupC1Ev(ptr noundef nonnull align 8 dereferenceable(8048) %18)
          to label %19 unwind label %20

19:                                               ; preds = %17
  store ptr %18, ptr %15, align 8, !tbaa !18
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %19, %14
  %.tr.be = phi ptr [ %18, %19 ], [ %16, %14 ]
  br label %tailrecurse

20:                                               ; preds = %17
  %21 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN6norlit2gc6detail11HandleGroupdlEPv(ptr noundef %18) #2
  resume { ptr, i32 } %21
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm984EE4testEm(ptr noundef nonnull align 8 dereferenceable(128), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(128) ptr @_ZNSt6bitsetILm984EE3setEmb(ptr noundef nonnull align 8 dereferenceable(128), i64 noundef, i1 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN6norlit2gc6detail11HandleGroupnwEm(i64 noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc6detail11HandleGroupdlEPv(ptr noundef) local_unnamed_addr #1 align 2

declare void @_ZN6norlit2gc6detail11HandleGroupC1Ev(ptr) local_unnamed_addr

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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !17, i64 168}
!8 = !{!"_ZTSN6norlit2gc6detail11HandleGroupE", !9, i64 0, !14, i64 32, !16, i64 160, !17, i64 168, !10, i64 176}
!9 = !{!"_ZTSN6norlit2gc6ObjectE", !10, i64 8, !12, i64 24, !13, i64 25, !10, i64 26}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN6norlit2gc5SpaceE", !10, i64 0}
!13 = !{!"_ZTSN6norlit2gc6StatusE", !10, i64 0}
!14 = !{!"_ZTSSt6bitsetILm984EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Base_bitsetILm16EE", !10, i64 0}
!16 = !{!"any pointer", !10, i64 0}
!17 = !{!"long", !10, i64 0}
!18 = !{!8, !16, i64 160}


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