; LLVM IR from brewlin/garbage-collect :: gc-golang/central (central)

; 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.mheap = type { %union.pthread_mutex_t, %struct.mtreap, %struct.mtreap, %struct.array_t, [2 x %struct.gcSweepBuf], %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.lineralloc, %struct.array_t, ptr, [1 x %struct.array_t], i64, i32, i32, i32, ptr, i64, i64, i64, [134 x %struct.mcentral] }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.mtreap = type { ptr }
%struct.gcSweepBuf = type { %union.pthread_mutex_t, ptr, i64, i64, i32 }
%struct.mfixalloc = type { i64, ptr, ptr, ptr, i64, i32, i64, i8 }
%struct.lineralloc = type { i64, i64, i64 }
%struct.array_t = type { ptr, i32, i64, i32 }
%struct.mcentral = type { %union.pthread_mutex_t, i8, %struct.mspanlist, %struct.mspanlist, i64 }
%struct.mspanlist = type { ptr, ptr }
%struct.mspan = type { ptr, ptr, ptr, i64, i64, i64, i8, i8, i8, i16, i32, i64, i8, i16, i8, i8, i16, i64, i64, i64, ptr, ptr, i64 }

@heap_ = external global %struct.mheap, align 8
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #1

declare void @spanlist_remove(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

declare zeroext i8 @span_sweep(ptr noundef, i8 noundef zeroext) #2

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

declare i32 @printf(ptr noundef, ...) #2

declare void @atomic_Store(ptr noundef, i32 noundef) #2

declare void @spanlist_insert(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @central_uncacheSpan(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.mspan, ptr %9, i32 0, i32 9
  %11 = load i16, ptr %10, align 4, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 poison, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %16

16:                                               ; preds = %14, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %17 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !15
  store i32 %17, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.mspan, ptr %18, i32 0, i32 10
  %20 = load i32, ptr %19, align 8, !tbaa !21
  %21 = load i32, ptr %6, align 4, !tbaa !14
  %22 = add i32 %21, 1
  %23 = icmp eq i32 %20, %22
  %24 = zext i1 %23 to i32
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr %7, align 1, !tbaa !22
  %26 = load i8, ptr %7, align 1, !tbaa !22
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %16
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mspan, ptr %29, i32 0, i32 10
  %31 = load i32, ptr %6, align 4, !tbaa !14
  %32 = sub i32 %31, 1
  call void @atomic_Store(ptr noundef %30, i32 noundef %32)
  br label %37

33:                                               ; preds = %16
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mspan, ptr %34, i32 0, i32 10
  %36 = load i32, ptr %6, align 4, !tbaa !14
  call void @atomic_Store(ptr noundef %35, i32 noundef %36)
  br label %37

37:                                               ; preds = %33, %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mspan, ptr %38, i32 0, i32 19
  %40 = load i64, ptr %39, align 8, !tbaa !23
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mspan, ptr %41, i32 0, i32 9
  %43 = load i16, ptr %42, align 4, !tbaa !9
  %44 = zext i16 %43 to i64
  %45 = sub i64 %40, %44
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %8, align 4, !tbaa !14
  %47 = load i32, ptr %8, align 4, !tbaa !14
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %49, label %66

49:                                               ; preds = %37
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mcentral, ptr %50, i32 0, i32 0
  %52 = call i32 @pthread_mutex_lock(ptr noundef %51) #4
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mcentral, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @spanlist_remove(ptr noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mcentral, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  call void @spanlist_insert(ptr noundef %57, ptr noundef %58)
  %59 = load i8, ptr %7, align 1, !tbaa !22
  %60 = icmp ne i8 %59, 0
  br i1 %60, label %62, label %61

61:                                               ; preds = %49
  br label %62

62:                                               ; preds = %61, %49
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mcentral, ptr %63, i32 0, i32 0
  %65 = call i32 @pthread_mutex_unlock(ptr noundef %64) #4
  br label %66

66:                                               ; preds = %62, %37
  %67 = load i8, ptr %7, align 1, !tbaa !22
  %68 = icmp ne i8 %67, 0
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = call zeroext i8 @span_sweep(ptr noundef %70, i8 noundef zeroext 0)
  br label %72

72:                                               ; preds = %69, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #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, !12, i64 52}
!10 = !{!"mspan", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 49, !7, i64 50, !12, i64 52, !13, i64 56, !11, i64 64, !7, i64 72, !12, i64 74, !7, i64 76, !7, i64 77, !12, i64 78, !11, i64 80, !11, i64 88, !11, i64 96, !6, i64 104, !6, i64 112, !11, i64 120}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !13, i64 720}
!16 = !{!"mheap", !7, i64 0, !17, i64 40, !17, i64 48, !18, i64 56, !7, i64 88, !19, i64 232, !19, i64 296, !19, i64 360, !19, i64 424, !19, i64 488, !19, i64 552, !20, i64 616, !18, i64 640, !6, i64 672, !7, i64 680, !11, i64 712, !13, i64 720, !13, i64 724, !13, i64 728, !6, i64 736, !11, i64 744, !11, i64 752, !11, i64 760, !7, i64 768}
!17 = !{!"mtreap", !6, i64 0}
!18 = !{!"", !6, i64 0, !13, i64 8, !11, i64 16, !13, i64 24}
!19 = !{!"mfixalloc", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !13, i64 40, !11, i64 48, !7, i64 56}
!20 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16}
!21 = !{!10, !13, i64 56}
!22 = !{!7, !7, i64 0}
!23 = !{!10, !11, i64 96}


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

%struct.mheap = type { %union.pthread_mutex_t, %struct.mtreap, %struct.mtreap, %struct.array_t, [2 x %struct.gcSweepBuf], %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.mfixalloc, %struct.lineralloc, %struct.array_t, ptr, [1 x %struct.array_t], i64, i32, i32, i32, ptr, i64, i64, i64, [134 x %struct.mcentral] }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.mtreap = type { ptr }
%struct.gcSweepBuf = type { %union.pthread_mutex_t, ptr, i64, i64, i32 }
%struct.mfixalloc = type { i64, ptr, ptr, ptr, i64, i32, i64, i8 }
%struct.lineralloc = type { i64, i64, i64 }
%struct.array_t = type { ptr, i32, i64, i32 }
%struct.mcentral = type { %union.pthread_mutex_t, i8, %struct.mspanlist, %struct.mspanlist, i64 }
%struct.mspanlist = type { ptr, ptr }

@heap_ = external local_unnamed_addr global %struct.mheap, align 8
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #0

declare void @spanlist_remove(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @span_sweep(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @atomic_Store(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @spanlist_insert(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @central_uncacheSpan(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = getelementptr inbounds i8, ptr %1, i64 52
  %4 = load i16, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i16 %4, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %8

8:                                                ; preds = %6, %2
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  %11 = load i32, ptr %10, align 8, !tbaa !19
  %12 = add i32 %9, 1
  %13 = icmp eq i32 %11, %12
  %14 = sext i1 %13 to i32
  %.sink = add i32 %9, %14
  tail call void @atomic_Store(ptr noundef nonnull %10, i32 noundef %.sink) #4
  %15 = getelementptr inbounds i8, ptr %1, i64 96
  %16 = load i64, ptr %15, align 8, !tbaa !20
  %17 = load i16, ptr %3, align 4, !tbaa !5
  %18 = zext i16 %17 to i64
  %19 = sub i64 %16, %18
  %20 = trunc i64 %19 to i32
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %8
  %23 = tail call i32 @pthread_mutex_lock(ptr noundef %0) #4
  %24 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @spanlist_remove(ptr noundef nonnull %24, ptr noundef nonnull %1) #4
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @spanlist_insert(ptr noundef nonnull %25, ptr noundef nonnull %1) #4
  %26 = tail call i32 @pthread_mutex_unlock(ptr noundef %0) #4
  br label %27

27:                                               ; preds = %22, %8
  br i1 %13, label %28, label %30

28:                                               ; preds = %27
  %29 = tail call zeroext i8 @span_sweep(ptr noundef nonnull %1, i8 noundef zeroext 0) #4
  br label %30

30:                                               ; preds = %28, %27
  ret void
}

attributes #0 = { nounwind "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 = { nofree nounwind "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 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 #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, !11, i64 52}
!6 = !{!"mspan", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !8, i64 48, !8, i64 49, !8, i64 50, !11, i64 52, !12, i64 56, !10, i64 64, !8, i64 72, !11, i64 74, !8, i64 76, !8, i64 77, !11, i64 78, !10, i64 80, !10, i64 88, !10, i64 96, !7, i64 104, !7, i64 112, !10, i64 120}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !12, i64 720}
!14 = !{!"mheap", !8, i64 0, !15, i64 40, !15, i64 48, !16, i64 56, !8, i64 88, !17, i64 232, !17, i64 296, !17, i64 360, !17, i64 424, !17, i64 488, !17, i64 552, !18, i64 616, !16, i64 640, !7, i64 672, !8, i64 680, !10, i64 712, !12, i64 720, !12, i64 724, !12, i64 728, !7, i64 736, !10, i64 744, !10, i64 752, !10, i64 760, !8, i64 768}
!15 = !{!"mtreap", !7, i64 0}
!16 = !{!"", !7, i64 0, !12, i64 8, !10, i64 16, !12, i64 24}
!17 = !{!"mfixalloc", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !12, i64 40, !10, i64 48, !8, i64 56}
!18 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16}
!19 = !{!6, !12, i64 56}
!20 = !{!6, !10, i64 96}


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