; 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.heapBits = type { ptr, i32, i32, ptr }
%struct.mcentral = type { %union.pthread_mutex_t, i8, %struct.mspanlist, %struct.mspanlist, i64 }
%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.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 }

@class_to_allocnpages = external global [67 x i8], align 16
@class_to_size = external global [67 x i16], align 16

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

declare signext i8 @sizeclass(i8 noundef zeroext) #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 ptr @central_grow(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca %struct.heapBits, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mcentral, ptr %11, i32 0, i32 1
  %13 = load i8, ptr %12, align 8, !tbaa !9
  %14 = call signext i8 @sizeclass(i8 noundef zeroext %13)
  %15 = sext i8 %14 to i64
  %16 = getelementptr inbounds [67 x i8], ptr @class_to_allocnpages, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !13
  %18 = zext i8 %17 to i64
  store i64 %18, ptr %4, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mcentral, ptr %19, i32 0, i32 1
  %21 = load i8, ptr %20, align 8, !tbaa !9
  %22 = call signext i8 @sizeclass(i8 noundef zeroext %21)
  %23 = sext i8 %22 to i64
  %24 = getelementptr inbounds [67 x i16], ptr @class_to_size, i64 0, i64 %23
  %25 = load i16, ptr %24, align 2, !tbaa !15
  %26 = zext i16 %25 to i64
  store i64 %26, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %27 = load i64, ptr %4, align 8, !tbaa !14
  %28 = shl i64 %27, 13
  %29 = load i64, ptr %5, align 8, !tbaa !14
  %30 = udiv i64 %28, %29
  store i64 %30, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %31 = load i64, ptr %4, align 8, !tbaa !14
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mcentral, ptr %32, i32 0, i32 1
  %34 = load i8, ptr %33, align 8, !tbaa !9
  %35 = call ptr @heap_alloc(i64 noundef %31, i8 noundef zeroext %34, i8 noundef zeroext 0, i8 noundef zeroext 1)
  store ptr %35, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %55

39:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mspan, ptr %40, i32 0, i32 3
  %42 = load i64, ptr %41, align 8, !tbaa !17
  store i64 %42, ptr %9, align 8, !tbaa !14
  %43 = load i64, ptr %9, align 8, !tbaa !14
  %44 = load i64, ptr %5, align 8, !tbaa !14
  %45 = load i64, ptr %6, align 8, !tbaa !14
  %46 = mul i64 %44, %45
  %47 = add i64 %43, %46
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mspan, ptr %48, i32 0, i32 4
  store i64 %47, ptr %49, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mspan, ptr %50, i32 0, i32 3
  %52 = load i64, ptr %51, align 8, !tbaa !17
  call void @hb_heapBitsForAddr(ptr dead_on_unwind writable sret(%struct.heapBits) align 8 %10, i64 noundef %52)
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  call void @hb_initSpan(ptr noundef byval(%struct.heapBits) align 8 %10, ptr noundef %53)
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %54, ptr %2, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %55

55:                                               ; preds = %39, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %56 = load ptr, ptr %2, align 8
  ret ptr %56
}

declare ptr @heap_alloc(i64 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #1

declare void @hb_heapBitsForAddr(ptr dead_on_unwind writable sret(%struct.heapBits) align 8, i64 noundef) #1

declare void @hb_initSpan(ptr noundef byval(%struct.heapBits) align 8, ptr noundef) #1

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 40}
!10 = !{!"mcentral", !7, i64 0, !7, i64 40, !11, i64 48, !11, i64 64, !12, i64 80}
!11 = !{!"mspanlist", !6, i64 0, !6, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !12, i64 24}
!18 = !{!"mspan", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !7, i64 48, !7, i64 49, !7, i64 50, !16, i64 52, !19, i64 56, !12, i64 64, !7, i64 72, !16, i64 74, !7, i64 76, !7, i64 77, !16, i64 78, !12, i64 80, !12, i64 88, !12, i64 96, !6, i64 104, !6, i64 112, !12, i64 120}
!19 = !{!"int", !7, i64 0}
!20 = !{!18, !12, i64 32}


; 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.heapBits = type { ptr, i32, i32, ptr }

@class_to_allocnpages = external local_unnamed_addr global [67 x i8], align 16
@class_to_size = external local_unnamed_addr global [67 x i16], align 16

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

declare signext i8 @sizeclass(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress 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 ptr @central_grow(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = alloca %struct.heapBits, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %5 = tail call signext i8 @sizeclass(i8 noundef zeroext %4) #3
  %6 = sext i8 %5 to i64
  %7 = getelementptr inbounds [67 x i8], ptr @class_to_allocnpages, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !12
  %.fr = freeze i8 %8
  %9 = zext i8 %.fr to i64
  %10 = load i8, ptr %3, align 8, !tbaa !5
  %11 = tail call signext i8 @sizeclass(i8 noundef zeroext %10) #3
  %12 = sext i8 %11 to i64
  %13 = getelementptr inbounds [67 x i16], ptr @class_to_size, i64 0, i64 %12
  %14 = load i16, ptr %13, align 2, !tbaa !13
  %15 = load i8, ptr %3, align 8, !tbaa !5
  %16 = tail call ptr @heap_alloc(i64 noundef %9, i8 noundef zeroext %15, i8 noundef zeroext 0, i8 noundef zeroext 1) #3
  %17 = icmp eq ptr %16, null
  br i1 %17, label %26, label %18

18:                                               ; preds = %1
  %19 = shl nuw nsw i64 %9, 13
  %20 = getelementptr inbounds i8, ptr %16, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %.lhs.trunc = trunc nuw nsw i64 %19 to i32
  %.rhs.trunc = zext i16 %14 to i32
  %22 = urem i32 %.lhs.trunc, %.rhs.trunc
  %.zext = zext nneg i32 %22 to i64
  %23 = add i64 %21, %19
  %24 = sub i64 %23, %.zext
  %25 = getelementptr inbounds i8, ptr %16, i64 32
  store i64 %24, ptr %25, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  call void @hb_heapBitsForAddr(ptr dead_on_unwind nonnull writable sret(%struct.heapBits) align 8 %2, i64 noundef %21) #3
  call void @hb_initSpan(ptr noundef nonnull byval(%struct.heapBits) align 8 %2, ptr noundef nonnull %16) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  br label %26

26:                                               ; preds = %1, %18
  ret ptr %16
}

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

declare void @hb_heapBitsForAddr(ptr dead_on_unwind writable sret(%struct.heapBits) align 8, i64 noundef) local_unnamed_addr #1

declare void @hb_initSpan(ptr noundef byval(%struct.heapBits) align 8, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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, !7, i64 40}
!6 = !{!"mcentral", !7, i64 0, !7, i64 40, !9, i64 48, !9, i64 64, !11, i64 80}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"mspanlist", !10, i64 0, !10, i64 8}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !11, i64 24}
!16 = !{!"mspan", !10, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 49, !7, i64 50, !14, i64 52, !17, i64 56, !11, i64 64, !7, i64 72, !14, i64 74, !7, i64 76, !7, i64 77, !14, i64 78, !11, i64 80, !11, i64 88, !11, i64 96, !10, i64 104, !10, i64 112, !11, i64 120}
!17 = !{!"int", !7, i64 0}
!18 = !{!16, !11, i64 32}


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