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

; 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
define dso_local void @GC_set_fl_marks(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %75

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = ptrtoint ptr %11 to i64
  %13 = and i64 %12, -4096
  %14 = inttoptr i64 %13 to ptr
  store ptr %14, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %15, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @GC_find_header(ptr noundef %16)
  store ptr %17, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %73, %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = ptrtoint ptr %19 to i64
  %22 = ptrtoint ptr %20 to i64
  %23 = sub i64 %21, %22
  %24 = lshr i64 %23, 4
  store i64 %24, ptr %6, align 8, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.hblkhdr, ptr %25, i32 0, i32 10
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = lshr i64 %27, 6
  %29 = getelementptr inbounds [5 x i64], ptr %26, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = and i64 %31, 63
  %33 = lshr i64 %30, %32
  %34 = and i64 %33, 1
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %52, label %36

36:                                               ; preds = %18
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = and i64 %37, 63
  %39 = shl i64 1, %38
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.hblkhdr, ptr %40, i32 0, i32 10
  %42 = getelementptr inbounds [5 x i64], ptr %41, i64 0, i64 0
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = lshr i64 %43, 6
  %45 = getelementptr inbounds i64, ptr %42, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = or i64 %46, %39
  store i64 %47, ptr %45, align 8, !tbaa !9
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.hblkhdr, ptr %48, i32 0, i32 9
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = add i64 %50, 1
  store i64 %51, ptr %49, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %36, %18
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %2, align 8, !tbaa !5
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  store i32 2, ptr %7, align 4
  br label %71

58:                                               ; preds = %52
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = ptrtoint ptr %59 to i64
  %61 = and i64 %60, -4096
  %62 = inttoptr i64 %61 to ptr
  store ptr %62, ptr %3, align 8, !tbaa !5
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = icmp ne ptr %63, %64
  br i1 %65, label %66, label %70

66:                                               ; preds = %58
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %67, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = call ptr @GC_find_header(ptr noundef %68)
  store ptr %69, ptr %5, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %66, %58
  store i32 0, ptr %7, align 4
  br label %71

71:                                               ; preds = %70, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %72 = load i32, ptr %7, align 4
  switch i32 %72, label %76 [
    i32 0, label %73
    i32 2, label %74
  ]

73:                                               ; preds = %71
  br label %18

74:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %75

75:                                               ; preds = %74, %1
  ret void

76:                                               ; preds = %71
  unreachable
}

declare ptr @GC_find_header(ptr noundef) #2

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 = { "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 = !{!"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
define dso_local void @GC_set_fl_marks(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread, label %2

2:                                                ; preds = %1
  %3 = ptrtoint ptr %0 to i64
  %4 = and i64 %3, -4096
  %5 = inttoptr i64 %4 to ptr
  br label %.sink.split

.sink.split:                                      ; preds = %26, %2
  %.sink = phi ptr [ %5, %2 ], [ %29, %26 ]
  %.025.ph = phi i64 [ %4, %2 ], [ %28, %26 ]
  %.020.ph = phi ptr [ %0, %2 ], [ %24, %26 ]
  %6 = tail call ptr @GC_find_header(ptr noundef %.sink) #2
  %7 = getelementptr inbounds i8, ptr %6, i64 64
  %8 = getelementptr inbounds i8, ptr %6, i64 56
  br label %9

9:                                                ; preds = %.sink.split, %26
  %.025 = phi i64 [ %28, %26 ], [ %.025.ph, %.sink.split ]
  %.020 = phi ptr [ %24, %26 ], [ %.020.ph, %.sink.split ]
  %10 = ptrtoint ptr %.020 to i64
  %11 = sub i64 %10, %.025
  %12 = lshr i64 %10, 4
  %13 = lshr i64 %11, 10
  %14 = getelementptr inbounds [5 x i64], ptr %7, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = and i64 %12, 63
  %17 = shl nuw i64 1, %16
  %18 = and i64 %17, %15
  %.not30 = icmp eq i64 %18, 0
  br i1 %.not30, label %19, label %23

19:                                               ; preds = %9
  %20 = or i64 %15, %17
  store i64 %20, ptr %14, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = add i64 %21, 1
  store i64 %22, ptr %8, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %19, %9
  %24 = load ptr, ptr %.020, align 8, !tbaa !13
  %25 = icmp eq ptr %24, null
  br i1 %25, label %.thread, label %26

26:                                               ; preds = %23
  %27 = ptrtoint ptr %24 to i64
  %28 = and i64 %27, -4096
  %29 = inttoptr i64 %28 to ptr
  %.not31 = icmp eq ptr %.sink, %29
  br i1 %.not31, label %9, label %.sink.split

.thread:                                          ; preds = %23, %1
  ret void
}

declare ptr @GC_find_header(ptr noundef) local_unnamed_addr #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 = { "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 = !{!"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}
!13 = !{!11, !11, i64 0}


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