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

; 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 global %struct._GC_arrays, align 8
@GC_page_size = external global i64, align 8
@GC_current_warn_proc = external global ptr, align 8
@.str = external hidden unnamed_addr constant [80 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 ptr @GC_scratch_alloc(i64 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %7 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 16), align 8, !tbaa !9
  store ptr %7, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp ult i64 %8, -16
  %10 = zext i1 %9 to i32
  %11 = sext i32 %10 to i64
  %12 = call i64 @llvm.expect.i64(i64 %11, i64 1)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %1
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = add i64 %15, 15
  br label %18

17:                                               ; preds = %1
  br label %18

18:                                               ; preds = %17, %14
  %19 = phi i64 [ %16, %14 ], [ -1, %17 ]
  %20 = and i64 %19, -16
  store i64 %20, ptr %3, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %125, %18
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 18), align 8, !tbaa !16
  %24 = ptrtoint ptr %23 to i64
  %25 = load ptr, ptr %4, align 8, !tbaa !15
  %26 = ptrtoint ptr %25 to i64
  %27 = sub i64 %24, %26
  %28 = icmp ule i64 %22, %27
  br i1 %28, label %29, label %34

29:                                               ; preds = %21
  %30 = load ptr, ptr %4, align 8, !tbaa !15
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  store ptr %32, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 16), align 8, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !15
  store ptr %33, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %130

34:                                               ; preds = %21
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = icmp uge i64 %35, 65536
  br i1 %36, label %37, label %66

37:                                               ; preds = %34
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %40 = sub i64 %39, 1
  %41 = sub i64 -1, %40
  %42 = icmp ult i64 %38, %41
  %43 = zext i1 %42 to i32
  %44 = sext i32 %43 to i64
  %45 = call i64 @llvm.expect.i64(i64 %44, i64 1)
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %52

47:                                               ; preds = %37
  %48 = load i64, ptr %3, align 8, !tbaa !5
  %49 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %50 = sub i64 %49, 1
  %51 = add i64 %48, %50
  br label %53

52:                                               ; preds = %37
  br label %53

53:                                               ; preds = %52, %47
  %54 = phi i64 [ %51, %47 ], [ -1, %52 ]
  %55 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %56 = sub i64 %55, 1
  %57 = xor i64 %56, -1
  %58 = and i64 %54, %57
  store i64 %58, ptr %5, align 8, !tbaa !5
  %59 = load i64, ptr %5, align 8, !tbaa !5
  %60 = call ptr @GC_os_get_mem(i64 noundef %59)
  store ptr %60, ptr %4, align 8, !tbaa !15
  %61 = load ptr, ptr %4, align 8, !tbaa !15
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %53
  br label %64

64:                                               ; preds = %63, %53
  %65 = load ptr, ptr %4, align 8, !tbaa !15
  store ptr %65, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %130

66:                                               ; preds = %34
  %67 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %68 = sub i64 %67, 1
  %69 = sub i64 -1, %68
  %70 = icmp ult i64 65536, %69
  %71 = zext i1 %70 to i32
  %72 = sext i32 %71 to i64
  %73 = call i64 @llvm.expect.i64(i64 %72, i64 1)
  %74 = icmp ne i64 %73, 0
  br i1 %74, label %75, label %79

75:                                               ; preds = %66
  %76 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %77 = sub i64 %76, 1
  %78 = add i64 65536, %77
  br label %80

79:                                               ; preds = %66
  br label %80

80:                                               ; preds = %79, %75
  %81 = phi i64 [ %78, %75 ], [ -1, %79 ]
  %82 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %83 = sub i64 %82, 1
  %84 = xor i64 %83, -1
  %85 = and i64 %81, %84
  store i64 %85, ptr %5, align 8, !tbaa !5
  %86 = load i64, ptr %5, align 8, !tbaa !5
  %87 = call ptr @GC_os_get_mem(i64 noundef %86)
  store ptr %87, ptr %4, align 8, !tbaa !15
  %88 = load ptr, ptr %4, align 8, !tbaa !15
  %89 = icmp eq ptr null, %88
  %90 = zext i1 %89 to i32
  %91 = sext i32 %90 to i64
  %92 = call i64 @llvm.expect.i64(i64 %91, i64 0)
  %93 = icmp ne i64 %92, 0
  br i1 %93, label %94, label %125

94:                                               ; preds = %80
  %95 = load ptr, ptr @GC_current_warn_proc, align 8, !tbaa !15
  %96 = load i64, ptr %3, align 8, !tbaa !5
  call void %95(ptr noundef @.str, i64 noundef %96)
  %97 = load i64, ptr %3, align 8, !tbaa !5
  %98 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %99 = sub i64 %98, 1
  %100 = sub i64 -1, %99
  %101 = icmp ult i64 %97, %100
  %102 = zext i1 %101 to i32
  %103 = sext i32 %102 to i64
  %104 = call i64 @llvm.expect.i64(i64 %103, i64 1)
  %105 = icmp ne i64 %104, 0
  br i1 %105, label %106, label %111

106:                                              ; preds = %94
  %107 = load i64, ptr %3, align 8, !tbaa !5
  %108 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %109 = sub i64 %108, 1
  %110 = add i64 %107, %109
  br label %112

111:                                              ; preds = %94
  br label %112

112:                                              ; preds = %111, %106
  %113 = phi i64 [ %110, %106 ], [ -1, %111 ]
  %114 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %115 = sub i64 %114, 1
  %116 = xor i64 %115, -1
  %117 = and i64 %113, %116
  store i64 %117, ptr %5, align 8, !tbaa !5
  %118 = load i64, ptr %5, align 8, !tbaa !5
  %119 = call ptr @GC_os_get_mem(i64 noundef %118)
  store ptr %119, ptr %4, align 8, !tbaa !15
  %120 = load ptr, ptr %4, align 8, !tbaa !15
  %121 = icmp ne ptr %120, null
  br i1 %121, label %122, label %123

122:                                              ; preds = %112
  br label %123

123:                                              ; preds = %122, %112
  %124 = load ptr, ptr %4, align 8, !tbaa !15
  store ptr %124, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %130

125:                                              ; preds = %80
  %126 = load ptr, ptr %4, align 8, !tbaa !15
  store ptr %126, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 16), align 8, !tbaa !9
  %127 = load ptr, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 16), align 8, !tbaa !9
  %128 = load i64, ptr %5, align 8, !tbaa !5
  %129 = getelementptr inbounds i8, ptr %127, i64 %128
  store ptr %129, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 18), align 8, !tbaa !16
  br label %21

130:                                              ; preds = %123, %64, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %131 = load ptr, ptr %2, align 8
  ret ptr %131
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

declare ptr @GC_os_get_mem(i64 noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { "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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 128}
!10 = !{!"_GC_arrays", !6, i64 0, !6, i64 8, !6, i64 16, !11, 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, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !12, i64 176, !12, i64 180, !12, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !11, i64 216, !11, i64 224, !6, i64 232, !12, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !13, i64 272, !13, i64 296, !14, i64 320, !12, i64 336, !11, i64 344, !6, i64 352, !6, i64 360, !12, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !11, 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, !11, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"dl_hashtbl_s", !11, i64 0, !6, i64 8, !12, i64 16}
!14 = !{!"fnlz_roots_s", !11, i64 0, !11, i64 8}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 144}


; 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 local_unnamed_addr global %struct._GC_arrays, align 8
@GC_page_size = external local_unnamed_addr global i64, align 8
@GC_current_warn_proc = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_scratch_alloc(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 128), align 8, !tbaa !5
  %3 = tail call i64 @llvm.uadd.sat.i64(i64 %0, i64 15)
  %4 = and i64 %3, -16
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 144), align 8, !tbaa !14
  %6 = ptrtoint ptr %5 to i64
  %7 = ptrtoint ptr %2 to i64
  %8 = sub i64 %6, %7
  %.not28 = icmp ugt i64 %4, %8
  br i1 %.not28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %9 = icmp ugt i64 %3, 65535
  br i1 %9, label %19, label %.lr.ph.split

._crit_edge:                                      ; preds = %38, %1
  %.0.lcssa = phi ptr [ %2, %1 ], [ %17, %38 ]
  %10 = getelementptr inbounds i8, ptr %.0.lcssa, i64 %4
  store ptr %10, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 128), align 8, !tbaa !5
  br label %40

.lr.ph.split:                                     ; preds = %.lr.ph, %38
  %11 = load i64, ptr @GC_page_size, align 8
  %notsub = add i64 %11, -1
  %12 = icmp ult i64 %notsub, -65537
  %13 = add i64 %11, 65535
  %14 = select i1 %12, i64 %13, i64 -1, !prof !15
  %15 = sub i64 0, %11
  %16 = and i64 %14, %15
  %17 = tail call ptr @GC_os_get_mem(i64 noundef %16) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %28, label %38, !prof !16

19:                                               ; preds = %.lr.ph
  %20 = load i64, ptr @GC_page_size, align 8
  %21 = sub i64 0, %20
  %22 = icmp ult i64 %4, %21
  %23 = add i64 %4, -1
  %24 = add i64 %23, %20
  %25 = select i1 %22, i64 %24, i64 -1, !prof !15
  %26 = and i64 %25, %21
  %27 = tail call ptr @GC_os_get_mem(i64 noundef %26) #3
  br label %40

28:                                               ; preds = %.lr.ph.split
  %29 = load ptr, ptr @GC_current_warn_proc, align 8, !tbaa !17
  tail call void %29(ptr noundef nonnull @.str, i64 noundef %4) #3
  %30 = load i64, ptr @GC_page_size, align 8
  %31 = sub i64 0, %30
  %32 = icmp ult i64 %4, %31
  %33 = add nsw i64 %4, -1
  %34 = add i64 %33, %30
  %35 = select i1 %32, i64 %34, i64 -1, !prof !15
  %36 = and i64 %35, %31
  %37 = tail call ptr @GC_os_get_mem(i64 noundef %36) #3
  br label %40

38:                                               ; preds = %.lr.ph.split
  store ptr %17, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 128), align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %17, i64 %16
  store ptr %39, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 144), align 8, !tbaa !14
  %.not = icmp ugt i64 %4, %16
  br i1 %.not, label %.lr.ph.split, label %._crit_edge

40:                                               ; preds = %28, %19, %._crit_edge
  %.023 = phi ptr [ %.0.lcssa, %._crit_edge ], [ %27, %19 ], [ %37, %28 ]
  ret ptr %.023
}

declare ptr @GC_os_get_mem(i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.uadd.sat.i64(i64, i64) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 128}
!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, !10, i64 144}
!15 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!16 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!17 = !{!10, !10, i64 0}


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