; 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 }
%struct.bi = type { [1024 x ptr], ptr, ptr, i64, ptr }
%struct.hblkhdr = type { ptr, ptr, ptr, i8, i8, i16, i64, i64, ptr, i64, [5 x i64] }

@GC_all_interior_pointers = external dso_local global i32, align 4
@GC_arrays = external dso_local global %struct._GC_arrays, 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
declare hidden ptr @GC_find_header(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_mark_and_push(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.prefetch.p0(ptr %16, i32 0, i32 0, i32 1)
  br label %17

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  br label %19

19:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = lshr i64 %21, 22
  store i64 %22, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %23 = load i64, ptr %13, align 8, !tbaa !9
  %24 = and i64 %23, 2047
  %25 = getelementptr inbounds [2048 x ptr], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 61), i64 0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %14, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %39, %19
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.bi, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = load i64, ptr %13, align 8, !tbaa !9
  %32 = icmp ne i64 %30, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %27
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 28), align 8, !tbaa !13
  %36 = icmp ne ptr %34, %35
  br label %37

37:                                               ; preds = %33, %27
  %38 = phi i1 [ false, %27 ], [ %36, %33 ]
  br i1 %38, label %39, label %43

39:                                               ; preds = %37
  %40 = load ptr, ptr %14, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.bi, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  store ptr %42, ptr %14, align 8, !tbaa !5
  br label %27, !llvm.loop !19

43:                                               ; preds = %37
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %44, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %45

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.bi, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = ptrtoint ptr %49 to i64
  %51 = lshr i64 %50, 12
  %52 = and i64 %51, 1023
  %53 = getelementptr inbounds [1024 x ptr], ptr %48, i64 0, i64 %52
  store ptr %53, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %54

54:                                               ; preds = %46
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  store ptr %57, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %58

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = ptrtoint ptr %60 to i64
  %62 = icmp ule i64 %61, 4095
  %63 = zext i1 %62 to i32
  %64 = sext i32 %63 to i64
  %65 = call i64 @llvm.expect.i64(i64 %64, i64 0)
  %66 = icmp ne i64 %65, 0
  br i1 %66, label %67, label %75

67:                                               ; preds = %59
  %68 = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !21
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %86

70:                                               ; preds = %67
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = call ptr @GC_base(ptr noundef %71)
  %73 = call ptr @GC_find_header(ptr noundef %72)
  store ptr %73, ptr %10, align 8, !tbaa !5
  %74 = icmp eq ptr null, %73
  br i1 %74, label %86, label %75

75:                                               ; preds = %70, %59
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.hblkhdr, ptr %76, i32 0, i32 4
  %78 = load i8, ptr %77, align 1, !tbaa !22
  %79 = zext i8 %78 to i32
  %80 = and i32 %79, 4
  %81 = icmp ne i32 %80, 0
  %82 = zext i1 %81 to i32
  %83 = sext i32 %82 to i64
  %84 = call i64 @llvm.expect.i64(i64 %83, i64 0)
  %85 = icmp ne i64 %84, 0
  br i1 %85, label %86, label %97

86:                                               ; preds = %75, %70, %67
  %87 = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !21
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %92

89:                                               ; preds = %86
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = ptrtoint ptr %90 to i64
  call void @GC_add_to_black_list_stack(i64 noundef %91)
  br label %95

92:                                               ; preds = %86
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = ptrtoint ptr %93 to i64
  call void @GC_add_to_black_list_normal(i64 noundef %94)
  br label %95

95:                                               ; preds = %92, %89
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %96, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %104

97:                                               ; preds = %75
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  %103 = call ptr @GC_push_contents_hdr(ptr noundef %98, ptr noundef %99, ptr noundef %100, ptr noundef %101, ptr noundef %102, i32 noundef 1)
  store ptr %103, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %104

104:                                              ; preds = %97, %95
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %105 = load ptr, ptr %5, align 8
  ret ptr %105
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @llvm.prefetch.p0(ptr nocapture readonly, i32 immarg, i32 immarg, i32 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden void @GC_add_to_black_list_stack(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @GC_add_to_black_list_normal(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @GC_push_contents_hdr(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) }
attributes #4 = { inlinehint 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 #5 = { 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 8208}
!12 = !{!"bi", !7, i64 0, !6, i64 8192, !6, i64 8200, !10, i64 8208, !6, i64 8216}
!13 = !{!14, !6, i64 216}
!14 = !{!"_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, !15, i64 176, !15, i64 180, !15, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !6, i64 216, !6, i64 224, !10, i64 232, !15, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !16, i64 272, !16, i64 296, !17, i64 320, !15, i64 336, !6, i64 344, !10, i64 352, !10, i64 360, !15, 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}
!15 = !{!"int", !7, i64 0}
!16 = !{!"dl_hashtbl_s", !6, i64 0, !10, i64 8, !15, i64 16}
!17 = !{!"fnlz_roots_s", !6, i64 0, !6, i64 8}
!18 = !{!12, !6, i64 8216}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!15, !15, i64 0}
!22 = !{!23, !7, i64 25}
!23 = !{!"hblkhdr", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !24, i64 26, !10, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !7, i64 64}
!24 = !{!"short", !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._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_all_interior_pointers = external dso_local local_unnamed_addr global i32, align 4
@GC_arrays = external dso_local local_unnamed_addr global %struct._GC_arrays, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_mark_and_push(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  tail call void @llvm.prefetch.p0(ptr %0, i32 0, i32 0, i32 1)
  %5 = ptrtoint ptr %0 to i64
  %6 = lshr i64 %5, 22
  %7 = and i64 %6, 2047
  %8 = getelementptr inbounds [2048 x ptr], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 165328), i64 0, i64 %7
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 216), align 8
  br label %10

10:                                               ; preds = %10, %4
  %.0.in = phi ptr [ %8, %4 ], [ %16, %10 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.0, i64 8208
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i64 %12, %6
  %14 = icmp ne ptr %.0, %9
  %15 = select i1 %13, i1 %14, i1 false
  %16 = getelementptr inbounds i8, ptr %.0, i64 8216
  br i1 %15, label %10, label %17, !llvm.loop !12

17:                                               ; preds = %10
  %18 = lshr i64 %5, 12
  %19 = and i64 %18, 1023
  %20 = getelementptr inbounds [1024 x ptr], ptr %.0, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp ult ptr %21, inttoptr (i64 4096 to ptr)
  br i1 %22, label %23, label %29, !prof !14

23:                                               ; preds = %17
  %24 = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !15
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %.thread, label %25

25:                                               ; preds = %23
  %26 = tail call ptr @GC_base(ptr noundef %0)
  %27 = tail call ptr @GC_find_header(ptr noundef %26)
  %28 = icmp eq ptr %27, null
  br i1 %28, label %33, label %29

29:                                               ; preds = %25, %17
  %.023 = phi ptr [ %27, %25 ], [ %21, %17 ]
  %30 = getelementptr inbounds i8, ptr %.023, i64 25
  %31 = load i8, ptr %30, align 1, !tbaa !17
  %32 = and i8 %31, 4
  %.not25 = icmp eq i8 %32, 0
  br i1 %.not25, label %35, label %33, !prof !20

33:                                               ; preds = %29, %25
  %.pr = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !15
  %.not26 = icmp eq i32 %.pr, 0
  br i1 %.not26, label %.thread, label %34

34:                                               ; preds = %33
  tail call void @GC_add_to_black_list_stack(i64 noundef %5)
  br label %37

.thread:                                          ; preds = %23, %33
  tail call void @GC_add_to_black_list_normal(i64 noundef %5)
  br label %37

35:                                               ; preds = %29
  %36 = tail call ptr @GC_push_contents_hdr(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef nonnull %.023, i32 noundef 1)
  br label %37

37:                                               ; preds = %34, %.thread, %35
  %.022 = phi ptr [ %36, %35 ], [ %1, %.thread ], [ %1, %34 ]
  ret ptr %.022
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @llvm.prefetch.p0(ptr nocapture readonly, i32 immarg, i32 immarg, i32 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @GC_add_to_black_list_stack(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @GC_add_to_black_list_normal(i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @GC_push_contents_hdr(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) }
attributes #2 = { inlinehint 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8208}
!10 = !{!"bi", !7, i64 0, !6, i64 8192, !6, i64 8200, !11, i64 8208, !6, i64 8216}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !7, i64 25}
!18 = !{!"hblkhdr", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !19, i64 26, !11, i64 32, !11, i64 40, !6, i64 48, !11, i64 56, !7, i64 64}
!19 = !{!"short", !7, i64 0}
!20 = !{!"branch_weights", !"expected", i32 2000, i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass