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

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

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE = external hidden unnamed_addr constant [54 x i8], align 1

; 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 @_ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE(ptr noundef nonnull align 8 dereferenceable(8048) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 4
  %10 = getelementptr inbounds [984 x ptr], ptr %9, i64 0, i64 0
  %11 = ptrtoint ptr %8 to i64
  %12 = ptrtoint ptr %10 to i64
  %13 = sub i64 %11, %12
  %14 = sdiv exact i64 %13, 8
  store i64 %14, ptr %5, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp sge i64 %15, 0
  br i1 %16, label %17, label %28

17:                                               ; preds = %2
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = icmp slt i64 %18, 984
  br i1 %19, label %20, label %28

20:                                               ; preds = %17
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN6norlit2gc6detail11HandleGroup5WriteEPPNS0_6ObjectES4_(ptr noundef nonnull align 8 dereferenceable(8048) %7, ptr noundef %21, ptr noundef null)
  %22 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 1
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = call noundef nonnull align 8 dereferenceable(128) ptr @_ZNSt6bitsetILm984EE5resetEm(ptr noundef nonnull align 8 dereferenceable(128) %22, i64 noundef %23)
  %25 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 3
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = add i64 %26, -1
  store i64 %27, ptr %25, align 8, !tbaa !11
  br label %61

28:                                               ; preds = %17, %2
  %29 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  br label %35

33:                                               ; preds = %28
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 102, ptr noundef @__PRETTY_FUNCTION__._ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE) #4
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %32
  %36 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE(ptr noundef nonnull align 8 dereferenceable(8048) %37, ptr noundef %38)
  %39 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %40, i32 0, i32 3
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %60, label %44

44:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %45 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  store ptr %46, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 2
  store ptr %49, ptr %50, align 8, !tbaa !18
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %51, i32 0, i32 2
  store ptr null, ptr %52, align 8, !tbaa !18
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %59, label %55

55:                                               ; preds = %44
  %56 = load ptr, ptr %53, align 8, !tbaa !19
  %57 = getelementptr inbounds ptr, ptr %56, i64 2
  %58 = load ptr, ptr %57, align 8
  call void %58(ptr noundef nonnull align 8 dereferenceable(8048) %53) #3
  br label %59

59:                                               ; preds = %55, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %60

60:                                               ; preds = %59, %35
  br label %61

61:                                               ; preds = %60, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6norlit2gc6detail11HandleGroup5WriteEPPNS0_6ObjectES4_(ptr noundef nonnull align 8 dereferenceable(8048), ptr noundef, ptr noundef) #1 align 2

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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 = { 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 = { nounwind }
attributes #4 = { noreturn 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 = !{!12, !6, i64 160}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}


; 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 [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE(ptr noundef nonnull align 8 dereferenceable(8048) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 176
  %4 = ptrtoint ptr %1 to i64
  %5 = ptrtoint ptr %3 to i64
  %6 = sub i64 %4, %5
  %7 = ashr exact i64 %6, 3
  %or.cond = icmp ult i64 %7, 984
  br i1 %or.cond, label %8, label %14

8:                                                ; preds = %2
  tail call void @_ZN6norlit2gc6detail11HandleGroup5WriteEPPNS0_6ObjectES4_(ptr noundef nonnull align 8 dereferenceable(8048) %0, ptr noundef %1, ptr noundef null)
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = tail call noundef nonnull align 8 dereferenceable(128) ptr @_ZNSt6bitsetILm984EE5resetEm(ptr noundef nonnull align 8 dereferenceable(128) %9, i64 noundef %7)
  %11 = getelementptr inbounds i8, ptr %0, i64 168
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = add i64 %12, -1
  store i64 %13, ptr %11, align 8, !tbaa !5
  br label %28

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

17:                                               ; preds = %14
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 102, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE) #2
  unreachable

18:                                               ; preds = %14
  tail call void @_ZN6norlit2gc6detail11HandleGroup4FreeEPPNS0_6ObjectE(ptr noundef nonnull align 8 dereferenceable(8048) %16, ptr noundef %1)
  %19 = load ptr, ptr %15, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %19, i64 168
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %.not12 = icmp eq i64 %21, 0
  br i1 %.not12, label %22, label %28

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %19, i64 160
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  store ptr %24, ptr %15, align 8, !tbaa !16
  store ptr null, ptr %23, align 8, !tbaa !16
  %25 = load ptr, ptr %19, align 8, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load ptr, ptr %26, align 8
  tail call void %27(ptr noundef nonnull align 8 dereferenceable(8048) %19) #3
  br label %28

28:                                               ; preds = %22, %18, %8
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6norlit2gc6detail11HandleGroup5WriteEPPNS0_6ObjectES4_(ptr noundef nonnull align 8 dereferenceable(8048), ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

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

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

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


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