; LLVM IR from nbdd0121/GenerationalGC :: Heap.ll (ZN6norlit2gc4Heap25EdenSpace_CalculateTargetEv)

; 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::Heap::Iterable" = type { %"class.norlit::gc::Heap::MemorySpaceIterator" }
%"class.norlit::gc::Heap::MemorySpaceIterator" = type <{ ptr, ptr, ptr, i8, [7 x i8] }>
%"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator" = 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 }

@_ZN6norlit2gc4Heap10eden_spaceE = external dso_local global ptr, align 8
@_ZN6norlit2gc4Heap17survivor_to_spaceE = external dso_local global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 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: mustprogress uwtable
declare dso_local void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEEC2IJRPNS0_11MemorySpaceEEEEDpOT_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE5beginEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE3endEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc4Heap25EdenSpace_CalculateTargetEv() #2 align 2 {
  %1 = alloca ptr, align 8
  %2 = alloca %"class.norlit::gc::Heap::Iterable", align 8
  %3 = alloca %"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator", align 8
  %4 = alloca %"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator", align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #4
  call void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEEC2IJRPNS0_11MemorySpaceEEEEDpOT_(ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(8) @_ZN6norlit2gc4Heap10eden_spaceE)
  store ptr %2, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = call ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE5beginEv(ptr noundef nonnull align 8 dereferenceable(32) %6)
  %8 = getelementptr inbounds %"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator", ptr %3, i32 0, i32 0
  store ptr %7, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = call ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE3endEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  %11 = getelementptr inbounds %"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator", ptr %4, i32 0, i32 0
  store ptr %10, ptr %11, align 8
  br label %12

12:                                               ; preds = %48, %0
  %13 = call noundef zeroext i1 @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorneERKS5_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %13, label %15, label %14

14:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  br label %49

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %16 = call noundef ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.norlit::gc::Object", ptr %17, i32 0, i32 3
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = icmp eq i8 %19, 2
  br i1 %20, label %21, label %44

21:                                               ; preds = %15
  %22 = load ptr, ptr @_ZN6norlit2gc4Heap17survivor_to_spaceE, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.norlit::gc::Object", ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.anon.0, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = zext i32 %26 to i64
  %28 = call noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40) %22, i64 noundef %27, i1 noundef zeroext true)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.norlit::gc::Object", ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.anon.0, ptr %30, i32 0, i32 0
  store ptr %28, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.norlit::gc::Object", ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.anon.0, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %32, ptr noundef %36)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.norlit::gc::Object", ptr %38, i32 0, i32 2
  store i8 1, ptr %39, align 8, !tbaa !14
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.norlit::gc::Object", ptr %40, i32 0, i32 4
  %42 = load i8, ptr %41, align 2, !tbaa !15
  %43 = add i8 %42, 1
  store i8 %43, ptr %41, align 2, !tbaa !15
  br label %47

44:                                               ; preds = %15
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %45)
  br label %47

47:                                               ; preds = %44, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %48

48:                                               ; preds = %47
  call void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  br label %12

49:                                               ; preds = %14
  ret void
}

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 = { 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 #3 = { 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, !12, i64 25}
!10 = !{!"_ZTSN6norlit2gc6ObjectE", !7, i64 8, !11, i64 24, !12, i64 25, !7, i64 26}
!11 = !{!"_ZTSN6norlit2gc5SpaceE", !7, i64 0}
!12 = !{!"_ZTSN6norlit2gc6StatusE", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !11, i64 24}
!15 = !{!10, !7, i64 26}


; 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::Heap::Iterable" = type { %"class.norlit::gc::Heap::MemorySpaceIterator" }
%"class.norlit::gc::Heap::MemorySpaceIterator" = type <{ ptr, ptr, ptr, i8, [7 x i8] }>
%"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator" = type { ptr }

@_ZN6norlit2gc4Heap10eden_spaceE = external dso_local global ptr, align 8
@_ZN6norlit2gc4Heap17survivor_to_spaceE = external dso_local local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 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
declare dso_local void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEEC2IJRPNS0_11MemorySpaceEEEEDpOT_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE5beginEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE3endEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorneERKS5_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc4Heap25EdenSpace_CalculateTargetEv() local_unnamed_addr #3 align 2 {
  %1 = alloca %"class.norlit::gc::Heap::Iterable", align 8
  %2 = alloca %"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator", align 8
  %3 = alloca %"class.norlit::gc::Heap::Iterable<norlit::gc::Heap::MemorySpaceIterator>::Iterator", align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #5
  call void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEEC2IJRPNS0_11MemorySpaceEEEEDpOT_(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(8) @_ZN6norlit2gc4Heap10eden_spaceE)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %4 = call ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE5beginEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  store ptr %4, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %5 = call ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE3endEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  store ptr %5, ptr %3, align 8
  %6 = call noundef zeroext i1 @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorneERKS5_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %25, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #5
  ret void

.lr.ph:                                           ; preds = %0, %25
  %7 = call noundef ptr @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratordeEv(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %8 = getelementptr inbounds i8, ptr %7, i64 25
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = icmp eq i8 %9, 2
  br i1 %10, label %11, label %23

11:                                               ; preds = %.lr.ph
  %12 = load ptr, ptr @_ZN6norlit2gc4Heap17survivor_to_spaceE, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %7, i64 8
  %14 = getelementptr inbounds i8, ptr %7, i64 20
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = zext i32 %15 to i64
  %17 = call noundef ptr @_ZN6norlit2gc11MemorySpace8AllocateEmb(ptr noundef nonnull align 8 dereferenceable(40) %12, i64 noundef %16, i1 noundef zeroext true)
  store ptr %17, ptr %13, align 8, !tbaa !13
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %7, ptr noundef %17)
  %19 = getelementptr inbounds i8, ptr %7, i64 24
  store i8 1, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %7, i64 26
  %21 = load i8, ptr %20, align 2, !tbaa !15
  %22 = add i8 %21, 1
  store i8 %22, ptr %20, align 2, !tbaa !15
  br label %25

23:                                               ; preds = %.lr.ph
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef nonnull %7)
  br label %25

25:                                               ; preds = %23, %11
  call void @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorppEv(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %26 = call noundef zeroext i1 @_ZN6norlit2gc4Heap8IterableINS1_19MemorySpaceIteratorEE8IteratorneERKS5_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %26, label %.lr.ph, label %._crit_edge
}

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 = { 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, !10, i64 25}
!6 = !{!"_ZTSN6norlit2gc6ObjectE", !7, i64 8, !9, i64 24, !10, i64 25, !7, i64 26}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"_ZTSN6norlit2gc5SpaceE", !7, i64 0}
!10 = !{!"_ZTSN6norlit2gc6StatusE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !9, i64 24}
!15 = !{!6, !7, i64 26}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass