; 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
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.test_auto_gc = external hidden unnamed_addr constant [20 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
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_auto_gc() #0 {
  %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 25, ptr noundef @__PRETTY_FUNCTION__.test_auto_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 26, ptr noundef @__PRETTY_FUNCTION__.test_auto_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 @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 35, ptr noundef @__PRETTY_FUNCTION__.test_auto_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 36, ptr noundef @__PRETTY_FUNCTION__.test_auto_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 37, ptr noundef @__PRETTY_FUNCTION__.test_auto_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 = getelementptr inbounds %struct.t, ptr %41, i32 0, i32 0
  store i32 100, ptr %42, align 8, !tbaa !11
  %43 = load i32, ptr @to, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  br label %47

46:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 46, ptr noundef @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

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

50:                                               ; preds = %47
  br label %52

51:                                               ; preds = %47
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 47, ptr noundef @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

52:                                               ; preds = %50
  %53 = load ptr, ptr %3, align 8, !tbaa !9
  %54 = load ptr, ptr %2, align 8, !tbaa !9
  %55 = icmp eq ptr %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  br label %58

57:                                               ; preds = %52
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 51, ptr noundef @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

58:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %59 = call ptr @gc_malloc(i64 noundef 16)
  store ptr %59, ptr %4, align 8, !tbaa !9
  %60 = load ptr, ptr %3, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.t, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !11
  %63 = icmp eq i32 %62, 100
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  br label %66

65:                                               ; preds = %58
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 56, ptr noundef @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

66:                                               ; preds = %64
  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 @gc_init(i64 noundef) #1

; 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.start.p0(i64 immarg, ptr nocapture) #3

declare ptr @gc_malloc(i64 noundef) #1

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

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 = { "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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}


; 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
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.test_auto_gc = external hidden unnamed_addr constant [20 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
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_auto_gc() local_unnamed_addr #0 {
  tail call void @gc_init(i64 noundef 64) #3
  %1 = load i32, ptr @to, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 0
  br i1 %2, label %4, label %3

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

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

7:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 26, ptr noundef nonnull @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

8:                                                ; preds = %4
  %9 = tail call ptr @gc_malloc(i64 noundef 16) #3
  store i32 1, ptr %9, align 8, !tbaa !9
  %10 = tail call ptr @gc_malloc(i64 noundef 16) #3
  %11 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %10, ptr %11, align 8, !tbaa !12
  store i32 2, ptr %10, align 8, !tbaa !9
  %.not = icmp eq ptr %9, %10
  br i1 %.not, label %12, label %13

12:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 37, ptr noundef nonnull @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

13:                                               ; preds = %8
  %14 = tail call ptr @gc_malloc(i64 noundef 16) #3
  store i32 100, ptr %14, align 8, !tbaa !9
  %15 = load i32, ptr @to, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 46, ptr noundef nonnull @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

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

21:                                               ; preds = %18
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 47, ptr noundef nonnull @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

22:                                               ; preds = %18
  %23 = icmp eq ptr %14, %10
  br i1 %23, label %25, label %24

24:                                               ; preds = %22
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 51, ptr noundef nonnull @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

25:                                               ; preds = %22
  %26 = tail call ptr @gc_malloc(i64 noundef 16) #3
  %27 = load i32, ptr %14, align 8, !tbaa !9
  %28 = icmp eq i32 %27, 100
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 56, ptr noundef nonnull @__PRETTY_FUNCTION__.test_auto_gc) #4
  unreachable

30:                                               ; preds = %25
  ret void
}

declare void @gc_init(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 #2

declare ptr @gc_malloc(i64 noundef) local_unnamed_addr #1

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 = { "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 = { 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 }
attributes #4 = { 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, !6, i64 0}
!10 = !{!"t", !6, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}


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