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

@GC_gc_no = external dso_local global i64, align 8
@GC_disable_automatic_collection = external hidden global i32, align 4
@GC_should_start_incremental_collection = external hidden global i32, align 4
@GC_should_collect.last_min_bytes_allocd = external hidden global i64, align 8
@GC_should_collect.last_gc_no = external hidden global i64, align 8
@GC_arrays = external global %struct._GC_arrays, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @GC_should_collect() #0 {
  %1 = alloca i32, align 4
  %2 = load i64, ptr @GC_should_collect.last_gc_no, align 8, !tbaa !5
  %3 = load i64, ptr @GC_gc_no, align 8, !tbaa !5
  %4 = icmp ne i64 %2, %3
  br i1 %4, label %5, label %8

5:                                                ; preds = %0
  %6 = call i64 @min_bytes_allocd()
  store i64 %6, ptr @GC_should_collect.last_min_bytes_allocd, align 8, !tbaa !5
  %7 = load i64, ptr @GC_gc_no, align 8, !tbaa !5
  store i64 %7, ptr @GC_should_collect.last_gc_no, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %5, %0
  %9 = load i32, ptr @GC_should_start_incremental_collection, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  store i32 0, ptr @GC_should_start_incremental_collection, align 4, !tbaa !9
  store i32 1, ptr %1, align 4
  br label %26

12:                                               ; preds = %8
  %13 = load i32, ptr @GC_disable_automatic_collection, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  store i32 0, ptr %1, align 4
  br label %26

16:                                               ; preds = %12
  %17 = load i64, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 27), align 8, !tbaa !11
  %18 = load i64, ptr @GC_gc_no, align 8, !tbaa !5
  %19 = icmp eq i64 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 1, ptr %1, align 4
  br label %26

21:                                               ; preds = %16
  %22 = call i64 @GC_adj_bytes_allocd()
  %23 = load i64, ptr @GC_should_collect.last_min_bytes_allocd, align 8, !tbaa !5
  %24 = icmp uge i64 %22, %23
  %25 = zext i1 %24 to i32
  store i32 %25, ptr %1, align 4
  br label %26

26:                                               ; preds = %21, %20, %15, %11
  %27 = load i32, ptr %1, align 4
  ret i32 %27
}

; Function Attrs: nounwind uwtable
declare hidden i64 @min_bytes_allocd() #0

; Function Attrs: nounwind uwtable
declare hidden i64 @GC_adj_bytes_allocd() #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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 208}
!12 = !{!"_GC_arrays", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !13, i64 216, !13, i64 224, !6, i64 232, !10, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !14, i64 272, !14, i64 296, !15, i64 320, !10, i64 336, !13, i64 344, !6, i64 352, !6, i64 360, !10, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !13, 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, !13, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"dl_hashtbl_s", !13, i64 0, !6, i64 8, !10, i64 16}
!15 = !{!"fnlz_roots_s", !13, i64 0, !13, i64 8}


; 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_gc_no = external dso_local local_unnamed_addr global i64, align 8
@GC_disable_automatic_collection = external hidden local_unnamed_addr global i32, align 4
@GC_should_start_incremental_collection = external hidden local_unnamed_addr global i32, align 4
@GC_should_collect.last_min_bytes_allocd = external hidden local_unnamed_addr global i64, align 8
@GC_should_collect.last_gc_no = external hidden local_unnamed_addr global i64, align 8
@GC_arrays = external local_unnamed_addr global %struct._GC_arrays, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @GC_should_collect() local_unnamed_addr #0 {
  %1 = load i64, ptr @GC_should_collect.last_gc_no, align 8, !tbaa !5
  %2 = load i64, ptr @GC_gc_no, align 8, !tbaa !5
  %.not = icmp eq i64 %1, %2
  br i1 %.not, label %6, label %3

3:                                                ; preds = %0
  %4 = tail call i64 @min_bytes_allocd()
  store i64 %4, ptr @GC_should_collect.last_min_bytes_allocd, align 8, !tbaa !5
  %5 = load i64, ptr @GC_gc_no, align 8, !tbaa !5
  store i64 %5, ptr @GC_should_collect.last_gc_no, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %3, %0
  %7 = phi i64 [ %5, %3 ], [ %1, %0 ]
  %8 = load i32, ptr @GC_should_start_incremental_collection, align 4, !tbaa !9
  %.not1 = icmp eq i32 %8, 0
  br i1 %.not1, label %10, label %9

9:                                                ; preds = %6
  store i32 0, ptr @GC_should_start_incremental_collection, align 4, !tbaa !9
  br label %20

10:                                               ; preds = %6
  %11 = load i32, ptr @GC_disable_automatic_collection, align 4, !tbaa !9
  %.not2 = icmp eq i32 %11, 0
  br i1 %.not2, label %12, label %20

12:                                               ; preds = %10
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 208), align 8, !tbaa !11
  %14 = icmp eq i64 %13, %7
  br i1 %14, label %20, label %15

15:                                               ; preds = %12
  %16 = tail call i64 @GC_adj_bytes_allocd()
  %17 = load i64, ptr @GC_should_collect.last_min_bytes_allocd, align 8, !tbaa !5
  %18 = icmp uge i64 %16, %17
  %19 = zext i1 %18 to i32
  br label %20

20:                                               ; preds = %12, %10, %15, %9
  %.0 = phi i32 [ 1, %9 ], [ %19, %15 ], [ 0, %10 ], [ 1, %12 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @min_bytes_allocd() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @GC_adj_bytes_allocd() 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 208}
!12 = !{!"_GC_arrays", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !13, i64 216, !13, i64 224, !6, i64 232, !10, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !14, i64 272, !14, i64 296, !15, i64 320, !10, i64 336, !13, i64 344, !6, i64 352, !6, i64 360, !10, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !13, 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, !13, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"dl_hashtbl_s", !13, i64 0, !6, i64 8, !10, i64 16}
!15 = !{!"fnlz_roots_s", !13, i64 0, !13, i64 8}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass