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

@GC_least_plausible_heap_addr = external dso_local global ptr, align 8
@GC_greatest_plausible_heap_addr = external dso_local global ptr, 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
define dso_local void @GC_push_all_eager(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr @GC_greatest_plausible_heap_addr, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %12 = load ptr, ptr @GC_least_plausible_heap_addr, align 8, !tbaa !5
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 1, ptr %9, align 4
  br label %56

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = add i64 %18, 7
  %20 = and i64 %19, -8
  %21 = inttoptr i64 %20 to ptr
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = ptrtoint ptr %22 to i64
  %24 = and i64 %23, -8
  %25 = inttoptr i64 %24 to ptr
  %26 = getelementptr inbounds i64, ptr %25, i64 -1
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %52, %16
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = icmp ule i64 %29, %31
  br i1 %32, label %33, label %55

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %34, align 8, !tbaa !9
  store i64 %35, ptr %10, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %33
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = ptrtoint ptr %38 to i64
  %40 = icmp ugt i64 %37, %39
  br i1 %40, label %41, label %49

41:                                               ; preds = %36
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = ptrtoint ptr %43 to i64
  %45 = icmp ult i64 %42, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %41
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = inttoptr i64 %47 to ptr
  call void @GC_mark_and_push_stack(ptr noundef %48)
  br label %49

49:                                               ; preds = %46, %41, %36
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 8
  store ptr %54, ptr %5, align 8, !tbaa !5
  br label %27, !llvm.loop !11

55:                                               ; preds = %27
  store i32 0, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %57 = load i32, ptr %9, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @GC_mark_and_push_stack(ptr noundef) #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 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

@GC_least_plausible_heap_addr = external dso_local local_unnamed_addr global ptr, align 8
@GC_greatest_plausible_heap_addr = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @GC_push_all_eager(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @GC_greatest_plausible_heap_addr, align 8, !tbaa !5
  %4 = load ptr, ptr @GC_least_plausible_heap_addr, align 8, !tbaa !5
  %5 = icmp eq ptr %1, null
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = ptrtoint ptr %0 to i64
  %8 = add i64 %7, 7
  %9 = and i64 %8, -8
  %10 = ptrtoint ptr %1 to i64
  %11 = and i64 %10, -8
  %12 = add i64 %11, -8
  %.not14 = icmp ult i64 %12, %9
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %13 = inttoptr i64 %9 to ptr
  %14 = ptrtoint ptr %4 to i64
  %15 = ptrtoint ptr %3 to i64
  br label %16

16:                                               ; preds = %.lr.ph, %22
  %.015 = phi ptr [ %13, %.lr.ph ], [ %23, %22 ]
  %17 = load i64, ptr %.015, align 8, !tbaa !9
  %18 = icmp ugt i64 %17, %14
  %19 = icmp ult i64 %17, %15
  %or.cond = select i1 %18, i1 %19, i1 false
  br i1 %or.cond, label %20, label %22

20:                                               ; preds = %16
  %21 = inttoptr i64 %17 to ptr
  tail call void @GC_mark_and_push_stack(ptr noundef nonnull %21)
  br label %22

22:                                               ; preds = %20, %16
  %23 = getelementptr inbounds i8, ptr %.015, i64 8
  %24 = ptrtoint ptr %23 to i64
  %.not = icmp ult i64 %12, %24
  br i1 %.not, label %.loopexit, label %16, !llvm.loop !11

.loopexit:                                        ; preds = %22, %6, %2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @GC_mark_and_push_stack(ptr noundef) 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass