; 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.timespec = type { i64, i64 }

@GC_incremental = external dso_local global i32, align 4
@GC_time_limit = external dso_local global i64, align 8
@GC_dont_gc = external global i32, align 4
@GC_on_abort = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@GC_rate = external hidden global i32, align 4
@max_prior_attempts = external hidden global i32, align 4
@GC_deficit = external hidden global i32, align 4
@GC_n_attempts = external hidden global i32, align 4
@GC_start_time = external hidden global %struct.timespec, 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
declare dso_local i32 @GC_never_stop_func() #1

; Function Attrs: nounwind uwtable
define dso_local void @GC_collect_a_little_inner(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @GC_incremental, align 4, !tbaa !5
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %75

7:                                                ; preds = %1
  %8 = call i32 @GC_collection_in_progress()
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %75

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %11 = load i32, ptr @GC_rate, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = mul nsw i32 %11, %12
  store i32 %13, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr @GC_deficit, align 4, !tbaa !5
  store i32 %14, ptr %3, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %24, %10
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %27

19:                                               ; preds = %15
  %20 = call i32 @GC_mark_some(ptr noundef null)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  br label %27

23:                                               ; preds = %19
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %15, !llvm.loop !9

27:                                               ; preds = %22, %15
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %63

31:                                               ; preds = %27
  %32 = load i32, ptr @GC_dont_gc, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %63, label %34

34:                                               ; preds = %31
  %35 = load i64, ptr @GC_time_limit, align 8, !tbaa !11
  %36 = icmp ne i64 %35, 999999
  br i1 %36, label %37, label %50

37:                                               ; preds = %34
  %38 = load i32, ptr @GC_n_attempts, align 4, !tbaa !5
  %39 = load i32, ptr @max_prior_attempts, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %50

41:                                               ; preds = %37
  br label %42

42:                                               ; preds = %41
  %43 = call i32 @clock_gettime(i32 noundef 1, ptr noundef @GC_start_time) #5
  %44 = icmp eq i32 %43, -1
  br i1 %44, label %45, label %47

45:                                               ; preds = %42
  %46 = load ptr, ptr @GC_on_abort, align 8, !tbaa !13
  call void %46(ptr noundef @.str.2)
  call void @abort() #6
  unreachable

47:                                               ; preds = %42
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49, %37, %34
  %51 = load i32, ptr @GC_n_attempts, align 4, !tbaa !5
  %52 = load i32, ptr @max_prior_attempts, align 4, !tbaa !5
  %53 = icmp slt i32 %51, %52
  %54 = zext i1 %53 to i64
  %55 = select i1 %53, ptr @GC_timeout_stop_func, ptr @GC_never_stop_func
  %56 = call i32 @GC_stopped_mark(ptr noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  call void @GC_finish_collection()
  br label %62

59:                                               ; preds = %50
  %60 = load i32, ptr @GC_n_attempts, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @GC_n_attempts, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %59, %58
  br label %63

63:                                               ; preds = %62, %31, %27
  %64 = load i32, ptr @GC_deficit, align 4, !tbaa !5
  %65 = icmp sgt i32 %64, 0
  br i1 %65, label %66, label %74

66:                                               ; preds = %63
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = load i32, ptr @GC_deficit, align 4, !tbaa !5
  %69 = sub nsw i32 %68, %67
  store i32 %69, ptr @GC_deficit, align 4, !tbaa !5
  %70 = load i32, ptr @GC_deficit, align 4, !tbaa !5
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %66
  store i32 0, ptr @GC_deficit, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %72, %66
  br label %74

74:                                               ; preds = %73, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %80

75:                                               ; preds = %7, %1
  %76 = load i32, ptr @GC_dont_gc, align 4, !tbaa !5
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %79, label %78

78:                                               ; preds = %75
  call void @GC_maybe_gc()
  br label %79

79:                                               ; preds = %78, %75
  br label %80

80:                                               ; preds = %79, %74
  ret void
}

declare i32 @GC_collection_in_progress() #2

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) #3

; Function Attrs: noreturn nounwind
declare void @abort() #4

; Function Attrs: nounwind uwtable
declare hidden i32 @GC_stopped_mark(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @GC_finish_collection() #1

declare i32 @GC_mark_some(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @GC_timeout_stop_func() #1

; Function Attrs: nounwind uwtable
declare hidden void @GC_maybe_gc() #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 = { "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 "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 #4 = { noreturn nounwind "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 #5 = { nounwind }
attributes #6 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, 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.timespec = type { i64, i64 }

@GC_incremental = external dso_local local_unnamed_addr global i32, align 4
@GC_time_limit = external dso_local local_unnamed_addr global i64, align 8
@GC_dont_gc = external local_unnamed_addr global i32, align 4
@GC_on_abort = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@GC_rate = external hidden local_unnamed_addr global i32, align 4
@max_prior_attempts = external hidden local_unnamed_addr global i32, align 4
@GC_deficit = external hidden local_unnamed_addr global i32, align 4
@GC_n_attempts = external hidden local_unnamed_addr global i32, align 4
@GC_start_time = external hidden global %struct.timespec, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @GC_never_stop_func() #0

; Function Attrs: nounwind uwtable
define dso_local void @GC_collect_a_little_inner(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @GC_incremental, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %38, label %3

3:                                                ; preds = %1
  %4 = tail call i32 @GC_collection_in_progress() #5
  %.not9 = icmp eq i32 %4, 0
  br i1 %.not9, label %38, label %5

5:                                                ; preds = %3
  %6 = load i32, ptr @GC_rate, align 4, !tbaa !5
  %7 = mul nsw i32 %6, %0
  %8 = load i32, ptr @GC_deficit, align 4, !tbaa !5
  %9 = icmp slt i32 %8, %7
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %11
  %.014 = phi i32 [ %12, %11 ], [ %8, %5 ]
  %10 = tail call i32 @GC_mark_some(ptr noundef null) #5
  %.not11 = icmp eq i32 %10, 0
  br i1 %.not11, label %11, label %._crit_edge

11:                                               ; preds = %.lr.ph
  %12 = add i32 %.014, 1
  %exitcond.not = icmp eq i32 %12, %7
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.0.lcssa = phi i32 [ %8, %5 ], [ %.014, %.lr.ph ]
  %13 = icmp sge i32 %.0.lcssa, %7
  %14 = load i32, ptr @GC_dont_gc, align 4
  %15 = icmp ne i32 %14, 0
  %or.cond = select i1 %13, i1 true, i1 %15
  br i1 %or.cond, label %._crit_edge.thread, label %16

16:                                               ; preds = %._crit_edge
  %17 = load i64, ptr @GC_time_limit, align 8, !tbaa !11
  %.not12 = icmp ne i64 %17, 999999
  %.pre18 = load i32, ptr @GC_n_attempts, align 4, !tbaa !5
  %.pre20 = load i32, ptr @max_prior_attempts, align 4, !tbaa !5
  %18 = icmp slt i32 %.pre18, %.pre20
  %or.cond24 = select i1 %.not12, i1 %18, i1 false
  br i1 %or.cond24, label %19, label %24

19:                                               ; preds = %16
  %20 = tail call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull @GC_start_time) #5
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %._crit_edge17

._crit_edge17:                                    ; preds = %19
  %.pre = load i32, ptr @GC_n_attempts, align 4, !tbaa !5
  %.pre19 = load i32, ptr @max_prior_attempts, align 4, !tbaa !5
  br label %24

22:                                               ; preds = %19
  %23 = load ptr, ptr @GC_on_abort, align 8, !tbaa !13
  tail call void %23(ptr noundef nonnull @.str.2) #5
  tail call void @abort() #6
  unreachable

24:                                               ; preds = %._crit_edge17, %16
  %25 = phi i32 [ %.pre19, %._crit_edge17 ], [ %.pre20, %16 ]
  %26 = phi i32 [ %.pre, %._crit_edge17 ], [ %.pre18, %16 ]
  %27 = icmp slt i32 %26, %25
  %28 = select i1 %27, ptr @GC_timeout_stop_func, ptr @GC_never_stop_func
  %29 = tail call i32 @GC_stopped_mark(ptr noundef nonnull %28)
  %.not13 = icmp eq i32 %29, 0
  br i1 %.not13, label %31, label %30

30:                                               ; preds = %24
  tail call void @GC_finish_collection()
  br label %._crit_edge.thread

31:                                               ; preds = %24
  %32 = load i32, ptr @GC_n_attempts, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @GC_n_attempts, align 4, !tbaa !5
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %11, %30, %31, %._crit_edge
  %34 = load i32, ptr @GC_deficit, align 4, !tbaa !5
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %36, label %41

36:                                               ; preds = %._crit_edge.thread
  %37 = sub nsw i32 %34, %7
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %37, i32 0)
  store i32 %spec.store.select, ptr @GC_deficit, align 4
  br label %41

38:                                               ; preds = %3, %1
  %39 = load i32, ptr @GC_dont_gc, align 4, !tbaa !5
  %.not10 = icmp eq i32 %39, 0
  br i1 %.not10, label %40, label %41

40:                                               ; preds = %38
  tail call void @GC_maybe_gc()
  br label %41

41:                                               ; preds = %._crit_edge.thread, %36, %38, %40
  ret void
}

declare i32 @GC_collection_in_progress() local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @GC_stopped_mark(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @GC_finish_collection() local_unnamed_addr #0

declare i32 @GC_mark_some(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @GC_timeout_stop_func() #0

; Function Attrs: nounwind uwtable
declare hidden void @GC_maybe_gc() local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 "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 = { noreturn nounwind "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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