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

@GC_arrays = external dso_local 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
define dso_local void @GC_apply_to_all_blocks(ptr noundef nonnull %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %7 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 14), align 8, !tbaa !11
  store ptr %7, ptr %6, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %70, %2
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %74

11:                                               ; preds = %8
  store i64 1023, ptr %5, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %68, %11
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp sge i64 %13, 0
  br i1 %14, label %15, label %69

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.bi, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds [1024 x ptr], ptr %17, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = icmp ule i64 %21, 4095
  br i1 %22, label %48, label %23

23:                                               ; preds = %15
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bi, ptr %24, i32 0, i32 0
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds [1024 x ptr], ptr %25, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hblkhdr, ptr %28, i32 0, i32 4
  %30 = load i8, ptr %29, align 1, !tbaa !16
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 4
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %45, label %34

34:                                               ; preds = %23
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.bi, ptr %36, i32 0, i32 3
  %38 = load i64, ptr %37, align 8, !tbaa !19
  %39 = shl i64 %38, 10
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = add i64 %39, %40
  %42 = shl i64 %41, 12
  %43 = inttoptr i64 %42 to ptr
  %44 = load i64, ptr %4, align 8, !tbaa !9
  call void %35(ptr noundef %43, i64 noundef %44)
  br label %45

45:                                               ; preds = %34, %23
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = add nsw i64 %46, -1
  store i64 %47, ptr %5, align 8, !tbaa !9
  br label %68

48:                                               ; preds = %15
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.bi, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds [1024 x ptr], ptr %50, i64 0, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %58

55:                                               ; preds = %48
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = add nsw i64 %56, -1
  store i64 %57, ptr %5, align 8, !tbaa !9
  br label %67

58:                                               ; preds = %48
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.bi, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = getelementptr inbounds [1024 x ptr], ptr %60, i64 0, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = ptrtoint ptr %63 to i64
  %65 = load i64, ptr %5, align 8, !tbaa !9
  %66 = sub nsw i64 %65, %64
  store i64 %66, ptr %5, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %58, %55
  br label %68

68:                                               ; preds = %67, %45
  br label %12, !llvm.loop !21

69:                                               ; preds = %12
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.bi, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !23
  store ptr %73, ptr %6, align 8, !tbaa !5
  br label %8, !llvm.loop !24

74:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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


; 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

; Function Attrs: nounwind uwtable
define dso_local void @GC_apply_to_all_blocks(ptr nocapture noundef nonnull readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %.021 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 112), align 8, !tbaa !5
  %.not22 = icmp eq ptr %.021, null
  br i1 %.not22, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %2, %29
  %.023 = phi ptr [ %.0, %29 ], [ %.021, %2 ]
  %3 = getelementptr inbounds i8, ptr %.023, i64 8208
  br label %4

4:                                                ; preds = %.preheader, %27
  %.01720 = phi i64 [ 1023, %.preheader ], [ %.1, %27 ]
  %5 = getelementptr inbounds [1024 x ptr], ptr %.023, i64 0, i64 %.01720
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = ptrtoint ptr %6 to i64
  %8 = icmp ult ptr %6, inttoptr (i64 4096 to ptr)
  br i1 %8, label %21, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %6, i64 25
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = and i8 %11, 4
  %.not19 = icmp eq i8 %12, 0
  br i1 %.not19, label %13, label %19

13:                                               ; preds = %9
  %14 = load i64, ptr %3, align 8, !tbaa !13
  %15 = shl i64 %14, 22
  %16 = shl i64 %.01720, 12
  %17 = add i64 %15, %16
  %18 = inttoptr i64 %17 to ptr
  tail call void %0(ptr noundef %18, i64 noundef %1) #1
  br label %19

19:                                               ; preds = %13, %9
  %20 = add nsw i64 %.01720, -1
  br label %27

21:                                               ; preds = %4
  %22 = icmp eq ptr %6, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %21
  %24 = add nsw i64 %.01720, -1
  br label %27

25:                                               ; preds = %21
  %26 = sub nsw i64 %.01720, %7
  br label %27

27:                                               ; preds = %23, %25, %19
  %.1 = phi i64 [ %24, %23 ], [ %26, %25 ], [ %20, %19 ]
  %28 = icmp sgt i64 %.1, -1
  br i1 %28, label %4, label %29, !llvm.loop !15

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %.023, i64 8192
  %.0 = load ptr, ptr %30, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !17

._crit_edge:                                      ; preds = %29, %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" }
attributes #1 = { 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, !7, i64 25}
!10 = !{!"hblkhdr", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !11, i64 26, !12, i64 32, !12, i64 40, !6, i64 48, !12, i64 56, !7, i64 64}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8208}
!14 = !{!"bi", !7, i64 0, !6, i64 8192, !6, i64 8200, !12, i64 8208, !6, i64 8216}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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