; LLVM IR from brewlin/garbage-collect :: gc-try (mark_sweep)

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

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gc_mark(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @is_pointer_to_heap(ptr noundef %7)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i32 1, ptr %5, align 4
  br label %59

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call ptr @get_header(ptr noundef %12, ptr noundef %13)
  store ptr %14, ptr %4, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %11
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i32 1, ptr %5, align 4
  br label %59

18:                                               ; preds = %11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.header, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = and i64 %21, 1
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %26, label %24

24:                                               ; preds = %18
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %5, align 4
  br label %59

26:                                               ; preds = %18
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.header, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = and i64 %29, 2
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %26
  store i32 1, ptr %5, align 4
  br label %59

33:                                               ; preds = %26
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.header, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = or i64 %36, 2
  store i64 %37, ptr %35, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %38, ptr %6, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %55, %33
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.header, ptr %41, i64 1
  %43 = ptrtoint ptr %42 to i64
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.header, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !12
  %47 = sub i64 %46, 48
  %48 = add i64 %43, %47
  %49 = inttoptr i64 %48 to ptr
  %50 = icmp ult ptr %40, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %39
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %58

52:                                               ; preds = %39
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  call void @gc_mark(ptr noundef %54)
  br label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i32 1
  store ptr %57, ptr %6, align 8, !tbaa !5
  br label %39, !llvm.loop !13

58:                                               ; preds = %51
  store i32 0, ptr %5, align 4
  br label %59

59:                                               ; preds = %58, %32, %24, %16, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %60 = load i32, ptr %5, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  ret void

62:                                               ; preds = %59
  unreachable
}

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

declare ptr @is_pointer_to_heap(ptr noundef) #2

declare ptr @get_header(ptr noundef, ptr noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { 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 8}
!10 = !{!"header", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gc_mark(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @is_pointer_to_heap(ptr noundef %0) #3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = tail call ptr @get_header(ptr noundef nonnull %2, ptr noundef %0) #3
  %.not14 = icmp eq ptr %4, null
  br i1 %.not14, label %.loopexit.sink.split, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = and i64 %7, 1
  %.not15 = icmp eq i64 %8, 0
  br i1 %.not15, label %.loopexit.sink.split, label %9

9:                                                ; preds = %5
  %10 = and i64 %7, 2
  %.not16 = icmp eq i64 %10, 0
  br i1 %.not16, label %11, label %.loopexit

11:                                               ; preds = %9
  %12 = or disjoint i64 %7, 2
  store i64 %12, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %4, i64 48
  %14 = ptrtoint ptr %13 to i64
  %15 = getelementptr inbounds i8, ptr %4, i64 16
  %16 = add i64 %14, -48
  %17 = load i64, ptr %15, align 8, !tbaa !11
  %18 = add i64 %16, %17
  %19 = inttoptr i64 %18 to ptr
  %20 = icmp ugt ptr %19, %0
  br i1 %20, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.017 = phi ptr [ %22, %.lr.ph ], [ %0, %11 ]
  %21 = load ptr, ptr %.017, align 8, !tbaa !12
  tail call void @gc_mark(ptr noundef %21)
  %22 = getelementptr inbounds i8, ptr %.017, i64 1
  %23 = load i64, ptr %15, align 8, !tbaa !11
  %24 = add i64 %16, %23
  %25 = inttoptr i64 %24 to ptr
  %26 = icmp ult ptr %22, %25
  br i1 %26, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit.sink.split:                             ; preds = %5, %3
  %.str.1.sink = phi ptr [ @.str, %3 ], [ @.str.1, %5 ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.loopexit.sink.split, %11, %9, %1
  ret void
}

declare ptr @is_pointer_to_heap(ptr noundef) local_unnamed_addr #1

declare ptr @get_header(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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 = { 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 = { 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, !7, i64 8}
!6 = !{!"header", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass