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

; 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_hblk_s = type { [4096 x i8] }

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_build_fl(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.prefetch.p0(ptr %14, i32 1, i32 3, i32 1)
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 128
  call void @llvm.prefetch.p0(ptr %16, i32 1, i32 3, i32 1)
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 256
  call void @llvm.prefetch.p0(ptr %18, i32 1, i32 3, i32 1)
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 378
  call void @llvm.prefetch.p0(ptr %20, i32 1, i32 3, i32 1)
  %21 = load i64, ptr %7, align 8, !tbaa !9
  switch i64 %21, label %44 [
    i64 2, label %22
    i64 4, label %33
  ]

22:                                               ; preds = %4
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = call ptr @GC_build_fl_clear2(ptr noundef %26, ptr noundef %27)
  store ptr %28, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %86

29:                                               ; preds = %22
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call ptr @GC_build_fl2(ptr noundef %30, ptr noundef %31)
  store ptr %32, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %86

33:                                               ; preds = %4
  %34 = load i32, ptr %8, align 4, !tbaa !11
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %40

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = call ptr @GC_build_fl_clear4(ptr noundef %37, ptr noundef %38)
  store ptr %39, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %86

40:                                               ; preds = %33
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = call ptr @GC_build_fl4(ptr noundef %41, ptr noundef %42)
  store ptr %43, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %86

44:                                               ; preds = %4
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %8, align 4, !tbaa !11
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %45
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %49, i8 0, i64 4096, i1 false)
  br label %50

50:                                               ; preds = %48, %45
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.GC_hblk_s, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [4096 x i8], ptr %52, i64 0, i64 0
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds i64, ptr %53, i64 %54
  store ptr %55, ptr %10, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.GC_hblk_s, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [4096 x i8], ptr %57, i64 0, i64 0
  store ptr %58, ptr %11, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 4096
  store ptr %60, ptr %12, align 8, !tbaa !5
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = sub i64 0, %61
  %64 = getelementptr inbounds i64, ptr %62, i64 %63
  store ptr %64, ptr %12, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %71, %50
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = ptrtoint ptr %66 to i64
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = ptrtoint ptr %68 to i64
  %70 = icmp ule i64 %67, %69
  br i1 %70, label %71, label %78

71:                                               ; preds = %65
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %72, ptr %73, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %74, ptr %11, align 8, !tbaa !5
  %75 = load i64, ptr %7, align 8, !tbaa !9
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds i64, ptr %76, i64 %75
  store ptr %77, ptr %10, align 8, !tbaa !5
  br label %65, !llvm.loop !13

78:                                               ; preds = %65
  %79 = load i64, ptr %7, align 8, !tbaa !9
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = sub i64 0, %79
  %82 = getelementptr inbounds i64, ptr %80, i64 %81
  store ptr %82, ptr %10, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %83, ptr %84, align 8, !tbaa !5
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %85, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %86

86:                                               ; preds = %78, %40, %36, %29, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %87 = load ptr, ptr %5, align 8
  ret ptr %87
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; 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) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_build_fl_clear2(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_build_fl2(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_build_fl_clear4(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_build_fl4(ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_build_fl(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  tail call void @llvm.prefetch.p0(ptr %0, i32 1, i32 3, i32 1)
  %5 = getelementptr inbounds i8, ptr %0, i64 128
  tail call void @llvm.prefetch.p0(ptr nonnull %5, i32 1, i32 3, i32 1)
  %6 = getelementptr inbounds i8, ptr %0, i64 256
  tail call void @llvm.prefetch.p0(ptr nonnull %6, i32 1, i32 3, i32 1)
  %7 = getelementptr inbounds i8, ptr %0, i64 378
  tail call void @llvm.prefetch.p0(ptr nonnull %7, i32 1, i32 3, i32 1)
  %.not38 = icmp eq i32 %2, 0
  switch i64 %1, label %18 [
    i64 2, label %8
    i64 4, label %13
  ]

8:                                                ; preds = %4
  br i1 %.not38, label %11, label %9

9:                                                ; preds = %8
  %10 = tail call ptr @GC_build_fl_clear2(ptr noundef %0, ptr noundef %3)
  br label %25

11:                                               ; preds = %8
  %12 = tail call ptr @GC_build_fl2(ptr noundef %0, ptr noundef %3)
  br label %25

13:                                               ; preds = %4
  br i1 %.not38, label %16, label %14

14:                                               ; preds = %13
  %15 = tail call ptr @GC_build_fl_clear4(ptr noundef %0, ptr noundef %3)
  br label %25

16:                                               ; preds = %13
  %17 = tail call ptr @GC_build_fl4(ptr noundef %0, ptr noundef %3)
  br label %25

18:                                               ; preds = %4
  br i1 %.not38, label %21, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(4096) %20, i8 0, i64 4088, i1 false)
  br label %21

21:                                               ; preds = %19, %18
  %22 = getelementptr inbounds i8, ptr %0, i64 4096
  %23 = sub i64 0, %1
  %24 = getelementptr inbounds i64, ptr %22, i64 %23
  %.03540 = getelementptr inbounds i64, ptr %0, i64 %1
  %.not3941 = icmp ugt ptr %.03540, %24
  br i1 %.not3941, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %21, %.lr.ph
  %.03543 = phi ptr [ %.035, %.lr.ph ], [ %.03540, %21 ]
  %.042 = phi ptr [ %.03543, %.lr.ph ], [ %0, %21 ]
  store ptr %.042, ptr %.03543, align 8, !tbaa !5
  %.035 = getelementptr inbounds i64, ptr %.03543, i64 %1
  %.not39 = icmp ugt ptr %.035, %24
  br i1 %.not39, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %21
  %.0.lcssa = phi ptr [ %0, %21 ], [ %.03543, %.lr.ph ]
  store ptr %3, ptr %0, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %._crit_edge, %16, %14, %11, %9
  %.036 = phi ptr [ %.0.lcssa, %._crit_edge ], [ %15, %14 ], [ %17, %16 ], [ %10, %9 ], [ %12, %11 ]
  ret ptr %.036
}

; 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 ptr @GC_build_fl_clear2(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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