; 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
@GC_gc_no = external dso_local global i64, align 8
@GC_stackbottom = external dso_local global ptr, align 8
@GC_stack_last_cleared = external hidden global i64, align 8
@GC_high_water = external hidden global ptr, align 8
@GC_min_sp = external hidden global ptr, align 8
@GC_bytes_allocd_at_reset = external hidden global i64, 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_clear_stack(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = call ptr @GC_approx_sp()
  store ptr %7, ptr %4, align 8, !tbaa !5
  %8 = load i64, ptr @GC_gc_no, align 8, !tbaa !9
  %9 = load i64, ptr @GC_stack_last_cleared, align 8, !tbaa !9
  %10 = icmp ne i64 %8, %9
  br i1 %10, label %11, label %24

11:                                               ; preds = %1
  %12 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  %14 = zext i1 %13 to i32
  %15 = sext i32 %14 to i64
  %16 = call i64 @llvm.expect.i64(i64 %15, i64 0)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %11
  %19 = load ptr, ptr @GC_stackbottom, align 8, !tbaa !5
  store ptr %19, ptr @GC_high_water, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %11
  %21 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  store ptr %21, ptr @GC_min_sp, align 8, !tbaa !5
  %22 = load i64, ptr @GC_gc_no, align 8, !tbaa !9
  store i64 %22, ptr @GC_stack_last_cleared, align 8, !tbaa !9
  %23 = load i64, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 9), align 8, !tbaa !11
  store i64 %23, ptr @GC_bytes_allocd_at_reset, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %20, %1
  %25 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 4400
  %27 = ptrtoint ptr %26 to i64
  %28 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = icmp ugt i64 %27, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %24
  %32 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 4400
  store ptr %33, ptr @GC_high_water, align 8, !tbaa !5
  br label %35

34:                                               ; preds = %24
  store ptr inttoptr (i64 -1 to ptr), ptr @GC_high_water, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %34, %31
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = ptrtoint ptr %36 to i64
  %38 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %39 = ptrtoint ptr %38 to i64
  %40 = icmp ult i64 %37, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %35
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %42, ptr @GC_high_water, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %41, %35
  %44 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 -4000
  store ptr %45, ptr @GC_high_water, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %46 = load ptr, ptr @GC_min_sp, align 8, !tbaa !5
  store ptr %46, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 -400
  store ptr %48, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = ptrtoint ptr %49 to i64
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = ptrtoint ptr %51 to i64
  %53 = icmp ugt i64 %50, %52
  br i1 %53, label %54, label %63

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = ptrtoint ptr %55 to i64
  %57 = and i64 %56, -16
  %58 = inttoptr i64 %57 to ptr
  store ptr %58, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %59, ptr @GC_min_sp, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call ptr @GC_clear_stack_inner(ptr noundef %60, ptr noundef %61)
  store ptr %62, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %64

63:                                               ; preds = %43
  store i32 0, ptr %6, align 4
  br label %64

64:                                               ; preds = %63, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %65 = load i32, ptr %6, align 4
  switch i32 %65, label %86 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  %67 = load i64, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 9), align 8, !tbaa !11
  %68 = load i64, ptr @GC_bytes_allocd_at_reset, align 8, !tbaa !9
  %69 = sub i64 %67, %68
  %70 = icmp ugt i64 %69, 100000
  br i1 %70, label %71, label %84

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %72, ptr @GC_min_sp, align 8, !tbaa !5
  %73 = load ptr, ptr @GC_min_sp, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 -25000
  store ptr %74, ptr @GC_min_sp, align 8, !tbaa !5
  %75 = load ptr, ptr @GC_min_sp, align 8, !tbaa !5
  %76 = ptrtoint ptr %75 to i64
  %77 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  %78 = ptrtoint ptr %77 to i64
  %79 = icmp ult i64 %76, %78
  br i1 %79, label %80, label %82

80:                                               ; preds = %71
  %81 = load ptr, ptr @GC_high_water, align 8, !tbaa !5
  store ptr %81, ptr @GC_min_sp, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %80, %71
  %83 = load i64, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 9), align 8, !tbaa !11
  store i64 %83, ptr @GC_bytes_allocd_at_reset, align 8, !tbaa !9
  br label %84

84:                                               ; preds = %82, %66
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %85, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %86

86:                                               ; preds = %84, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %87 = load ptr, ptr %2, align 8
  ret ptr %87
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @GC_clear_stack_inner(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_approx_sp() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 72}
!12 = !{!"_GC_arrays", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !13, i64 176, !13, i64 180, !13, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !6, i64 216, !6, i64 224, !10, i64 232, !13, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !14, i64 272, !14, i64 296, !15, i64 320, !13, i64 336, !6, i64 344, !10, i64 352, !10, i64 360, !13, i64 368, !10, i64 376, !10, i64 384, !10, i64 392, !6, 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, !6, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!13 = !{!"int", !7, i64 0}
!14 = !{!"dl_hashtbl_s", !6, i64 0, !10, i64 8, !13, i64 16}
!15 = !{!"fnlz_roots_s", !6, i64 0, !6, 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_arrays = external dso_local local_unnamed_addr global %struct._GC_arrays, align 8
@GC_gc_no = external dso_local local_unnamed_addr global i64, align 8
@GC_stackbottom = external dso_local local_unnamed_addr global ptr, align 8
@GC_stack_last_cleared = external hidden local_unnamed_addr global i64, align 8
@GC_high_water = external hidden local_unnamed_addr global ptr, align 8
@GC_min_sp = external hidden local_unnamed_addr global ptr, align 8
@GC_bytes_allocd_at_reset = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_clear_stack(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @GC_approx_sp()
  %3 = load i64, ptr @GC_gc_no, align 8, !tbaa !5
  %4 = load i64, ptr @GC_stack_last_cleared, align 8, !tbaa !5
  %.not = icmp eq i64 %3, %4
  %.pre = load ptr, ptr @GC_high_water, align 8, !tbaa !9
  br i1 %.not, label %._crit_edge, label %5

._crit_edge:                                      ; preds = %1
  %.pre17 = load ptr, ptr @GC_min_sp, align 8, !tbaa !9
  br label %12

5:                                                ; preds = %1
  %6 = icmp eq ptr %.pre, null
  br i1 %6, label %7, label %9, !prof !11

7:                                                ; preds = %5
  %8 = load ptr, ptr @GC_stackbottom, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %7, %5
  %10 = phi ptr [ %8, %7 ], [ %.pre, %5 ]
  store ptr %10, ptr @GC_min_sp, align 8, !tbaa !9
  store i64 %3, ptr @GC_stack_last_cleared, align 8, !tbaa !5
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 72), align 8, !tbaa !12
  store i64 %11, ptr @GC_bytes_allocd_at_reset, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %._crit_edge, %9
  %13 = phi ptr [ %.pre17, %._crit_edge ], [ %10, %9 ]
  %14 = phi ptr [ %.pre, %._crit_edge ], [ %10, %9 ]
  %15 = getelementptr inbounds i8, ptr %14, i64 4400
  %16 = icmp ult ptr %2, %15
  %spec.store.select15 = select i1 %16, ptr %2, ptr %15
  %17 = getelementptr inbounds i8, ptr %spec.store.select15, i64 -4000
  store ptr %17, ptr @GC_high_water, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %13, i64 -400
  %.not14 = icmp ugt ptr %2, %18
  br i1 %.not14, label %.thread, label %23

.thread:                                          ; preds = %12
  %19 = ptrtoint ptr %18 to i64
  %20 = and i64 %19, -16
  %21 = inttoptr i64 %20 to ptr
  store ptr %2, ptr @GC_min_sp, align 8, !tbaa !9
  %22 = tail call ptr @GC_clear_stack_inner(ptr noundef %0, ptr noundef %21)
  br label %31

23:                                               ; preds = %12
  %24 = load i64, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 72), align 8, !tbaa !12
  %25 = load i64, ptr @GC_bytes_allocd_at_reset, align 8, !tbaa !5
  %26 = sub i64 %24, %25
  %27 = icmp ugt i64 %26, 100000
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = getelementptr inbounds i8, ptr %2, i64 -25000
  %30 = icmp ult ptr %29, %17
  %spec.store.select = select i1 %30, ptr %17, ptr %29
  store ptr %spec.store.select, ptr @GC_min_sp, align 8
  store i64 %24, ptr @GC_bytes_allocd_at_reset, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %.thread, %23, %28
  %.1 = phi ptr [ %0, %28 ], [ %0, %23 ], [ %22, %.thread ]
  ret ptr %.1
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_approx_sp() 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 = !{!"any pointer", !7, i64 0}
!11 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!12 = !{!13, !6, i64 72}
!13 = !{!"_GC_arrays", !6, i64 0, !6, i64 8, !6, i64 16, !10, 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, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !14, i64 176, !14, i64 180, !14, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !10, i64 224, !6, i64 232, !14, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !15, i64 272, !15, i64 296, !16, i64 320, !14, i64 336, !10, i64 344, !6, i64 352, !6, i64 360, !14, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !10, 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, !10, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!14 = !{!"int", !7, i64 0}
!15 = !{!"dl_hashtbl_s", !10, i64 0, !6, i64 8, !14, i64 16}
!16 = !{!"fnlz_roots_s", !10, i64 0, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass