; 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.finalizable_object = type { %struct.hash_chain_entry, ptr, ptr, i64, ptr }
%struct.hash_chain_entry = type { i64, ptr }

@GC_arrays = external dso_local global %struct._GC_arrays, align 8
@.str.41 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [24 x i8], align 1

; 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 dso_local void @GC_printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @GC_dump_finalization() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 37), align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %0
  br label %12

8:                                                ; preds = %0
  %9 = load i32, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 38), align 8, !tbaa !14
  %10 = zext i32 %9 to i64
  %11 = shl i64 1, %10
  br label %12

12:                                               ; preds = %8, %7
  %13 = phi i64 [ 0, %7 ], [ %11, %8 ]
  store i64 %13, ptr %3, align 8, !tbaa !15
  call void (ptr, ...) @GC_printf(ptr noundef @.str.41)
  call void @GC_dump_finalization_links(ptr noundef getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 36))
  call void (ptr, ...) @GC_printf(ptr noundef @.str.42)
  call void @GC_dump_finalization_links(ptr noundef getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 35))
  call void (ptr, ...) @GC_printf(ptr noundef @.str.43)
  store i64 0, ptr %2, align 8, !tbaa !15
  br label %14

14:                                               ; preds = %40, %12
  %15 = load i64, ptr %2, align 8, !tbaa !15
  %16 = load i64, ptr %3, align 8, !tbaa !15
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %43

18:                                               ; preds = %14
  %19 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 37), align 8, !tbaa !5
  %20 = load i64, ptr %2, align 8, !tbaa !15
  %21 = getelementptr inbounds ptr, ptr %19, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  store ptr %22, ptr %1, align 8, !tbaa !16
  br label %23

23:                                               ; preds = %34, %18
  %24 = load ptr, ptr %1, align 8, !tbaa !16
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %39

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %27 = load ptr, ptr %1, align 8, !tbaa !16
  %28 = getelementptr inbounds %struct.finalizable_object, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.hash_chain_entry, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !17
  %31 = xor i64 %30, -1
  %32 = inttoptr i64 %31 to ptr
  store ptr %32, ptr %4, align 8, !tbaa !16
  %33 = load ptr, ptr %4, align 8, !tbaa !16
  call void (ptr, ...) @GC_printf(ptr noundef @.str.44, ptr noundef %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %34

34:                                               ; preds = %26
  %35 = load ptr, ptr %1, align 8, !tbaa !16
  %36 = getelementptr inbounds %struct.finalizable_object, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.hash_chain_entry, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  store ptr %38, ptr %1, align 8, !tbaa !16
  br label %23, !llvm.loop !21

39:                                               ; preds = %23
  br label %40

40:                                               ; preds = %39
  %41 = load i64, ptr %2, align 8, !tbaa !15
  %42 = add i64 %41, 1
  store i64 %42, ptr %2, align 8, !tbaa !15
  br label %14, !llvm.loop !23

43:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @GC_dump_finalization_links(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 = { 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, !10, i64 320}
!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 = !{!6, !11, i64 336}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!18, !7, i64 0}
!18 = !{!"finalizable_object", !19, i64 0, !10, i64 16, !10, i64 24, !7, i64 32, !10, i64 40}
!19 = !{!"hash_chain_entry", !7, i64 0, !10, i64 8}
!20 = !{!18, !10, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !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 global %struct._GC_arrays, align 8
@.str.41 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @GC_printf(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GC_dump_finalization() local_unnamed_addr #0 {
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 320), align 8, !tbaa !5
  %.not15 = icmp eq ptr %1, null
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 336), align 8
  %3 = zext nneg i32 %2 to i64
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.41)
  tail call void @GC_dump_finalization_links(ptr noundef nonnull getelementptr inbounds (i8, ptr @GC_arrays, i64 296))
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.42)
  tail call void @GC_dump_finalization_links(ptr noundef nonnull getelementptr inbounds (i8, ptr @GC_arrays, i64 272))
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.43)
  br i1 %.not15, label %._crit_edge14, label %.lr.ph13.split

.lr.ph13.split:                                   ; preds = %0, %._crit_edge
  %.0711 = phi i64 [ %10, %._crit_edge ], [ 0, %0 ]
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 320), align 8, !tbaa !5
  %5 = getelementptr inbounds ptr, ptr %4, i64 %.0711
  %.08 = load ptr, ptr %5, align 8, !tbaa !14
  %.not9 = icmp eq ptr %.08, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph13.split, %.lr.ph
  %.010 = phi ptr [ %.0, %.lr.ph ], [ %.08, %.lr.ph13.split ]
  %6 = load i64, ptr %.010, align 8, !tbaa !15
  %7 = xor i64 %6, -1
  %8 = inttoptr i64 %7 to ptr
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.44, ptr noundef %8)
  %9 = getelementptr inbounds i8, ptr %.010, i64 8
  %.0 = load ptr, ptr %9, align 8, !tbaa !14
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph13.split
  %10 = add i64 %.0711, 1
  %.07.highbits = lshr i64 %10, %3
  %11 = icmp eq i64 %.07.highbits, 0
  br i1 %11, label %.lr.ph13.split, label %._crit_edge14, !llvm.loop !20

._crit_edge14:                                    ; preds = %._crit_edge, %0
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @GC_dump_finalization_links(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" }

!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, !10, i64 320}
!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 = !{!10, !10, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"finalizable_object", !17, i64 0, !10, i64 16, !10, i64 24, !7, i64 32, !10, i64 40}
!17 = !{!"hash_chain_entry", !7, i64 0, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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