; 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: nounwind uwtable
declare dso_local ptr @GC_find_header(ptr noundef) #0

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

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

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

12:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %73

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.GC_hblk_s, ptr %14, i64 1
  %16 = call ptr @GC_find_header(ptr noundef %15)
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  store i32 1, ptr %6, align 4
  br label %73

19:                                               ; preds = %13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.GC_hblk_s, ptr %20, i64 1
  store ptr %21, ptr %5, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %69, %19
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = ptrtoint ptr %23 to i64
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = ptrtoint ptr %25 to i64
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = add i64 %26, %27
  %29 = icmp ult i64 %24, %28
  br i1 %29, label %30, label %72

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = lshr i64 %34, 22
  store i64 %35, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = and i64 %36, 2047
  %38 = getelementptr inbounds [2048 x ptr], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 61), i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %9, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %52, %32
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.bi, ptr %41, i32 0, i32 3
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = icmp ne i64 %43, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %40
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 28), align 8, !tbaa !13
  %49 = icmp ne ptr %47, %48
  br label %50

50:                                               ; preds = %46, %40
  %51 = phi i1 [ false, %40 ], [ %49, %46 ]
  br i1 %51, label %52, label %56

52:                                               ; preds = %50
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.bi, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !18
  store ptr %55, ptr %9, align 8, !tbaa !5
  br label %40, !llvm.loop !19

56:                                               ; preds = %50
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %57, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %58

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.bi, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = ptrtoint ptr %62 to i64
  %64 = lshr i64 %63, 12
  %65 = and i64 %64, 1023
  %66 = getelementptr inbounds [1024 x ptr], ptr %61, i64 0, i64 %65
  store ptr null, ptr %66, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %67

67:                                               ; preds = %59
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.GC_hblk_s, ptr %70, i64 1
  store ptr %71, ptr %5, align 8, !tbaa !5
  br label %22, !llvm.loop !21

72:                                               ; preds = %22
  store i32 0, ptr %6, align 4
  br label %73

73:                                               ; preds = %72, %18, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %74 = load i32, ptr %6, align 4
  switch i32 %74, label %76 [
    i32 0, label %75
    i32 1, label %75
  ]

75:                                               ; preds = %73, %73
  ret void

76:                                               ; preds = %73
  unreachable
}

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 = { 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 = !{!12, !10, i64 8208}
!12 = !{!"bi", !7, i64 0, !6, i64 8192, !6, i64 8200, !10, i64 8208, !6, i64 8216}
!13 = !{!14, !6, i64 216}
!14 = !{!"_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, !15, i64 176, !15, i64 180, !15, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !6, i64 216, !6, i64 224, !10, i64 232, !15, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !16, i64 272, !16, i64 296, !17, i64 320, !15, i64 336, !6, i64 344, !10, i64 352, !10, i64 360, !15, 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}
!15 = !{!"int", !7, i64 0}
!16 = !{!"dl_hashtbl_s", !6, i64 0, !10, i64 8, !15, i64 16}
!17 = !{!"fnlz_roots_s", !6, i64 0, !6, i64 8}
!18 = !{!12, !6, i64 8216}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !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 }

@GC_arrays = external local_unnamed_addr global %struct._GC_arrays, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @GC_find_header(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GC_remove_counts(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %1, 4097
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 4096
  %6 = tail call ptr @GC_find_header(ptr noundef nonnull %5)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %4
  %8 = ptrtoint ptr %0 to i64
  %9 = add i64 %8, %1
  %10 = ptrtoint ptr %5 to i64
  %11 = icmp ugt i64 %9, %10
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %24
  %12 = phi i64 [ %29, %24 ], [ %10, %.preheader ]
  %.01518 = phi ptr [ %28, %24 ], [ %5, %.preheader ]
  %13 = lshr i64 %12, 22
  %14 = and i64 %13, 2047
  %15 = getelementptr inbounds [2048 x ptr], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 165328), i64 0, i64 %14
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 216), align 8
  br label %17

17:                                               ; preds = %17, %.lr.ph
  %.0.in = phi ptr [ %15, %.lr.ph ], [ %23, %17 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.0, i64 8208
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = icmp ne i64 %19, %13
  %21 = icmp ne ptr %.0, %16
  %22 = select i1 %20, i1 %21, i1 false
  %23 = getelementptr inbounds i8, ptr %.0, i64 8216
  br i1 %22, label %17, label %24, !llvm.loop !12

24:                                               ; preds = %17
  %25 = lshr i64 %12, 12
  %26 = and i64 %25, 1023
  %27 = getelementptr inbounds [1024 x ptr], ptr %.0, i64 0, i64 %26
  store ptr null, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.01518, i64 4096
  %29 = ptrtoint ptr %28 to i64
  %30 = icmp ugt i64 %9, %29
  br i1 %30, label %.lr.ph, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %24, %.preheader, %4, %2
  ret void
}

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

!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 8208}
!10 = !{!"bi", !7, i64 0, !6, i64 8192, !6, i64 8200, !11, i64 8208, !6, i64 8216}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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