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

; 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.GC_hblk_s = type { [4096 x i8] }
%struct.bi = type { [1024 x ptr], ptr, ptr, i64, ptr }

@GC_arrays = external global %struct._GC_arrays, 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
declare hidden i32 @get_index(i64 noundef) #1

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

13:                                               ; preds = %33, %2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = add i64 %17, %18
  %20 = icmp ult i64 %15, %19
  br i1 %20, label %21, label %36

21:                                               ; preds = %13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = ptrtoint ptr %22 to i64
  %24 = call i32 @get_index(i64 noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %113

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = icmp ugt i64 %29, -4194305
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br label %36

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.GC_hblk_s, ptr %34, i64 1024
  store ptr %35, ptr %6, align 8, !tbaa !5
  br label %13, !llvm.loop !11

36:                                               ; preds = %31, %13
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = ptrtoint ptr %37 to i64
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = add i64 %38, %39
  %41 = sub i64 %40, 1
  %42 = call i32 @get_index(i64 noundef %41)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %113

45:                                               ; preds = %36
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.GC_hblk_s, ptr %46, i64 1
  store ptr %47, ptr %6, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %109, %45
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = ptrtoint ptr %49 to i64
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = ptrtoint ptr %51 to i64
  %53 = load i64, ptr %5, align 8, !tbaa !9
  %54 = add i64 %52, %53
  %55 = icmp ult i64 %50, %54
  br i1 %55, label %56, label %112

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = ptrtoint ptr %57 to i64
  %60 = ptrtoint ptr %58 to i64
  %61 = sub i64 %59, %60
  %62 = ashr i64 %61, 12
  store i64 %62, ptr %8, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  br label %64

64:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = ptrtoint ptr %65 to i64
  %67 = lshr i64 %66, 22
  store i64 %67, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %68 = load i64, ptr %10, align 8, !tbaa !9
  %69 = and i64 %68, 2047
  %70 = getelementptr inbounds [2048 x ptr], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 61), i64 0, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  store ptr %71, ptr %11, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %84, %64
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.bi, ptr %73, i32 0, i32 3
  %75 = load i64, ptr %74, align 8, !tbaa !13
  %76 = load i64, ptr %10, align 8, !tbaa !9
  %77 = icmp ne i64 %75, %76
  br i1 %77, label %78, label %82

78:                                               ; preds = %72
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 28), align 8, !tbaa !15
  %81 = icmp ne ptr %79, %80
  br label %82

82:                                               ; preds = %78, %72
  %83 = phi i1 [ false, %72 ], [ %81, %78 ]
  br i1 %83, label %84, label %88

84:                                               ; preds = %82
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.bi, ptr %85, i32 0, i32 4
  %87 = load ptr, ptr %86, align 8, !tbaa !20
  store ptr %87, ptr %11, align 8, !tbaa !5
  br label %72, !llvm.loop !21

88:                                               ; preds = %82
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %89, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %90

90:                                               ; preds = %88
  br label %91

91:                                               ; preds = %90
  %92 = load i64, ptr %8, align 8, !tbaa !9
  %93 = icmp ugt i64 %92, 4095
  br i1 %93, label %94, label %95

94:                                               ; preds = %91
  br label %97

95:                                               ; preds = %91
  %96 = load i64, ptr %8, align 8, !tbaa !9
  br label %97

97:                                               ; preds = %95, %94
  %98 = phi i64 [ 4095, %94 ], [ %96, %95 ]
  %99 = inttoptr i64 %98 to ptr
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.bi, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = ptrtoint ptr %102 to i64
  %104 = lshr i64 %103, 12
  %105 = and i64 %104, 1023
  %106 = getelementptr inbounds [1024 x ptr], ptr %101, i64 0, i64 %105
  store ptr %99, ptr %106, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %107

107:                                              ; preds = %97
  br label %108

108:                                              ; preds = %107
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %109

109:                                              ; preds = %108
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.GC_hblk_s, ptr %110, i64 1
  store ptr %111, ptr %6, align 8, !tbaa !5
  br label %48, !llvm.loop !22

112:                                              ; preds = %48
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %113

113:                                              ; preds = %112, %44, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %114 = load i32, ptr %3, align 4
  ret i32 %114
}

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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 8208}
!14 = !{!"bi", !7, i64 0, !6, i64 8192, !6, i64 8200, !10, i64 8208, !6, i64 8216}
!15 = !{!16, !6, i64 216}
!16 = !{!"_GC_arrays", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, 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, !17, i64 176, !17, i64 180, !17, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !6, i64 216, !6, i64 224, !10, i64 232, !17, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !18, i64 272, !18, i64 296, !19, i64 320, !17, i64 336, !6, i64 344, !10, i64 352, !10, i64 360, !17, i64 368, !10, i64 376, !10, i64 384, !10, 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}
!17 = !{!"int", !7, i64 0}
!18 = !{!"dl_hashtbl_s", !6, i64 0, !10, i64 8, !17, i64 16}
!19 = !{!"fnlz_roots_s", !6, i64 0, !6, i64 8}
!20 = !{!14, !6, i64 8216}
!21 = distinct !{!21, !12}
!22 = distinct !{!22, !12}


; 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 local_unnamed_addr global %struct._GC_arrays, align 8

; Function Attrs: nounwind uwtable
declare hidden i32 @get_index(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @GC_install_counts(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %0 to i64
  %4 = add i64 %3, %1
  %5 = icmp ugt i64 %4, %3
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %8
  %6 = phi i64 [ %11, %8 ], [ %3, %2 ]
  %.02836 = phi ptr [ %10, %8 ], [ %0, %2 ]
  %7 = tail call i32 @get_index(i64 noundef %6)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.loopexit, label %8

8:                                                ; preds = %.lr.ph
  %9 = icmp ule ptr %.02836, inttoptr (i64 -4194305 to ptr)
  %10 = getelementptr inbounds i8, ptr %.02836, i64 4194304
  %11 = ptrtoint ptr %10 to i64
  %12 = icmp ugt i64 %4, %11
  %or.cond = select i1 %9, i1 %12, i1 false
  br i1 %or.cond, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %8, %2
  %13 = add i64 %4, -1
  %14 = tail call i32 @get_index(i64 noundef %13)
  %.not31 = icmp eq i32 %14, 0
  br i1 %.not31, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %.141 = getelementptr inbounds i8, ptr %0, i64 4096
  %15 = ptrtoint ptr %.141 to i64
  %16 = icmp ugt i64 %4, %15
  br i1 %16, label %.lr.ph43, label %.loopexit

.lr.ph43:                                         ; preds = %.preheader, %30
  %17 = phi i64 [ %37, %30 ], [ %15, %.preheader ]
  %.142 = phi ptr [ %.1, %30 ], [ %.141, %.preheader ]
  %18 = sub i64 %17, %3
  %19 = lshr i64 %17, 22
  %20 = and i64 %19, 2047
  %21 = getelementptr inbounds [2048 x ptr], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 165328), i64 0, i64 %20
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 216), align 8
  br label %23

23:                                               ; preds = %23, %.lr.ph43
  %.0.in = phi ptr [ %21, %.lr.ph43 ], [ %29, %23 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !7
  %24 = getelementptr inbounds i8, ptr %.0, i64 8208
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = icmp ne i64 %25, %19
  %27 = icmp ne ptr %.0, %22
  %28 = select i1 %26, i1 %27, i1 false
  %29 = getelementptr inbounds i8, ptr %.0, i64 8216
  br i1 %28, label %23, label %30, !llvm.loop !14

30:                                               ; preds = %23
  %31 = ashr i64 %18, 12
  %32 = tail call i64 @llvm.umin.i64(i64 %31, i64 4095)
  %33 = inttoptr i64 %32 to ptr
  %34 = lshr i64 %17, 12
  %35 = and i64 %34, 1023
  %36 = getelementptr inbounds [1024 x ptr], ptr %.0, i64 0, i64 %35
  store ptr %33, ptr %36, align 8, !tbaa !7
  %.1 = getelementptr inbounds i8, ptr %.142, i64 4096
  %37 = ptrtoint ptr %.1 to i64
  %38 = icmp ugt i64 %4, %37
  br i1 %38, label %.lr.ph43, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %30, %.preheader, %._crit_edge
  %.027 = phi i32 [ 0, %._crit_edge ], [ 1, %.preheader ], [ 1, %30 ], [ 0, %.lr.ph ]
  ret i32 %.027
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #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 speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !13, i64 8208}
!12 = !{!"bi", !9, i64 0, !8, i64 8192, !8, i64 8200, !13, i64 8208, !8, i64 8216}
!13 = !{!"long", !9, i64 0}
!14 = distinct !{!14, !6}
!15 = distinct !{!15, !6}


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