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

; 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.mcache = type { i64, i64, i64, i64, [134 x ptr], [67 x i64], i32 }
%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 }

@.str = external hidden unnamed_addr constant [50 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @cache_nextFree(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mcache, ptr %15, i32 0, i32 4
  %17 = load i8, ptr %6, align 1, !tbaa !9
  %18 = zext i8 %17 to i64
  %19 = getelementptr inbounds [134 x ptr], ptr %16, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %20, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %21, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = call i64 @span_nextFreeIndex(ptr noundef %22)
  store i64 %23, ptr %10, align 8, !tbaa !10
  %24 = load i64, ptr %10, align 8, !tbaa !10
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mspan, ptr %25, i32 0, i32 19
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = icmp eq i64 %24, %27
  br i1 %28, label %29, label %52

29:                                               ; preds = %4
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mspan, ptr %30, i32 0, i32 9
  %32 = load i16, ptr %31, align 4, !tbaa !16
  %33 = zext i16 %32 to i64
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mspan, ptr %34, i32 0, i32 19
  %36 = load i64, ptr %35, align 8, !tbaa !12
  %37 = icmp ne i64 %33, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %29
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 poison, ptr %11, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %40

40:                                               ; preds = %38, %29
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i8, ptr %6, align 1, !tbaa !9
  call void @cache_refill(ptr noundef %41, i8 noundef zeroext %42)
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 1, ptr %43, align 1, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mcache, ptr %44, i32 0, i32 4
  %46 = load i8, ptr %6, align 1, !tbaa !9
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds [134 x ptr], ptr %45, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  store ptr %49, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = call i64 @span_nextFreeIndex(ptr noundef %50)
  store i64 %51, ptr %10, align 8, !tbaa !10
  br label %52

52:                                               ; preds = %40, %4
  %53 = load i64, ptr %10, align 8, !tbaa !10
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mspan, ptr %54, i32 0, i32 19
  %56 = load i64, ptr %55, align 8, !tbaa !12
  %57 = icmp uge i64 %53, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %52
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 poison, ptr %12, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %60

60:                                               ; preds = %58, %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %61 = load i64, ptr %10, align 8, !tbaa !10
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mspan, ptr %62, i32 0, i32 17
  %64 = load i64, ptr %63, align 8, !tbaa !18
  %65 = mul i64 %61, %64
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mspan, ptr %66, i32 0, i32 3
  %68 = load i64, ptr %67, align 8, !tbaa !19
  %69 = add i64 %65, %68
  store i64 %69, ptr %13, align 8, !tbaa !10
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mspan, ptr %70, i32 0, i32 9
  %72 = load i16, ptr %71, align 4, !tbaa !16
  %73 = add i16 %72, 1
  store i16 %73, ptr %71, align 4, !tbaa !16
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.mspan, ptr %74, i32 0, i32 9
  %76 = load i16, ptr %75, align 4, !tbaa !16
  %77 = zext i16 %76 to i64
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.mspan, ptr %78, i32 0, i32 19
  %80 = load i64, ptr %79, align 8, !tbaa !12
  %81 = icmp ugt i64 %77, %80
  br i1 %81, label %82, label %84

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

84:                                               ; preds = %82, %60
  %85 = load i64, ptr %13, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i64 %85
}

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

declare i64 @span_nextFreeIndex(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @cache_refill(ptr noundef, i8 noundef zeroext) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 96}
!13 = !{!"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, !14, i64 52, !15, 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, !6, i64 104, !6, i64 112, !11, i64 120}
!14 = !{!"short", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!13, !14, i64 52}
!17 = !{!15, !15, i64 0}
!18 = !{!13, !11, i64 80}
!19 = !{!13, !11, i64 24}


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

@.str = external hidden unnamed_addr constant [50 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @cache_nextFree(ptr noundef %0, i8 noundef zeroext %1, ptr nocapture noundef readnone %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = zext i8 %1 to i64
  %7 = getelementptr inbounds [134 x ptr], ptr %5, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 0, ptr %3, align 1, !tbaa !9
  %9 = tail call i64 @span_nextFreeIndex(ptr noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %8, i64 96
  %11 = load i64, ptr %10, align 8, !tbaa !10
  %12 = icmp eq i64 %9, %11
  br i1 %12, label %13, label %22

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %8, i64 52
  %15 = load i16, ptr %14, align 4, !tbaa !15
  %16 = zext i16 %15 to i64
  %.not = icmp eq i64 %9, %16
  br i1 %.not, label %19, label %17

17:                                               ; preds = %13
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %19

19:                                               ; preds = %17, %13
  tail call void @cache_refill(ptr noundef nonnull %0, i8 noundef zeroext %1)
  store i8 1, ptr %3, align 1, !tbaa !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = tail call i64 @span_nextFreeIndex(ptr noundef %20) #3
  %.phi.trans.insert = getelementptr inbounds i8, ptr %20, i64 96
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !10
  br label %22

22:                                               ; preds = %19, %4
  %23 = phi i64 [ %.pre, %19 ], [ %11, %4 ]
  %.022 = phi i64 [ %21, %19 ], [ %9, %4 ]
  %.0 = phi ptr [ %20, %19 ], [ %8, %4 ]
  %.not25 = icmp ult i64 %.022, %23
  br i1 %.not25, label %27, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %.0, i64 96
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %.pre26 = load i64, ptr %25, align 8, !tbaa !10
  br label %27

27:                                               ; preds = %24, %22
  %28 = phi i64 [ %.pre26, %24 ], [ %23, %22 ]
  %29 = getelementptr inbounds i8, ptr %.0, i64 80
  %30 = load i64, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %.0, i64 24
  %32 = load i64, ptr %31, align 8, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %.0, i64 52
  %34 = load i16, ptr %33, align 4, !tbaa !15
  %35 = add i16 %34, 1
  store i16 %35, ptr %33, align 4, !tbaa !15
  %36 = zext i16 %35 to i64
  %37 = icmp ult i64 %28, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %27
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %40

40:                                               ; preds = %38, %27
  %41 = mul i64 %30, %.022
  %42 = add i64 %41, %32
  ret i64 %42
}

declare i64 @span_nextFreeIndex(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @cache_refill(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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 = { 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 }

!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, !12, i64 96}
!11 = !{!"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, !13, i64 52, !14, i64 56, !12, i64 64, !7, i64 72, !13, i64 74, !7, i64 76, !7, i64 77, !13, i64 78, !12, i64 80, !12, i64 88, !12, i64 96, !6, i64 104, !6, i64 112, !12, i64 120}
!12 = !{!"long", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!11, !13, i64 52}
!16 = !{!11, !12, i64 80}
!17 = !{!11, !12, i64 24}


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