; 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.1 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 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

; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @central_freeSpan(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) #3 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i8 %2, ptr %8, align 1, !tbaa !9
  store i8 %3, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %14 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !10
  store i32 %14, ptr %10, align 4, !tbaa !18
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mspan, ptr %15, i32 0, i32 10
  %17 = load i32, ptr %16, align 8, !tbaa !19
  %18 = load i32, ptr %10, align 4, !tbaa !18
  %19 = add i32 %18, 1
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %28, label %21

21:                                               ; preds = %4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mspan, ptr %22, i32 0, i32 10
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = load i32, ptr %10, align 4, !tbaa !18
  %26 = add i32 %25, 3
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %21, %4
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 poison, ptr %11, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %30

30:                                               ; preds = %28, %21
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mspan, ptr %31, i32 0, i32 7
  store i8 1, ptr %32, align 1, !tbaa !22
  %33 = load i8, ptr %8, align 1, !tbaa !9
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %35, label %46

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mspan, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !23
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %42

40:                                               ; preds = %35
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 poison, ptr %12, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %42

42:                                               ; preds = %40, %35
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mspan, ptr %43, i32 0, i32 10
  %45 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !10
  call void @atomic_Store(ptr noundef %44, i32 noundef %45)
  store i8 0, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %80

46:                                               ; preds = %30
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mcentral, ptr %47, i32 0, i32 0
  %49 = call i32 @pthread_mutex_lock(ptr noundef %48) #4
  %50 = load i8, ptr %9, align 1, !tbaa !9
  %51 = icmp ne i8 %50, 0
  br i1 %51, label %52, label %59

52:                                               ; preds = %46
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mcentral, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  call void @spanlist_remove(ptr noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mcentral, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  call void @spanlist_insert(ptr noundef %57, ptr noundef %58)
  br label %59

59:                                               ; preds = %52, %46
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mspan, ptr %60, i32 0, i32 10
  %62 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !10
  call void @atomic_Store(ptr noundef %61, i32 noundef %62)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mspan, ptr %63, i32 0, i32 9
  %65 = load i16, ptr %64, align 4, !tbaa !24
  %66 = zext i16 %65 to i32
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %72

68:                                               ; preds = %59
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mcentral, ptr %69, i32 0, i32 0
  %71 = call i32 @pthread_mutex_unlock(ptr noundef %70) #4
  store i8 0, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %80

72:                                               ; preds = %59
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mcentral, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  call void @spanlist_remove(ptr noundef %74, ptr noundef %75)
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.mcentral, ptr %76, i32 0, i32 0
  %78 = call i32 @pthread_mutex_unlock(ptr noundef %77) #4
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  call void @heap_freeSpan(ptr noundef %79, i8 noundef zeroext 0)
  store i8 1, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %80

80:                                               ; preds = %72, %68, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %81 = load i8, ptr %5, align 1
  ret i8 %81
}

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

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

declare void @heap_freeSpan(ptr noundef, i8 noundef zeroext) #2

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


; 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.1 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @central_freeSpan(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #3 {
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 56
  %7 = load i32, ptr %6, align 8, !tbaa !16
  %8 = add i32 %5, 1
  %9 = icmp eq i32 %7, %8
  %10 = add i32 %5, 3
  %11 = icmp eq i32 %7, %10
  %or.cond = or i1 %9, %11
  br i1 %or.cond, label %12, label %14

12:                                               ; preds = %4
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %14

14:                                               ; preds = %4, %12
  %15 = getelementptr inbounds i8, ptr %1, i64 49
  store i8 1, ptr %15, align 1, !tbaa !19
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %24, label %16

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %22

22:                                               ; preds = %20, %16
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !5
  tail call void @atomic_Store(ptr noundef nonnull %6, i32 noundef %23) #4
  br label %38

24:                                               ; preds = %14
  %25 = tail call i32 @pthread_mutex_lock(ptr noundef %0) #4
  %.not22 = icmp eq i8 %3, 0
  br i1 %.not22, label %29, label %26

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @spanlist_remove(ptr noundef nonnull %27, ptr noundef nonnull %1) #4
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @spanlist_insert(ptr noundef nonnull %28, ptr noundef nonnull %1) #4
  br label %29

29:                                               ; preds = %26, %24
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !5
  tail call void @atomic_Store(ptr noundef nonnull %6, i32 noundef %30) #4
  %31 = getelementptr inbounds i8, ptr %1, i64 52
  %32 = load i16, ptr %31, align 4, !tbaa !21
  %.not23 = icmp eq i16 %32, 0
  br i1 %.not23, label %35, label %33

33:                                               ; preds = %29
  %34 = tail call i32 @pthread_mutex_unlock(ptr noundef %0) #4
  br label %38

35:                                               ; preds = %29
  %36 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @spanlist_remove(ptr noundef nonnull %36, ptr noundef nonnull %1) #4
  %37 = tail call i32 @pthread_mutex_unlock(ptr noundef %0) #4
  tail call void @heap_freeSpan(ptr noundef nonnull %1, i8 noundef zeroext 0) #4
  br label %38

38:                                               ; preds = %35, %33, %22
  %.0 = phi i8 [ 0, %22 ], [ 0, %33 ], [ 1, %35 ]
  ret i8 %.0
}

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

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

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

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


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