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

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

@GC_arrays = external global %struct._GC_arrays, align 8
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [45 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
define dso_local void @GC_print_heap_sects() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %6 = load i64, ptr @GC_arrays, align 8, !tbaa !5
  call void (ptr, ...) @GC_printf(ptr noundef @.str.5, i64 noundef %6)
  store i32 0, ptr %1, align 4, !tbaa !14
  br label %7

7:                                                ; preds = %54, %0
  %8 = load i32, ptr %1, align 4, !tbaa !14
  %9 = zext i32 %8 to i64
  %10 = load i64, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 33), align 8, !tbaa !15
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %12, label %57

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %13 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 58), align 8, !tbaa !16
  %14 = load i32, ptr %1, align 4, !tbaa !14
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds %struct.HeapSect, ptr %13, i64 %15
  %17 = getelementptr inbounds %struct.HeapSect, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  store ptr %18, ptr %2, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %19 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 58), align 8, !tbaa !16
  %20 = load i32, ptr %1, align 4, !tbaa !14
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.HeapSect, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.HeapSect, ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !20
  store i64 %24, ptr %3, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  %25 = load ptr, ptr %2, align 8, !tbaa !19
  store ptr %25, ptr %4, align 8, !tbaa !19
  br label %26

26:                                               ; preds = %42, %12
  %27 = load ptr, ptr %4, align 8, !tbaa !19
  %28 = ptrtoint ptr %27 to i64
  %29 = load ptr, ptr %2, align 8, !tbaa !19
  %30 = load i64, ptr %3, align 8, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = ptrtoint ptr %31 to i64
  %33 = icmp ult i64 %28, %32
  br i1 %33, label %34, label %45

34:                                               ; preds = %26
  %35 = load ptr, ptr %4, align 8, !tbaa !19
  %36 = call ptr @GC_is_black_listed(ptr noundef %35, i64 noundef 4096)
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load i32, ptr %5, align 4, !tbaa !14
  %40 = add i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !14
  br label %41

41:                                               ; preds = %38, %34
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %4, align 8, !tbaa !19
  %44 = getelementptr inbounds %struct.GC_hblk_s, ptr %43, i32 1
  store ptr %44, ptr %4, align 8, !tbaa !19
  br label %26, !llvm.loop !22

45:                                               ; preds = %26
  %46 = load i32, ptr %1, align 4, !tbaa !14
  %47 = load ptr, ptr %2, align 8, !tbaa !19
  %48 = load ptr, ptr %2, align 8, !tbaa !19
  %49 = load i64, ptr %3, align 8, !tbaa !21
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = load i32, ptr %5, align 4, !tbaa !14
  %52 = load i64, ptr %3, align 8, !tbaa !21
  %53 = lshr i64 %52, 12
  call void (ptr, ...) @GC_printf(ptr noundef @.str.6, i32 noundef %46, ptr noundef %47, ptr noundef %50, i32 noundef %51, i64 noundef %53)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %54

54:                                               ; preds = %45
  %55 = load i32, ptr %1, align 4, !tbaa !14
  %56 = add i32 %55, 1
  store i32 %56, ptr %1, align 4, !tbaa !14
  br label %7, !llvm.loop !24

57:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

declare void @GC_printf(ptr noundef, ...) #2

declare ptr @GC_is_black_listed(ptr noundef, i64 noundef) #2

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 = { "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 #3 = { 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, !7, i64 0}
!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 = !{!11, !11, i64 0}
!15 = !{!6, !7, i64 256}
!16 = !{!6, !10, i64 91592}
!17 = !{!18, !10, i64 0}
!18 = !{!"HeapSect", !10, i64 0, !7, i64 8}
!19 = !{!10, !10, i64 0}
!20 = !{!18, !7, i64 8}
!21 = !{!7, !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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

@GC_arrays = external local_unnamed_addr global %struct._GC_arrays, align 8
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_heap_sects() local_unnamed_addr #0 {
  %1 = load i64, ptr @GC_arrays, align 8, !tbaa !5
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.5, i64 noundef %1) #2
  %2 = load i64, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 256), align 8, !tbaa !14
  %.not26 = icmp eq i64 %2, 0
  br i1 %.not26, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %0, %._crit_edge
  %3 = phi i64 [ %17, %._crit_edge ], [ 0, %0 ]
  %.01722 = phi i32 [ %16, %._crit_edge ], [ 0, %0 ]
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 91592), align 8, !tbaa !15
  %5 = getelementptr inbounds %struct.HeapSect, ptr %4, i64 %3
  %6 = load ptr, ptr %5, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !18
  %9 = getelementptr inbounds i8, ptr %6, i64 %8
  %10 = icmp sgt i64 %8, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %.020 = phi i32 [ %spec.select, %.lr.ph ], [ 0, %.lr.ph24 ]
  %.01619 = phi ptr [ %13, %.lr.ph ], [ %6, %.lr.ph24 ]
  %11 = tail call ptr @GC_is_black_listed(ptr noundef %.01619, i64 noundef 4096) #2
  %.not = icmp ne ptr %11, null
  %12 = zext i1 %.not to i32
  %spec.select = add i32 %.020, %12
  %13 = getelementptr inbounds i8, ptr %.01619, i64 4096
  %14 = icmp ult ptr %13, %9
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph24
  %.0.lcssa = phi i32 [ 0, %.lr.ph24 ], [ %spec.select, %.lr.ph ]
  %15 = lshr i64 %8, 12
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.6, i32 noundef %.01722, ptr noundef %6, ptr noundef %9, i32 noundef %.0.lcssa, i64 noundef %15) #2
  %16 = add i32 %.01722, 1
  %17 = zext i32 %16 to i64
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 256), align 8, !tbaa !14
  %19 = icmp ugt i64 %18, %17
  br i1 %19, label %.lr.ph24, label %._crit_edge25, !llvm.loop !21

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

declare void @GC_printf(ptr noundef, ...) local_unnamed_addr #1

declare ptr @GC_is_black_listed(ptr noundef, i64 noundef) local_unnamed_addr #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 = { "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, !7, i64 0}
!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, !7, i64 256}
!15 = !{!6, !10, i64 91592}
!16 = !{!17, !10, i64 0}
!17 = !{!"HeapSect", !10, i64 0, !7, i64 8}
!18 = !{!17, !7, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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