; LLVM IR from brewlin/garbage-collect :: tri-color-marking (test)

; 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.obj = type { i32, ptr, ptr }

@gc_heaps_used = external global i64, align 8
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@auto_grow = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [42 x i8], align 1
@max_sweep = external global i32, align 4
@max_mark = external global i32, align 4
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.test_gc = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@gc_phase = external global i32, align 4
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [25 x i8], align 1

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

declare void @gc_init(i64 noundef) #0

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

declare ptr @gc_malloc(i64 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @test_gc() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %6 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr @auto_grow, align 4, !tbaa !5
  store i64 3, ptr @gc_heaps_used, align 8, !tbaa !9
  call void @gc_init(i64 noundef 72)
  store i32 3, ptr @max_sweep, align 4, !tbaa !5
  store i32 1, ptr @max_mark, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %7 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %7, ptr %1, align 8, !tbaa !11
  call void @add_roots(ptr noundef %1)
  %8 = load ptr, ptr %1, align 8, !tbaa !11
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %0
  br label %12

11:                                               ; preds = %0
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.3, i32 noundef 58, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %13 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %13, ptr %2, align 8, !tbaa !11
  call void @add_roots(ptr noundef %2)
  %14 = load ptr, ptr %2, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  br label %18

17:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.3, i32 noundef 61, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

18:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %19 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %19, ptr %3, align 8, !tbaa !11
  %20 = load ptr, ptr %3, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.obj, ptr %20, i32 0, i32 0
  store i32 33, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !11
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  br label %26

25:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.3, i32 noundef 64, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

26:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %27 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %27, ptr %4, align 8, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !11
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  br label %32

31:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 68, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

32:                                               ; preds = %30
  %33 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 2
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %37

36:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.3, i32 noundef 69, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

37:                                               ; preds = %35
  %38 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %38, ptr %4, align 8, !tbaa !11
  %39 = load ptr, ptr %4, align 8, !tbaa !11
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  br label %43

42:                                               ; preds = %37
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 73, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

43:                                               ; preds = %41
  %44 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %45 = icmp eq i32 %44, 2
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  br label %48

47:                                               ; preds = %43
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.3, i32 noundef 74, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

48:                                               ; preds = %46
  %49 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %49, ptr %4, align 8, !tbaa !11
  %50 = load ptr, ptr %4, align 8, !tbaa !11
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %48
  br label %54

53:                                               ; preds = %48
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 77, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

54:                                               ; preds = %52
  %55 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %56 = icmp eq i32 %55, 3
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  br label %59

58:                                               ; preds = %54
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.3, i32 noundef 78, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

59:                                               ; preds = %57
  %60 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %60, ptr %4, align 8, !tbaa !11
  %61 = load ptr, ptr %3, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.obj, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !13
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %59
  br label %67

66:                                               ; preds = %59
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.3, i32 noundef 84, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

67:                                               ; preds = %65
  %68 = load ptr, ptr %4, align 8, !tbaa !11
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %71

70:                                               ; preds = %67
  br label %72

71:                                               ; preds = %67
  call void @__assert_fail(ptr noundef @.str.14, ptr noundef @.str.3, i32 noundef 85, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

72:                                               ; preds = %70
  %73 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %74 = icmp eq i32 %73, 1
  br i1 %74, label %75, label %76

75:                                               ; preds = %72
  br label %77

76:                                               ; preds = %72
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 86, ptr noundef @__PRETTY_FUNCTION__.test_gc) #5
  unreachable

77:                                               ; preds = %75
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  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 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

declare void @add_roots(ptr noundef) #0

attributes #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 = { noreturn 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 #3 = { 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 }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"obj", !6, i64 0, !12, i64 8, !12, i64 16}


; 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"

@gc_heaps_used = external local_unnamed_addr global i64, align 8
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@auto_grow = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [42 x i8], align 1
@max_sweep = external local_unnamed_addr global i32, align 4
@max_mark = external local_unnamed_addr global i32, align 4
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.test_gc = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@gc_phase = external local_unnamed_addr global i32, align 4
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [25 x i8], align 1

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

declare void @gc_init(i64 noundef) local_unnamed_addr #1

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

declare ptr @gc_malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local void @test_gc() local_unnamed_addr #4 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  store i32 0, ptr @auto_grow, align 4, !tbaa !5
  store i64 3, ptr @gc_heaps_used, align 8, !tbaa !9
  tail call void @gc_init(i64 noundef 72) #5
  store i32 3, ptr @max_sweep, align 4, !tbaa !5
  store i32 1, ptr @max_mark, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %5 = tail call ptr @gc_malloc(i64 noundef 24) #5
  store ptr %5, ptr %1, align 8, !tbaa !11
  call void @add_roots(ptr noundef nonnull %1) #5
  %6 = load ptr, ptr %1, align 8, !tbaa !11
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %8

7:                                                ; preds = %0
  call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.3, i32 noundef 58, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

8:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %9 = call ptr @gc_malloc(i64 noundef 24) #5
  store ptr %9, ptr %2, align 8, !tbaa !11
  call void @add_roots(ptr noundef nonnull %2) #5
  %10 = load ptr, ptr %2, align 8, !tbaa !11
  %.not7 = icmp eq ptr %10, null
  br i1 %.not7, label %11, label %12

11:                                               ; preds = %8
  call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.3, i32 noundef 61, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

12:                                               ; preds = %8
  %13 = call ptr @gc_malloc(i64 noundef 24) #5
  store i32 33, ptr %13, align 8, !tbaa !13
  %14 = call ptr @gc_malloc(i64 noundef 24) #5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 68, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

17:                                               ; preds = %12
  %18 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 2
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.3, i32 noundef 69, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

21:                                               ; preds = %17
  %22 = call ptr @gc_malloc(i64 noundef 24) #5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 73, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

25:                                               ; preds = %21
  %26 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 2
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.3, i32 noundef 74, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

29:                                               ; preds = %25
  %30 = call ptr @gc_malloc(i64 noundef 24) #5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 77, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

33:                                               ; preds = %29
  %34 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.3, i32 noundef 78, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

37:                                               ; preds = %33
  %38 = call ptr @gc_malloc(i64 noundef 24) #5
  %39 = load i32, ptr %13, align 8, !tbaa !13
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.3, i32 noundef 84, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

42:                                               ; preds = %37
  %.not8 = icmp eq ptr %38, null
  br i1 %.not8, label %43, label %44

43:                                               ; preds = %42
  call void @__assert_fail(ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.3, i32 noundef 85, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

44:                                               ; preds = %42
  %45 = load i32, ptr @gc_phase, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 86, ptr noundef nonnull @__PRETTY_FUNCTION__.test_gc) #6
  unreachable

48:                                               ; preds = %44
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret void
}

declare void @add_roots(ptr noundef) local_unnamed_addr #1

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


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