; 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
@.str.5 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [19 x i8], align 1
@GC_root_size = external hidden global i64, align 8
@.str.50 = external hidden unnamed_addr constant [41 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
declare dso_local void @GC_err_printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_static_roots() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %26, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = load i32, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 42), align 8, !tbaa !9
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %7, label %29

7:                                                ; preds = %3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %9
  %11 = getelementptr inbounds %struct.roots, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %14
  %16 = getelementptr inbounds %struct.roots, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 59), i64 0, i64 %19
  %21 = getelementptr inbounds %struct.roots, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, ptr @.str.48, ptr @.str.5
  call void (ptr, ...) @GC_printf(ptr noundef @.str.47, ptr noundef %12, ptr noundef %17, ptr noundef %25)
  br label %26

26:                                               ; preds = %7
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !19

29:                                               ; preds = %3
  %30 = load i64, ptr @GC_root_size, align 8, !tbaa !21
  call void (ptr, ...) @GC_printf(ptr noundef @.str.49, i64 noundef %30)
  %31 = call i64 @GC_compute_root_size()
  store i64 %31, ptr %2, align 8, !tbaa !21
  %32 = load i64, ptr @GC_root_size, align 8, !tbaa !21
  %33 = icmp ne i64 %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = load i64, ptr %2, align 8, !tbaa !21
  call void (ptr, ...) @GC_err_printf(ptr noundef @.str.50, i64 noundef %35)
  br label %36

36:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @GC_compute_root_size() #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, !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"}
!21 = !{!11, !11, i64 0}


; 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
@.str.5 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [19 x i8], align 1
@GC_root_size = external hidden local_unnamed_addr global i64, align 8
@.str.50 = external hidden unnamed_addr constant [41 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_static_roots() local_unnamed_addr #0 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 368), align 8, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %3 = getelementptr inbounds [2048 x %struct.roots], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 91600), i64 0, i64 %indvars.iv
  %4 = load ptr, ptr %3, align 8, !tbaa !14
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %3, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !17
  %.not7 = icmp eq i32 %8, 0
  %9 = select i1 %.not7, ptr @.str.5, ptr @.str.48
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.47, ptr noundef %4, ptr noundef %6, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 368), align 8, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %0
  %13 = load i64, ptr @GC_root_size, align 8, !tbaa !20
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.49, i64 noundef %13)
  %14 = tail call i64 @GC_compute_root_size()
  %15 = load i64, ptr @GC_root_size, align 8, !tbaa !20
  %.not = icmp eq i64 %14, %15
  br i1 %.not, label %17, label %16

16:                                               ; preds = %._crit_edge
  tail call void (ptr, ...) @GC_err_printf(ptr noundef nonnull @.str.50, i64 noundef %14)
  br label %17

17:                                               ; preds = %16, %._crit_edge
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @GC_compute_root_size() 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, !11, i64 368}
!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 = !{!15, !10, i64 0}
!15 = !{!"roots", !10, i64 0, !10, i64 8, !10, i64 16, !11, i64 24}
!16 = !{!15, !10, i64 8}
!17 = !{!15, !11, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!7, !7, i64 0}


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