; LLVM IR from nbdd0121/GenerationalGC :: Heap.ll (ZN6norlit2gc4Heap18UntrackStackObjectEPNS0_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::Object" = type <{ ptr, %union.anon, i8, i8, i8, [5 x i8] }>
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr }
%"struct.norlit::gc::Heap::DecRefIterator" = type { %"class.norlit::gc::FieldIterator" }
%"class.norlit::gc::FieldIterator" = type { ptr }

@_ZN6norlit2gc4Heap11initializedE = external dso_local global i8, align 1
@_ZN6norlit2gc4Heap11stack_spaceE = external dso_local global %"class.norlit::gc::Object", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6norlit2gc4Heap13GlobalDestroyEv() #0 align 2

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

; 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 @_ZN6norlit2gc4Heap18UntrackStackObjectEPNS0_6ObjectE(ptr noundef %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"struct.norlit::gc::Heap::DecRefIterator", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load i8, ptr @_ZN6norlit2gc4Heap11initializedE, align 1, !tbaa !9, !range !11, !noundef !12
  %5 = trunc i8 %4 to i1
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  br label %36

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp eq ptr %8, @_ZN6norlit2gc4Heap11stack_spaceE
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  call void @_ZN6norlit2gc4Heap13GlobalDestroyEv()
  store i8 0, ptr @_ZN6norlit2gc4Heap11initializedE, align 1, !tbaa !9
  br label %36

11:                                               ; preds = %7
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 8, i1 false)
  call void @_ZN6norlit2gc4Heap14DecRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds ptr, ptr %13, i64 5
  %15 = load ptr, ptr %14, align 8
  call void %15(ptr noundef nonnull align 8 dereferenceable(27) %12, ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %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, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.norlit::gc::Object", ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds %"class.norlit::gc::Object", ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.anon, ptr %24, i32 0, i32 1
  store ptr %19, ptr %25, align 8, !tbaa !15
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.norlit::gc::Object", ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.norlit::gc::Object", ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.anon, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds %"class.norlit::gc::Object", ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.anon, ptr %34, i32 0, i32 0
  store ptr %29, ptr %35, align 8, !tbaa !15
  br label %36

36:                                               ; preds = %11, %10, %6
  ret void
}

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc4Heap14DecRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = !{!7, !7, 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"

%"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.norlit::gc::Heap::DecRefIterator" = type { %"class.norlit::gc::FieldIterator" }
%"class.norlit::gc::FieldIterator" = type { ptr }

@_ZN6norlit2gc4Heap11initializedE = external dso_local local_unnamed_addr global i8, align 1
@_ZN6norlit2gc4Heap11stack_spaceE = external dso_local global %"class.norlit::gc::Object", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6norlit2gc4Heap13GlobalDestroyEv() local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress 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 @_ZN6norlit2gc4Heap18UntrackStackObjectEPNS0_6ObjectE(ptr noundef %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %"struct.norlit::gc::Heap::DecRefIterator", align 8
  %3 = load i8, ptr @_ZN6norlit2gc4Heap11initializedE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %19

5:                                                ; preds = %1
  %6 = icmp eq ptr %0, @_ZN6norlit2gc4Heap11stack_spaceE
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @_ZN6norlit2gc4Heap13GlobalDestroyEv()
  store i8 0, ptr @_ZN6norlit2gc4Heap11initializedE, align 1, !tbaa !5
  br label %19

8:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store i64 0, ptr %2, align 8
  call void @_ZN6norlit2gc4Heap14DecRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #3
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 40
  %11 = load ptr, ptr %10, align 8
  call void %11(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) #3
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = load ptr, ptr %12, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store ptr %14, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %12, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !13
  br label %19

19:                                               ; preds = %1, %8, %7
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc4Heap14DecRefIteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 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 = { mustprogress 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!7, !7, i64 0}


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