; LLVM IR from nbdd0121/GenerationalGC :: Heap.ll (ZN6norlit2gc4Heap10InitializeEPNS0_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.anon.0 = type { ptr, i32, i32 }

@_ZN6norlit2gc4Heap11initializedE = external dso_local global i8, align 1
@_ZN6norlit2gc4Heap11stack_spaceE = external dso_local global %"class.norlit::gc::Object", align 8
@_ZN6norlit2gc4Heap10eden_spaceE = external dso_local global ptr, align 8
@_ZN6norlit2gc4Heap15allocating_sizeE = external dso_local global i32, align 4
@_ZN6norlit2gc4Heap17allocating_objectE = external dso_local global ptr, align 8
@_ZN6norlit2gc4Heap13no_gc_counterE = external dso_local global i64, align 8

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc4Heap10InitializeEPNS0_6ObjectE(ptr noundef %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load i8, ptr @_ZN6norlit2gc4Heap11initializedE, align 1, !tbaa !9, !range !11, !noundef !12
  %4 = trunc i8 %3 to i1
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  call void @_ZN6norlit2gc4Heap16GlobalInitializeEv()
  store ptr @_ZN6norlit2gc4Heap11stack_spaceE, ptr getelementptr inbounds (%"class.norlit::gc::Object", ptr @_ZN6norlit2gc4Heap11stack_spaceE, i32 0, i32 1), align 8, !tbaa !13
  store ptr @_ZN6norlit2gc4Heap11stack_spaceE, ptr getelementptr inbounds (%struct.anon, ptr getelementptr inbounds (%"class.norlit::gc::Object", ptr @_ZN6norlit2gc4Heap11stack_spaceE, i32 0, i32 1), i32 0, i32 1), align 8, !tbaa !13
  store i8 4, ptr getelementptr inbounds (%"class.norlit::gc::Object", ptr @_ZN6norlit2gc4Heap11stack_spaceE, i32 0, i32 2), align 8, !tbaa !14
  br label %6

6:                                                ; preds = %5, %1
  %7 = load ptr, ptr @_ZN6norlit2gc4Heap17allocating_objectE, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %7, %8
  br i1 %9, label %10, label %29

10:                                               ; preds = %6
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = icmp ne ptr %11, @_ZN6norlit2gc4Heap11stack_spaceE
  br i1 %12, label %13, label %28

13:                                               ; preds = %10
  %14 = load ptr, ptr getelementptr inbounds (%"class.norlit::gc::Object", ptr @_ZN6norlit2gc4Heap11stack_spaceE, i32 0, i32 1), align 8, !tbaa !13
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.norlit::gc::Object", ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 0
  store ptr %14, ptr %17, align 8, !tbaa !13
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.norlit::gc::Object", ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 1
  store ptr @_ZN6norlit2gc4Heap11stack_spaceE, ptr %20, align 8, !tbaa !13
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr getelementptr inbounds (%"class.norlit::gc::Object", ptr @_ZN6norlit2gc4Heap11stack_spaceE, i32 0, i32 1), align 8, !tbaa !13
  %23 = getelementptr inbounds %"class.norlit::gc::Object", ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 1
  store ptr %21, ptr %24, align 8, !tbaa !13
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %25, ptr getelementptr inbounds (%"class.norlit::gc::Object", ptr @_ZN6norlit2gc4Heap11stack_spaceE, i32 0, i32 1), align 8, !tbaa !13
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.norlit::gc::Object", ptr %26, i32 0, i32 2
  store i8 4, ptr %27, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %13, %10
  br label %72

29:                                               ; preds = %6
  %30 = load i32, ptr @_ZN6norlit2gc4Heap15allocating_sizeE, align 4, !tbaa !18
  %31 = zext i32 %30 to i64
  %32 = icmp ugt i64 %31, 4096
  br i1 %32, label %33, label %40

33:                                               ; preds = %29
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %"class.norlit::gc::Object", ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %struct.anon.0, ptr %36, i32 0, i32 0
  store ptr %34, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.norlit::gc::Object", ptr %38, i32 0, i32 2
  store i8 3, ptr %39, align 8, !tbaa !14
  br label %60

40:                                               ; preds = %29
  %41 = load i64, ptr @_ZN6norlit2gc4Heap13no_gc_counterE, align 8, !tbaa !20
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %40
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = load ptr, ptr @_ZN6norlit2gc4Heap10eden_spaceE, align 8, !tbaa !5
  %46 = call noundef ptr @_ZN6norlit2gc11MemorySpace5BeginEv(ptr noundef nonnull align 8 dereferenceable(40) %45)
  %47 = icmp uge ptr %44, %46
  br i1 %47, label %48, label %56

48:                                               ; preds = %43
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load ptr, ptr @_ZN6norlit2gc4Heap10eden_spaceE, align 8, !tbaa !5
  %51 = call noundef ptr @_ZN6norlit2gc11MemorySpace3EndEv(ptr noundef nonnull align 8 dereferenceable(40) %50)
  %52 = icmp ult ptr %49, %51
  br i1 %52, label %53, label %56

53:                                               ; preds = %48, %40
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.norlit::gc::Object", ptr %54, i32 0, i32 2
  store i8 0, ptr %55, align 8, !tbaa !14
  br label %59

56:                                               ; preds = %48, %43
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %"class.norlit::gc::Object", ptr %57, i32 0, i32 2
  store i8 1, ptr %58, align 8, !tbaa !14
  br label %59

59:                                               ; preds = %56, %53
  br label %60

60:                                               ; preds = %59, %33
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %"class.norlit::gc::Object", ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.anon.0, ptr %62, i32 0, i32 1
  store i32 0, ptr %63, align 8, !tbaa !13
  %64 = load i32, ptr @_ZN6norlit2gc4Heap15allocating_sizeE, align 4, !tbaa !18
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %"class.norlit::gc::Object", ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.anon.0, ptr %66, i32 0, i32 2
  store i32 %64, ptr %67, align 4, !tbaa !13
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %"class.norlit::gc::Object", ptr %68, i32 0, i32 3
  store i8 0, ptr %69, align 1, !tbaa !22
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %"class.norlit::gc::Object", ptr %70, i32 0, i32 4
  store i8 0, ptr %71, align 2, !tbaa !23
  store i32 0, ptr @_ZN6norlit2gc4Heap15allocating_sizeE, align 4, !tbaa !18
  store ptr null, ptr @_ZN6norlit2gc4Heap17allocating_objectE, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %60, %28
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6norlit2gc11MemorySpace5BeginEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6norlit2gc11MemorySpace3EndEv(ptr noundef nonnull align 8 dereferenceable(40)) #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, !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 = !{!7, !7, i64 0}
!14 = !{!15, !16, i64 24}
!15 = !{!"_ZTSN6norlit2gc6ObjectE", !7, i64 8, !16, i64 24, !17, i64 25, !7, i64 26}
!16 = !{!"_ZTSN6norlit2gc5SpaceE", !7, i64 0}
!17 = !{!"_ZTSN6norlit2gc6StatusE", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!15, !17, i64 25}
!23 = !{!15, !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::Object" = type <{ ptr, %union.anon, i8, i8, i8, [5 x i8] }>
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr }

@_ZN6norlit2gc4Heap11initializedE = external dso_local local_unnamed_addr global i8, align 1
@_ZN6norlit2gc4Heap11stack_spaceE = external dso_local global %"class.norlit::gc::Object", align 8
@_ZN6norlit2gc4Heap10eden_spaceE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN6norlit2gc4Heap15allocating_sizeE = external dso_local local_unnamed_addr global i32, align 4
@_ZN6norlit2gc4Heap17allocating_objectE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN6norlit2gc4Heap13no_gc_counterE = external dso_local local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6norlit2gc4Heap10InitializeEPNS0_6ObjectE(ptr noundef %0) local_unnamed_addr #0 align 2 {
  %2 = load i8, ptr @_ZN6norlit2gc4Heap11initializedE, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %5, label %4

4:                                                ; preds = %1
  tail call void @_ZN6norlit2gc4Heap16GlobalInitializeEv()
  store ptr @_ZN6norlit2gc4Heap11stack_spaceE, ptr getelementptr inbounds (i8, ptr @_ZN6norlit2gc4Heap11stack_spaceE, i64 8), align 8, !tbaa !11
  store ptr @_ZN6norlit2gc4Heap11stack_spaceE, ptr getelementptr inbounds (i8, ptr @_ZN6norlit2gc4Heap11stack_spaceE, i64 16), align 8, !tbaa !11
  store i8 4, ptr getelementptr inbounds (i8, ptr @_ZN6norlit2gc4Heap11stack_spaceE, i64 24), align 8, !tbaa !12
  br label %5

5:                                                ; preds = %4, %1
  %6 = load ptr, ptr @_ZN6norlit2gc4Heap17allocating_objectE, align 8, !tbaa !16
  %.not = icmp eq ptr %6, %0
  br i1 %.not, label %14, label %7

7:                                                ; preds = %5
  %.not20 = icmp eq ptr %0, @_ZN6norlit2gc4Heap11stack_spaceE
  br i1 %.not20, label %36, label %8

8:                                                ; preds = %7
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN6norlit2gc4Heap11stack_spaceE, i64 8), align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %9, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr @_ZN6norlit2gc4Heap11stack_spaceE, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %0, ptr %12, align 8, !tbaa !11
  store ptr %0, ptr getelementptr inbounds (i8, ptr @_ZN6norlit2gc4Heap11stack_spaceE, i64 8), align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 4, ptr %13, align 8, !tbaa !12
  br label %36

14:                                               ; preds = %5
  %15 = load i32, ptr @_ZN6norlit2gc4Heap15allocating_sizeE, align 4, !tbaa !18
  %16 = icmp ugt i32 %15, 4096
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %0, ptr %18, align 8, !tbaa !11
  br label %29

19:                                               ; preds = %14
  %20 = load i64, ptr @_ZN6norlit2gc4Heap13no_gc_counterE, align 8, !tbaa !20
  %.not18 = icmp eq i64 %20, 0
  br i1 %.not18, label %29, label %21

21:                                               ; preds = %19
  %22 = load ptr, ptr @_ZN6norlit2gc4Heap10eden_spaceE, align 8, !tbaa !16
  %23 = tail call noundef ptr @_ZN6norlit2gc11MemorySpace5BeginEv(ptr noundef nonnull align 8 dereferenceable(40) %22)
  %.not19 = icmp ugt ptr %23, %0
  br i1 %.not19, label %28, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr @_ZN6norlit2gc4Heap10eden_spaceE, align 8, !tbaa !16
  %26 = tail call noundef ptr @_ZN6norlit2gc11MemorySpace3EndEv(ptr noundef nonnull align 8 dereferenceable(40) %25)
  %27 = icmp ugt ptr %26, %0
  br i1 %27, label %29, label %28

28:                                               ; preds = %24, %21
  br label %29

29:                                               ; preds = %19, %24, %28, %17
  %.sink = phi i8 [ 1, %28 ], [ 3, %17 ], [ 0, %24 ], [ 0, %19 ]
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 %.sink, ptr %30, align 8, !tbaa !12
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %31, align 8, !tbaa !11
  %32 = load i32, ptr @_ZN6norlit2gc4Heap15allocating_sizeE, align 4, !tbaa !18
  %33 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %32, ptr %33, align 4, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 0, ptr %34, align 1, !tbaa !22
  %35 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 0, ptr %35, align 2, !tbaa !23
  store i32 0, ptr @_ZN6norlit2gc4Heap15allocating_sizeE, align 4, !tbaa !18
  store ptr null, ptr @_ZN6norlit2gc4Heap17allocating_objectE, align 8, !tbaa !16
  br label %36

36:                                               ; preds = %7, %8, %29
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6norlit2gc11MemorySpace5BeginEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6norlit2gc11MemorySpace3EndEv(ptr noundef nonnull align 8 dereferenceable(40)) 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, !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 = !{!7, !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 = !{!"any pointer", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!13, !15, i64 25}
!23 = !{!13, !7, i64 26}


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