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

; 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
declare hidden ptr @GC_find_header(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @GC_set_mark_bit(ptr noundef nonnull %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = ptrtoint ptr %6 to i64
  %8 = and i64 %7, -4096
  %9 = inttoptr i64 %8 to ptr
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call ptr @GC_find_header(ptr noundef %10)
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = ptrtoint ptr %12 to i64
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  %16 = sub i64 %13, %15
  %17 = lshr i64 %16, 4
  store i64 %17, ptr %5, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.hblkhdr, ptr %18, i32 0, i32 10
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = lshr i64 %20, 6
  %22 = getelementptr inbounds [5 x i64], ptr %19, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = and i64 %24, 63
  %26 = lshr i64 %23, %25
  %27 = and i64 %26, 1
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %45, label %29

29:                                               ; preds = %1
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = and i64 %30, 63
  %32 = shl i64 1, %31
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.hblkhdr, ptr %33, i32 0, i32 10
  %35 = getelementptr inbounds [5 x i64], ptr %34, i64 0, i64 0
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = lshr i64 %36, 6
  %38 = getelementptr inbounds i64, ptr %35, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = or i64 %39, %32
  store i64 %40, ptr %38, align 8, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hblkhdr, ptr %41, i32 0, i32 9
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = add i64 %43, 1
  store i64 %44, ptr %42, align 8, !tbaa !11
  br label %45

45:                                               ; preds = %29, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 = !{!12, !10, i64 56}
!12 = !{!"hblkhdr", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !13, i64 26, !10, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !7, i64 64}
!13 = !{!"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"

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

; Function Attrs: nounwind uwtable
define dso_local void @GC_set_mark_bit(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = ptrtoint ptr %0 to i64
  %3 = and i64 %2, -4096
  %4 = inttoptr i64 %3 to ptr
  %5 = tail call ptr @GC_find_header(ptr noundef %4)
  %6 = lshr i64 %2, 4
  %7 = getelementptr inbounds i8, ptr %5, i64 64
  %8 = lshr i64 %2, 10
  %9 = and i64 %8, 3
  %10 = getelementptr inbounds [5 x i64], ptr %7, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = and i64 %6, 63
  %13 = shl nuw i64 1, %12
  %14 = and i64 %11, %13
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %15, label %20

15:                                               ; preds = %1
  %16 = or i64 %11, %13
  store i64 %16, ptr %10, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %5, i64 56
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = add i64 %18, 1
  store i64 %19, ptr %17, align 8, !tbaa !9
  br label %20

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

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 56}
!10 = !{!"hblkhdr", !11, i64 0, !11, i64 8, !11, i64 16, !7, i64 24, !7, i64 25, !12, i64 26, !6, i64 32, !6, i64 40, !11, i64 48, !6, i64 56, !7, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"short", !7, i64 0}


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