; LLVM IR from humz2k/sugaryc :: ext/bdwgc (mark_rts)

; 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._GC_arrays = type { i64, i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i64, i64, i64, ptr, ptr, i64, i32, i64, i64, i64, %struct.dl_hashtbl_s, %struct.dl_hashtbl_s, %struct.fnlz_roots_s, i32, ptr, i64, i64, i32, i64, i64, i64, ptr, [64 x ptr], [8 x i8], [64 x ptr], [129 x ptr], [129 x ptr], [129 x ptr], [2049 x i64], [129 x ptr], [4096 x i8], [4096 x i64], [4096 x i64], ptr, [2048 x %struct.roots], [512 x %struct.exclusion], [2048 x ptr] }
%struct.dl_hashtbl_s = type { ptr, i64, i32 }
%struct.fnlz_roots_s = type { ptr, ptr }
%struct.roots = type { ptr, ptr, ptr, i32 }
%struct.exclusion = type { ptr, ptr }
%struct.obj_kind = type { ptr, ptr, i64, i32, i32 }

@GC_arrays = external global %struct._GC_arrays, align 8
@GC_push_typed_structures = external dso_local global ptr, align 8
@GC_n_kinds = external global i32, align 4
@GC_obj_kinds = external global [16 x %struct.obj_kind], align 16
@GC_push_other_roots = external global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @GC_push_roots(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %24, %2
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 42), align 8, !tbaa !11
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %27

12:                                               ; preds = %8
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %14
  %16 = getelementptr inbounds %struct.roots, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %19
  %21 = getelementptr inbounds %struct.roots, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = load i32, ptr %3, align 4, !tbaa !5
  call void @GC_push_conditional_with_exclusions(ptr noundef %17, ptr noundef %22, i32 noundef %23)
  br label %24

24:                                               ; preds = %12
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !19

27:                                               ; preds = %8
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %44, %27
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr @GC_n_kinds, align 4, !tbaa !5
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %32, label %47

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.obj_kind, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 16, !tbaa !21
  %38 = call ptr @GC_base(ptr noundef %37)
  store ptr %38, ptr %7, align 8, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %43

41:                                               ; preds = %32
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  call void @GC_set_mark_bit(ptr noundef %42)
  br label %43

43:                                               ; preds = %41, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = add i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !5
  br label %28, !llvm.loop !23

47:                                               ; preds = %28
  call void @GC_push_finalizer_structures()
  %48 = load ptr, ptr @GC_push_typed_structures, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %52

50:                                               ; preds = %47
  %51 = load ptr, ptr @GC_push_typed_structures, align 8, !tbaa !9
  call void %51()
  br label %52

52:                                               ; preds = %50, %47
  %53 = load ptr, ptr %4, align 8, !tbaa !9
  call void @GC_push_regs_and_stack(ptr noundef %53)
  %54 = load ptr, ptr @GC_push_other_roots, align 8, !tbaa !9
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %52
  %57 = load ptr, ptr @GC_push_other_roots, align 8, !tbaa !9
  call void %57()
  br label %58

58:                                               ; preds = %56, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @GC_push_conditional_with_exclusions(ptr noundef, ptr noundef, i32 noundef) #1

declare ptr @GC_base(ptr noundef) #2

declare void @GC_set_mark_bit(ptr noundef) #2

declare void @GC_push_finalizer_structures() #2

; Function Attrs: nounwind uwtable
declare hidden void @GC_push_regs_and_stack(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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 368}
!12 = !{!"_GC_arrays", !13, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !6, i64 176, !6, i64 180, !6, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !10, i64 216, !10, i64 224, !13, i64 232, !6, i64 240, !13, i64 248, !13, i64 256, !13, i64 264, !14, i64 272, !14, i64 296, !15, i64 320, !6, i64 336, !10, i64 344, !13, i64 352, !13, i64 360, !6, i64 368, !13, i64 376, !13, i64 384, !13, i64 392, !10, i64 400, !7, i64 408, !7, i64 920, !7, i64 928, !7, i64 1440, !7, i64 2472, !7, i64 3504, !7, i64 4536, !7, i64 20928, !7, i64 21960, !7, i64 26056, !7, i64 58824, !10, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!13 = !{!"long", !7, i64 0}
!14 = !{!"dl_hashtbl_s", !10, i64 0, !13, i64 8, !6, i64 16}
!15 = !{!"fnlz_roots_s", !10, i64 0, !10, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"roots", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!18 = !{!17, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !10, i64 0}
!22 = !{!"obj_kind", !10, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !6, i64 28}
!23 = distinct !{!23, !20}


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

%struct._GC_arrays = type { i64, i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i64, i64, i64, ptr, ptr, i64, i32, i64, i64, i64, %struct.dl_hashtbl_s, %struct.dl_hashtbl_s, %struct.fnlz_roots_s, i32, ptr, i64, i64, i32, i64, i64, i64, ptr, [64 x ptr], [8 x i8], [64 x ptr], [129 x ptr], [129 x ptr], [129 x ptr], [2049 x i64], [129 x ptr], [4096 x i8], [4096 x i64], [4096 x i64], ptr, [2048 x %struct.roots], [512 x %struct.exclusion], [2048 x ptr] }
%struct.dl_hashtbl_s = type { ptr, i64, i32 }
%struct.fnlz_roots_s = type { ptr, ptr }
%struct.roots = type { ptr, ptr, ptr, i32 }
%struct.exclusion = type { ptr, ptr }
%struct.obj_kind = type { ptr, ptr, i64, i32, i32 }

@GC_arrays = external local_unnamed_addr global %struct._GC_arrays, align 8
@GC_push_typed_structures = external dso_local local_unnamed_addr global ptr, align 8
@GC_n_kinds = external local_unnamed_addr global i32, align 4
@GC_obj_kinds = external local_unnamed_addr global [16 x %struct.obj_kind], align 16
@GC_push_other_roots = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @GC_push_roots(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 368), align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %2
  %5 = load i32, ptr @GC_n_kinds, align 4, !tbaa !14
  %.not19 = icmp eq i32 %5, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph18

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %6 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 91600), i64 0, i64 %indvars.iv
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  tail call void @GC_push_conditional_with_exclusions(ptr noundef %7, ptr noundef %9, i32 noundef %0)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 368), align 8, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %.preheader, !llvm.loop !18

.lr.ph18:                                         ; preds = %.preheader, %17
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %17 ], [ 0, %.preheader ]
  %13 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %indvars.iv21
  %14 = load ptr, ptr %13, align 16, !tbaa !20
  %15 = tail call ptr @GC_base(ptr noundef %14) #2
  %.not15 = icmp eq ptr %15, null
  br i1 %.not15, label %17, label %16

16:                                               ; preds = %.lr.ph18
  tail call void @GC_set_mark_bit(ptr noundef nonnull %15) #2
  br label %17

17:                                               ; preds = %16, %.lr.ph18
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %18 = load i32, ptr @GC_n_kinds, align 4, !tbaa !14
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %indvars.iv.next22, %19
  br i1 %20, label %.lr.ph18, label %._crit_edge, !llvm.loop !22

._crit_edge:                                      ; preds = %17, %.preheader
  tail call void @GC_push_finalizer_structures() #2
  %21 = load ptr, ptr @GC_push_typed_structures, align 8, !tbaa !23
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %23, label %22

22:                                               ; preds = %._crit_edge
  tail call void %21() #2
  br label %23

23:                                               ; preds = %22, %._crit_edge
  tail call void @GC_push_regs_and_stack(ptr noundef %1)
  %24 = load ptr, ptr @GC_push_other_roots, align 8, !tbaa !23
  %.not14 = icmp eq ptr %24, null
  br i1 %.not14, label %26, label %25

25:                                               ; preds = %23
  tail call void %24() #2
  br label %26

26:                                               ; preds = %25, %23
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @GC_push_conditional_with_exclusions(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @GC_base(ptr noundef) local_unnamed_addr #1

declare void @GC_set_mark_bit(ptr noundef) local_unnamed_addr #1

declare void @GC_push_finalizer_structures() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @GC_push_regs_and_stack(ptr noundef) local_unnamed_addr #0

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 = { 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, !11, i64 368}
!6 = !{!"_GC_arrays", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !11, i64 176, !11, i64 180, !11, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !10, i64 216, !10, i64 224, !7, i64 232, !11, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !12, i64 272, !12, i64 296, !13, i64 320, !11, i64 336, !10, i64 344, !7, i64 352, !7, i64 360, !11, i64 368, !7, i64 376, !7, i64 384, !7, i64 392, !10, i64 400, !8, i64 408, !8, i64 920, !8, i64 928, !8, i64 1440, !8, i64 2472, !8, i64 3504, !8, i64 4536, !8, i64 20928, !8, i64 21960, !8, i64 26056, !8, i64 58824, !10, i64 91592, !8, i64 91600, !8, i64 157136, !8, i64 165328}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"dl_hashtbl_s", !10, i64 0, !7, i64 8, !11, i64 16}
!13 = !{!"fnlz_roots_s", !10, i64 0, !10, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"roots", !10, i64 0, !10, i64 8, !10, i64 16, !11, i64 24}
!17 = !{!16, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !10, i64 0}
!21 = !{!"obj_kind", !10, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !11, i64 28}
!22 = distinct !{!22, !19}
!23 = !{!10, !10, i64 0}


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