; LLVM IR from brewlin/garbage-collect :: copying-or-mark (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.t = type { i32, ptr }

@to = external global i32, align 4
@from = external global i32, align 4
@root_used = external global i64, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__.test_add_root_gc = external hidden unnamed_addr constant [24 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [11 x i8], align 1

declare void @gc_init(i64 noundef) #0

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

; Function Attrs: 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) #0

; Function Attrs: 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_add_root_gc() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @gc_init(i64 noundef 64)
  %5 = load i32, ptr @to, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %0
  br label %9

8:                                                ; preds = %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 71, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

9:                                                ; preds = %7
  %10 = load i32, ptr @from, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  br label %14

13:                                               ; preds = %9
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 72, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

14:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %15 = call ptr @gc_malloc(i64 noundef 16)
  store ptr %15, ptr %1, align 8, !tbaa !9
  %16 = load ptr, ptr %1, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.t, ptr %16, i32 0, i32 0
  store i32 1, ptr %17, align 8, !tbaa !11
  call void @add_roots(ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %18 = call ptr @gc_malloc(i64 noundef 16)
  store ptr %18, ptr %2, align 8, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !9
  %20 = load ptr, ptr %1, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.t, ptr %20, i32 0, i32 1
  store ptr %19, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %2, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.t, ptr %22, i32 0, i32 0
  store i32 2, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %1, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %14
  br label %28

27:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 82, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

28:                                               ; preds = %26
  %29 = load ptr, ptr %2, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  br label %33

32:                                               ; preds = %28
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 83, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

33:                                               ; preds = %31
  %34 = load ptr, ptr %1, align 8, !tbaa !9
  %35 = load ptr, ptr %2, align 8, !tbaa !9
  %36 = icmp ne ptr %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  br label %39

38:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 84, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

39:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %40 = call ptr @gc_malloc(i64 noundef 16)
  store ptr %40, ptr %3, align 8, !tbaa !9
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  br label %45

44:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 96, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

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

48:                                               ; preds = %45
  br label %50

49:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 97, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

50:                                               ; preds = %48
  %51 = load i32, ptr @from, align 4, !tbaa !5
  %52 = icmp eq i32 %51, 2
  br i1 %52, label %53, label %54

53:                                               ; preds = %50
  br label %55

54:                                               ; preds = %50
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 98, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

55:                                               ; preds = %53
  %56 = load i64, ptr @root_used, align 8, !tbaa !14
  %57 = add i64 %56, -1
  store i64 %57, ptr @root_used, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %58 = call ptr @gc_malloc(i64 noundef 16)
  store ptr %58, ptr %4, align 8, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  br label %63

62:                                               ; preds = %55
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.1, i32 noundef 109, ptr noundef @__PRETTY_FUNCTION__.test_add_root_gc) #4
  unreachable

63:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn nounwind }
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, !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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"t", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !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"

@to = external local_unnamed_addr global i32, align 4
@from = external local_unnamed_addr global i32, align 4
@root_used = external local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__.test_add_root_gc = external hidden unnamed_addr constant [24 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [11 x i8], align 1

declare void @gc_init(i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 #0

; 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_add_root_gc() local_unnamed_addr #3 {
  %1 = alloca ptr, align 8
  tail call void @gc_init(i64 noundef 64) #4
  %2 = load i32, ptr @to, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %5, label %4

4:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 71, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

5:                                                ; preds = %0
  %6 = load i32, ptr @from, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 72, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %10 = tail call ptr @gc_malloc(i64 noundef 16) #4
  store ptr %10, ptr %1, align 8, !tbaa !9
  store i32 1, ptr %10, align 8, !tbaa !11
  call void @add_roots(ptr noundef nonnull %1) #4
  %11 = call ptr @gc_malloc(i64 noundef 16) #4
  %12 = load ptr, ptr %1, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %11, ptr %13, align 8, !tbaa !13
  store i32 2, ptr %11, align 8, !tbaa !11
  %.not6 = icmp eq ptr %12, %11
  br i1 %.not6, label %14, label %15

14:                                               ; preds = %9
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 84, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

15:                                               ; preds = %9
  %16 = call ptr @gc_malloc(i64 noundef 16) #4
  %17 = icmp eq ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 96, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

19:                                               ; preds = %15
  %20 = load i32, ptr @to, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 97, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

23:                                               ; preds = %19
  %24 = load i32, ptr @from, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 2
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 98, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

27:                                               ; preds = %23
  %28 = load i64, ptr @root_used, align 8, !tbaa !14
  %29 = add i64 %28, -1
  store i64 %29, ptr @root_used, align 8, !tbaa !14
  %30 = call ptr @gc_malloc(i64 noundef 16) #4
  %.not7 = icmp eq ptr %30, null
  br i1 %.not7, label %31, label %32

31:                                               ; preds = %27
  call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i32 noundef 109, ptr noundef nonnull @__PRETTY_FUNCTION__.test_add_root_gc) #5
  unreachable

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret void
}

declare void @add_roots(ptr noundef) local_unnamed_addr #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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"t", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}


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