; LLVM IR from nbdd0121/GenerationalGC :: Heap.ll (ZN6norlit2gc4Heap21PromoteToTenuredSpaceEPNS0_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"

%"struct.norlit::gc::Heap::IncRefIterator" = type { %"class.norlit::gc::FieldIterator" }
%"class.norlit::gc::FieldIterator" = type { ptr }
%"class.norlit::gc::Object" = type <{ ptr, %union.anon, i8, i8, i8, [5 x i8] }>
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr }
%struct.anon.0 = type { ptr, i32, i32 }

@_ZN6norlit2gc4Heap13tenured_spaceE = external dso_local global ptr, align 8
@_ZN6norlit2gc4Heap17full_gc_suggestedE = external dso_local global i8, align 1
@.str.9 = external hidden unnamed_addr constant [49 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

declare i32 @printf(ptr noundef, ...) #1

declare noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i1 noundef zeroext) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc4Heap21PromoteToTenuredSpaceEPNS0_6ObjectE(ptr noundef %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %"struct.norlit::gc::Heap::IncRefIterator", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %5 = load ptr, ptr @_ZN6norlit2gc4Heap13tenured_spaceE, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %"class.norlit::gc::Object", ptr %6, i32 0, i32 1
  %8 = getelementptr inbounds %struct.anon.0, ptr %7, i32 0, i32 2
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = call noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40) %5, i64 noundef %10, i1 noundef zeroext false)
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %22, label %14

14:                                               ; preds = %1
  store i8 1, ptr @_ZN6norlit2gc4Heap17full_gc_suggestedE, align 1, !tbaa !10
  %15 = load ptr, ptr @_ZN6norlit2gc4Heap13tenured_spaceE, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.norlit::gc::Object", ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds %struct.anon.0, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = call noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40) %15, i64 noundef %20, i1 noundef zeroext true)
  store ptr %21, ptr %3, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %14, %1
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.norlit::gc::Object", ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.anon.0, ptr %25, i32 0, i32 0
  store ptr %23, ptr %26, align 8, !tbaa !9
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.norlit::gc::Object", ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds %struct.anon.0, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, ptr noundef %27, ptr noundef %31)
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.norlit::gc::Object", ptr %33, i32 0, i32 2
  store i8 2, ptr %34, align 8, !tbaa !12
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 8, i1 false)
  call void @_ZN6norlit2gc4Heap14IncRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds ptr, ptr %36, i64 5
  %38 = load ptr, ptr %37, align 8
  call void %38(ptr noundef nonnull align 8 dereferenceable(27) %35, ptr noundef nonnull align 8 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc4Heap14IncRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = !{!13, !14, i64 24}
!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 = !{!17, !17, i64 0}
!17 = !{!"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"

%"struct.norlit::gc::Heap::IncRefIterator" = type { %"class.norlit::gc::FieldIterator" }
%"class.norlit::gc::FieldIterator" = type { ptr }

@_ZN6norlit2gc4Heap13tenured_spaceE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN6norlit2gc4Heap17full_gc_suggestedE = external dso_local local_unnamed_addr global i8, align 1
@.str.9 = external hidden unnamed_addr constant [49 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc4Heap21PromoteToTenuredSpaceEPNS0_6ObjectE(ptr noundef %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %"struct.norlit::gc::Heap::IncRefIterator", align 8
  %3 = load ptr, ptr @_ZN6norlit2gc4Heap13tenured_spaceE, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = zext i32 %5 to i64
  %7 = tail call noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40) %3, i64 noundef %6, i1 noundef zeroext false)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %13

8:                                                ; preds = %1
  store i8 1, ptr @_ZN6norlit2gc4Heap17full_gc_suggestedE, align 1, !tbaa !10
  %9 = load ptr, ptr @_ZN6norlit2gc4Heap13tenured_spaceE, align 8, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = tail call noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40) %9, i64 noundef %11, i1 noundef zeroext true)
  br label %13

13:                                               ; preds = %8, %1
  %.0 = phi ptr [ %7, %1 ], [ %12, %8 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.0, ptr %14, align 8, !tbaa !9
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, ptr noundef nonnull %0, ptr noundef %.0)
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 2, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i64 0, ptr %2, align 8
  call void @_ZN6norlit2gc4Heap14IncRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  %17 = load ptr, ptr %0, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %17, i64 40
  %19 = load ptr, ptr %18, align 8
  call void %19(ptr noundef nonnull align 8 dereferenceable(27) %0, ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc4Heap14IncRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 = { "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 = { 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 #4 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = !{!13, !14, i64 24}
!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 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}


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