; LLVM IR from brewlin/garbage-collect :: mark-sweep (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 }

@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__.test_reference_gc = external hidden unnamed_addr constant [25 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @clear() #0

; 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

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

declare ptr @gc_malloc(i64 noundef) #2

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

declare void @gc() #2

declare void @add_roots(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @test_reference_gc() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %4 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %5 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %5, ptr %1, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.obj, ptr %6, i32 0, i32 0
  store i32 10, ptr %7, align 8, !tbaa !9
  %8 = call ptr @gc_malloc(i64 noundef 24)
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.obj, ptr %9, i32 0, i32 1
  store ptr %8, ptr %10, align 8, !tbaa !12
  %11 = call ptr @gc_malloc(i64 noundef 24)
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.obj, ptr %12, i32 0, i32 2
  store ptr %11, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.obj, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds %struct.obj, ptr %16, i32 0, i32 0
  store i32 11, ptr %17, align 8, !tbaa !9
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.obj, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %struct.obj, ptr %20, i32 0, i32 0
  store i32 12, ptr %21, align 8, !tbaa !9
  call void @add_roots(ptr noundef %1)
  call void @gc()
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.obj, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = icmp eq i32 %24, 10
  br i1 %25, label %26, label %27

26:                                               ; preds = %0
  br label %28

27:                                               ; preds = %0
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 107, ptr noundef @__PRETTY_FUNCTION__.test_reference_gc) #5
  unreachable

28:                                               ; preds = %26
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.obj, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds %struct.obj, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = icmp eq i32 %33, 11
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  br label %37

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

37:                                               ; preds = %35
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.obj, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct.obj, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = icmp eq i32 %42, 12
  br i1 %43, label %44, label %45

44:                                               ; preds = %37
  br label %46

45:                                               ; preds = %37
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.3, i32 noundef 109, ptr noundef @__PRETTY_FUNCTION__.test_reference_gc) #5
  unreachable

46:                                               ; preds = %44
  %47 = call ptr @gc_malloc(i64 noundef 24)
  store ptr %47, ptr %1, align 8, !tbaa !5
  %48 = load ptr, ptr %1, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.obj, ptr %48, i32 0, i32 0
  store i32 10, ptr %49, align 8, !tbaa !9
  %50 = call ptr @gc_malloc(i64 noundef 24)
  %51 = load ptr, ptr %1, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.obj, ptr %51, i32 0, i32 1
  store ptr %50, ptr %52, align 8, !tbaa !12
  %53 = load ptr, ptr %1, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.obj, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = getelementptr inbounds %struct.obj, ptr %55, i32 0, i32 0
  store i32 11, ptr %56, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %57 = load ptr, ptr %1, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.obj, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !12
  store ptr %59, ptr %2, align 8, !tbaa !5
  call void @gc()
  %60 = load ptr, ptr %1, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.obj, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %46
  br label %66

65:                                               ; preds = %46
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.3, i32 noundef 118, ptr noundef @__PRETTY_FUNCTION__.test_reference_gc) #5
  unreachable

66:                                               ; preds = %64
  %67 = load ptr, ptr %1, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.obj, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !12
  %70 = icmp eq ptr %69, null
  br i1 %70, label %71, label %72

71:                                               ; preds = %66
  br label %73

72:                                               ; preds = %66
  call void @__assert_fail(ptr noundef @.str.14, ptr noundef @.str.3, i32 noundef 119, ptr noundef @__PRETTY_FUNCTION__.test_reference_gc) #5
  unreachable

73:                                               ; preds = %71
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.obj, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !9
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %78, label %79

78:                                               ; preds = %73
  br label %80

79:                                               ; preds = %73
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 121, ptr noundef @__PRETTY_FUNCTION__.test_reference_gc) #5
  unreachable

80:                                               ; preds = %78
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %82 = call i32 @clear()
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__.test_reference_gc = external hidden unnamed_addr constant [25 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @clear() local_unnamed_addr #0

; 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare ptr @gc_malloc(i64 noundef) local_unnamed_addr #3

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

declare void @gc() local_unnamed_addr #3

declare void @add_roots(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @test_reference_gc() local_unnamed_addr #0 {
  %1 = alloca ptr, align 8
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %4 = tail call ptr @gc_malloc(i64 noundef 24) #5
  store ptr %4, ptr %1, align 8, !tbaa !5
  store i32 10, ptr %4, align 8, !tbaa !9
  %5 = tail call ptr @gc_malloc(i64 noundef 24) #5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %5, ptr %6, align 8, !tbaa !12
  %7 = tail call ptr @gc_malloc(i64 noundef 24) #5
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %7, ptr %8, align 8, !tbaa !13
  %9 = load ptr, ptr %6, align 8, !tbaa !12
  store i32 11, ptr %9, align 8, !tbaa !9
  store i32 12, ptr %7, align 8, !tbaa !9
  call void @add_roots(ptr noundef nonnull %1) #5
  call void @gc() #5
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, 10
  br i1 %12, label %14, label %13

13:                                               ; preds = %0
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 107, ptr noundef nonnull @__PRETTY_FUNCTION__.test_reference_gc) #6
  unreachable

14:                                               ; preds = %0
  %15 = getelementptr inbounds i8, ptr %10, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i32 %17, 11
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.3, i32 noundef 108, ptr noundef nonnull @__PRETTY_FUNCTION__.test_reference_gc) #6
  unreachable

20:                                               ; preds = %14
  %21 = getelementptr inbounds i8, ptr %10, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = icmp eq i32 %23, 12
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.3, i32 noundef 109, ptr noundef nonnull @__PRETTY_FUNCTION__.test_reference_gc) #6
  unreachable

26:                                               ; preds = %20
  %27 = call ptr @gc_malloc(i64 noundef 24) #5
  store ptr %27, ptr %1, align 8, !tbaa !5
  store i32 10, ptr %27, align 8, !tbaa !9
  %28 = call ptr @gc_malloc(i64 noundef 24) #5
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr %28, ptr %30, align 8, !tbaa !12
  store i32 11, ptr %28, align 8, !tbaa !9
  call void @gc() #5
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 8, !tbaa !9
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %26
  call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.3, i32 noundef 118, ptr noundef nonnull @__PRETTY_FUNCTION__.test_reference_gc) #6
  unreachable

35:                                               ; preds = %26
  %36 = getelementptr inbounds i8, ptr %31, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = icmp eq ptr %37, null
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @__assert_fail(ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.3, i32 noundef 119, ptr noundef nonnull @__PRETTY_FUNCTION__.test_reference_gc) #6
  unreachable

40:                                               ; preds = %35
  %41 = load i32, ptr %28, align 8, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 121, ptr noundef nonnull @__PRETTY_FUNCTION__.test_reference_gc) #6
  unreachable

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

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


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