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

; 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_old_stack_bl = external hidden global ptr, align 8
@GC_incomplete_stack_bl = external hidden 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

declare ptr @GC_find_header(ptr noundef) #1

; 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_add_to_black_list_stack(i64 noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = lshr i64 %4, 12
  %6 = and i64 %5, 262143
  store i64 %6, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = inttoptr i64 %7 to ptr
  %9 = call ptr @GC_find_header(ptr noundef %8)
  %10 = icmp eq ptr %9, null
  br i1 %10, label %22, label %11

11:                                               ; preds = %1
  %12 = load ptr, ptr @GC_old_stack_bl, align 8, !tbaa !9
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = lshr i64 %13, 6
  %15 = getelementptr inbounds i64, ptr %12, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = and i64 %17, 63
  %19 = lshr i64 %16, %18
  %20 = and i64 %19, 1
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %32

22:                                               ; preds = %11, %1
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = and i64 %23, 63
  %25 = shl i64 1, %24
  %26 = load ptr, ptr @GC_incomplete_stack_bl, align 8, !tbaa !9
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = lshr i64 %27, 6
  %29 = getelementptr inbounds i64, ptr %26, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = or i64 %30, %25
  store i64 %31, ptr %29, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %22, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"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}


; 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_old_stack_bl = external hidden local_unnamed_addr global ptr, align 8
@GC_incomplete_stack_bl = external hidden local_unnamed_addr global ptr, align 8

declare ptr @GC_find_header(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GC_add_to_black_list_stack(i64 noundef %0) local_unnamed_addr #1 {
  %2 = lshr i64 %0, 12
  %3 = and i64 %2, 262143
  %4 = inttoptr i64 %0 to ptr
  %5 = tail call ptr @GC_find_header(ptr noundef %4) #2
  %6 = icmp eq ptr %5, null
  br i1 %6, label %._crit_edge, label %7

._crit_edge:                                      ; preds = %1
  %.pre = and i64 %2, 63
  %.pre6 = shl nuw i64 1, %.pre
  %.pre8 = lshr i64 %3, 6
  br label %15

7:                                                ; preds = %1
  %8 = load ptr, ptr @GC_old_stack_bl, align 8, !tbaa !5
  %9 = lshr i64 %3, 6
  %10 = getelementptr inbounds i64, ptr %8, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = and i64 %2, 63
  %13 = shl nuw i64 1, %12
  %14 = and i64 %11, %13
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %20, label %15

15:                                               ; preds = %._crit_edge, %7
  %.pre-phi9 = phi i64 [ %.pre8, %._crit_edge ], [ %9, %7 ]
  %.pre-phi7 = phi i64 [ %.pre6, %._crit_edge ], [ %13, %7 ]
  %16 = load ptr, ptr @GC_incomplete_stack_bl, align 8, !tbaa !5
  %17 = getelementptr inbounds i64, ptr %16, i64 %.pre-phi9
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = or i64 %18, %.pre-phi7
  store i64 %19, ptr %17, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %15, %7
  ret void
}

attributes #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 = { 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}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass