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

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

@GC_arrays = external dso_local global %struct._GC_arrays, align 8
@GC_is_tmp_root.last_root_set = external hidden global i32, align 4

; 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 i32 @GC_is_tmp_root(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %5 = load i32, ptr @GC_is_tmp_root.last_root_set, align 4, !tbaa !9
  store i32 %5, ptr %3, align 4, !tbaa !9
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = load i32, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 42), align 8, !tbaa !11
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %9, label %35

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = ptrtoint ptr %10 to i64
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %13
  %15 = getelementptr inbounds %struct.roots, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = ptrtoint ptr %16 to i64
  %18 = icmp uge i64 %11, %17
  br i1 %18, label %19, label %35

19:                                               ; preds = %9
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %23
  %25 = getelementptr inbounds %struct.roots, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = ptrtoint ptr %26 to i64
  %28 = icmp ult i64 %21, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %19
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %31
  %33 = getelementptr inbounds %struct.roots, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 8, !tbaa !19
  store i32 %34, ptr %4, align 4, !tbaa !9
  br label %72

35:                                               ; preds = %19, %9, %1
  store i32 0, ptr %4, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %68, %35
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = load i32, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 42), align 8, !tbaa !11
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %71

40:                                               ; preds = %36
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = ptrtoint ptr %41 to i64
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %44
  %46 = getelementptr inbounds %struct.roots, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = ptrtoint ptr %47 to i64
  %49 = icmp uge i64 %42, %48
  br i1 %49, label %50, label %67

50:                                               ; preds = %40
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = ptrtoint ptr %51 to i64
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %54
  %56 = getelementptr inbounds %struct.roots, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !18
  %58 = ptrtoint ptr %57 to i64
  %59 = icmp ult i64 %52, %58
  br i1 %59, label %60, label %67

60:                                               ; preds = %50
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %62
  %64 = getelementptr inbounds %struct.roots, ptr %63, i32 0, i32 3
  %65 = load i32, ptr %64, align 8, !tbaa !19
  store i32 %65, ptr %4, align 4, !tbaa !9
  %66 = load i32, ptr %3, align 4, !tbaa !9
  store i32 %66, ptr @GC_is_tmp_root.last_root_set, align 4, !tbaa !9
  br label %71

67:                                               ; preds = %50, %40
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %3, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %3, align 4, !tbaa !9
  br label %36, !llvm.loop !20

71:                                               ; preds = %60, %36
  br label %72

72:                                               ; preds = %71, %29
  %73 = load i32, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %73
}

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 368}
!12 = !{!"_GC_arrays", !13, i64 0, !13, i64 8, !13, i64 16, !6, 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, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !6, i64 216, !6, i64 224, !13, i64 232, !10, i64 240, !13, i64 248, !13, i64 256, !13, i64 264, !14, i64 272, !14, i64 296, !15, i64 320, !10, i64 336, !6, i64 344, !13, i64 352, !13, i64 360, !10, i64 368, !13, i64 376, !13, i64 384, !13, i64 392, !6, 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, !6, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!13 = !{!"long", !7, i64 0}
!14 = !{!"dl_hashtbl_s", !6, i64 0, !13, i64 8, !10, i64 16}
!15 = !{!"fnlz_roots_s", !6, i64 0, !6, i64 8}
!16 = !{!17, !6, i64 0}
!17 = !{!"roots", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!18 = !{!17, !6, i64 8}
!19 = !{!17, !10, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%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 }

@GC_arrays = external dso_local local_unnamed_addr global %struct._GC_arrays, align 8
@GC_is_tmp_root.last_root_set = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local i32 @GC_is_tmp_root(ptr noundef readnone %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @GC_is_tmp_root.last_root_set, align 4, !tbaa !5
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 368), align 8, !tbaa !9
  %4 = icmp slt i32 %2, %3
  br i1 %4, label %5, label %16

5:                                                ; preds = %1
  %6 = sext i32 %2 to i64
  %7 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 91600), i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %.not = icmp ugt ptr %8, %0
  br i1 %.not, label %16, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %7, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = icmp ugt ptr %11, %0
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %7, i64 24
  %15 = load i32, ptr %14, align 8, !tbaa !18
  br label %.loopexit

16:                                               ; preds = %9, %5, %1
  %17 = icmp sgt i32 %3, 0
  br i1 %17, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %16
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %28 ]
  %18 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 91600), i64 0, i64 %indvars.iv
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %.not18 = icmp ugt ptr %19, %0
  br i1 %.not18, label %28, label %20

20:                                               ; preds = %.lr.ph
  %21 = getelementptr inbounds i8, ptr %18, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = icmp ugt ptr %22, %0
  br i1 %23, label %24, label %28

24:                                               ; preds = %20
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = getelementptr inbounds i8, ptr %18, i64 24
  %27 = load i32, ptr %26, align 8, !tbaa !18
  store i32 %25, ptr @GC_is_tmp_root.last_root_set, align 4, !tbaa !5
  br label %.loopexit

28:                                               ; preds = %.lr.ph, %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %28, %16, %24, %13
  %.0 = phi i32 [ %15, %13 ], [ %27, %24 ], [ 0, %16 ], [ 0, %28 ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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 368}
!10 = !{!"_GC_arrays", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !6, i64 176, !6, i64 180, !6, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !12, i64 216, !12, i64 224, !11, i64 232, !6, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !13, i64 272, !13, i64 296, !14, i64 320, !6, i64 336, !12, i64 344, !11, i64 352, !11, i64 360, !6, i64 368, !11, i64 376, !11, i64 384, !11, i64 392, !12, 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, !12, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"dl_hashtbl_s", !12, i64 0, !11, i64 8, !6, i64 16}
!14 = !{!"fnlz_roots_s", !12, i64 0, !12, i64 8}
!15 = !{!16, !12, i64 0}
!16 = !{!"roots", !12, i64 0, !12, i64 8, !12, i64 16, !6, i64 24}
!17 = !{!16, !12, i64 8}
!18 = !{!16, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass