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

; 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] }
%"class.norlit::gc::Object" = type <{ ptr, %union.anon, i8, i8, i8, [5 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc6detail11HandleGroup12IterateFieldERKNS0_13FieldIteratorE(ptr noundef nonnull align 8 dereferenceable(8048) %0, ptr noundef nonnull align 8 dereferenceable(8) %1) unnamed_addr #0 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
  %8 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 3
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i64 %9, 0
  br i1 %10, label %11, label %44

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !17
  br label %12

12:                                               ; preds = %40, %11
  %13 = load i64, ptr %5, align 8, !tbaa !17
  %14 = icmp ult i64 %13, 984
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %43

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 4
  %18 = load i64, ptr %5, align 8, !tbaa !17
  %19 = getelementptr inbounds [984 x ptr], ptr %17, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %39

23:                                               ; preds = %16
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call noundef zeroext i1 @_ZNK6norlit2gc6Object8IsTaggedEv(ptr noundef nonnull align 8 dereferenceable(27) %24)
  br i1 %25, label %39, label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.norlit::gc::Object", ptr %27, i32 0, i32 2
  %29 = load i8, ptr %28, align 8, !tbaa !18
  %30 = icmp ne i8 %29, 4
  br i1 %30, label %31, label %39

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.norlit::gc::detail::HandleGroup", ptr %7, i32 0, i32 4
  %34 = load i64, ptr %5, align 8, !tbaa !17
  %35 = getelementptr inbounds [984 x ptr], ptr %33, i64 0, i64 %34
  %36 = load ptr, ptr %32, align 8, !tbaa !19
  %37 = getelementptr inbounds ptr, ptr %36, i64 0
  %38 = load ptr, ptr %37, align 8
  call void %38(ptr noundef nonnull align 8 dereferenceable(8) %32, ptr noundef %35)
  br label %39

39:                                               ; preds = %31, %26, %23, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %40

40:                                               ; preds = %39
  %41 = load i64, ptr %5, align 8, !tbaa !17
  %42 = add i64 %41, 1
  store i64 %42, ptr %5, align 8, !tbaa !17
  br label %12, !llvm.loop !21

43:                                               ; preds = %15
  br label %44

44:                                               ; preds = %43, %2
  ret void
}

; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK6norlit2gc6Object8IsTaggedEv(ptr noundef nonnull align 8 dereferenceable(27)) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 168}
!10 = !{!"_ZTSN6norlit2gc6detail11HandleGroupE", !11, i64 0, !14, i64 32, !6, i64 160, !16, i64 168, !7, i64 176}
!11 = !{!"_ZTSN6norlit2gc6ObjectE", !7, i64 8, !12, i64 24, !13, i64 25, !7, i64 26}
!12 = !{!"_ZTSN6norlit2gc5SpaceE", !7, i64 0}
!13 = !{!"_ZTSN6norlit2gc6StatusE", !7, i64 0}
!14 = !{!"_ZTSSt6bitsetILm984EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Base_bitsetILm16EE", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!11, !12, i64 24}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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 void @_ZN6norlit2gc6detail11HandleGroup12IterateFieldERKNS0_13FieldIteratorE(ptr noundef nonnull align 8 dereferenceable(8048) %0, ptr noundef nonnull align 8 dereferenceable(8) %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 168
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 176
  br label %6

6:                                                ; preds = %.preheader, %17
  %.011 = phi i64 [ 0, %.preheader ], [ %18, %17 ]
  %7 = getelementptr inbounds [984 x ptr], ptr %5, i64 0, i64 %.011
  %8 = load ptr, ptr %7, align 8, !tbaa !16
  %.not9 = icmp eq ptr %8, null
  br i1 %.not9, label %17, label %9

9:                                                ; preds = %6
  %10 = tail call noundef zeroext i1 @_ZNK6norlit2gc6Object8IsTaggedEv(ptr noundef nonnull align 8 dereferenceable(27) %8)
  br i1 %10, label %17, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %8, i64 24
  %13 = load i8, ptr %12, align 8, !tbaa !17
  %.not10 = icmp eq i8 %13, 4
  br i1 %.not10, label %17, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %1, align 8, !tbaa !18
  %16 = load ptr, ptr %15, align 8
  tail call void %16(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %7)
  br label %17

17:                                               ; preds = %14, %11, %9, %6
  %18 = add nuw nsw i64 %.011, 1
  %exitcond.not = icmp eq i64 %18, 984
  br i1 %exitcond.not, label %.loopexit, label %6, !llvm.loop !20

.loopexit:                                        ; preds = %17, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK6norlit2gc6Object8IsTaggedEv(ptr noundef nonnull align 8 dereferenceable(27)) local_unnamed_addr #1 align 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 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, !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 = !{!14, !14, i64 0}
!17 = !{!7, !10, i64 24}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass