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

@heap_ = external global %struct.mheap, align 8
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@emptyspan = external dso_local global %struct.mspan, align 8
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 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

declare i32 @printf(ptr noundef, ...) #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 void @cache_refill(ptr noundef %0, i8 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr @heap_, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mcache, ptr %11, i32 0, i32 4
  %13 = load i8, ptr %4, align 1, !tbaa !9
  %14 = zext i8 %13 to i64
  %15 = getelementptr inbounds [134 x ptr], ptr %12, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mspan, ptr %17, i32 0, i32 9
  %19 = load i16, ptr %18, align 4, !tbaa !10
  %20 = zext i16 %19 to i64
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mspan, ptr %21, i32 0, i32 19
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = icmp ne i64 %20, %23
  br i1 %24, label %25, label %27

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

27:                                               ; preds = %25, %2
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp ne ptr %28, @emptyspan
  br i1 %29, label %30, label %43

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mspan, ptr %31, i32 0, i32 10
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !18
  %35 = add i32 %34, 3
  %36 = icmp ne i32 %33, %35
  br i1 %36, label %37, label %39

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

39:                                               ; preds = %37, %30
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mspan, ptr %40, i32 0, i32 10
  %42 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !18
  call void @atomic_Store(ptr noundef %41, i32 noundef %42)
  br label %43

43:                                               ; preds = %39, %27
  %44 = load i8, ptr %4, align 1, !tbaa !9
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds [134 x %struct.mcentral], ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 23), i64 0, i64 %45
  %47 = call ptr @central_cacheSpan(ptr noundef %46)
  store ptr %47, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %52

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

52:                                               ; preds = %50, %43
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mspan, ptr %53, i32 0, i32 9
  %55 = load i16, ptr %54, align 4, !tbaa !10
  %56 = zext i16 %55 to i64
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.mspan, ptr %57, i32 0, i32 19
  %59 = load i64, ptr %58, align 8, !tbaa !15
  %60 = icmp eq i64 %56, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %52
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 poison, ptr %10, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %63

63:                                               ; preds = %61, %52
  %64 = load i32, ptr getelementptr inbounds (%struct.mheap, ptr @heap_, i32 0, i32 16), align 8, !tbaa !18
  %65 = add i32 %64, 3
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mspan, ptr %66, i32 0, i32 10
  store i32 %65, ptr %67, align 8, !tbaa !17
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mcache, ptr %69, i32 0, i32 4
  %71 = load i8, ptr %4, align 1, !tbaa !9
  %72 = zext i8 %71 to i64
  %73 = getelementptr inbounds [134 x ptr], ptr %70, i64 0, i64 %72
  store ptr %68, ptr %73, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

declare ptr @central_cacheSpan(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 = !{!7, !7, i64 0}
!10 = !{!11, !13, i64 52}
!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, !12, i64 96}
!16 = !{!14, !14, i64 0}
!17 = !{!11, !14, i64 56}
!18 = !{!19, !14, i64 720}
!19 = !{!"mheap", !7, i64 0, !20, i64 40, !20, i64 48, !21, i64 56, !7, i64 88, !22, i64 232, !22, i64 296, !22, i64 360, !22, i64 424, !22, i64 488, !22, i64 552, !23, i64 616, !21, i64 640, !6, i64 672, !7, i64 680, !12, i64 712, !14, i64 720, !14, i64 724, !14, i64 728, !6, i64 736, !12, i64 744, !12, i64 752, !12, i64 760, !7, i64 768}
!20 = !{!"mtreap", !6, i64 0}
!21 = !{!"", !6, i64 0, !14, i64 8, !12, i64 16, !14, i64 24}
!22 = !{!"mfixalloc", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !14, i64 40, !12, i64 48, !7, i64 56}
!23 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16}


; 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 }
%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 [42 x i8], align 1
@emptyspan = external dso_local global %struct.mspan, align 8
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @cache_refill(ptr nocapture noundef %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = zext i8 %1 to i64
  %5 = getelementptr inbounds [134 x ptr], ptr %3, i64 0, i64 %4
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 52
  %8 = load i16, ptr %7, align 4, !tbaa !9
  %9 = zext i16 %8 to i64
  %10 = getelementptr inbounds i8, ptr %6, i64 96
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %.not = icmp eq i64 %11, %9
  br i1 %.not, label %14, label %12

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

14:                                               ; preds = %12, %2
  %.not14 = icmp eq ptr %6, @emptyspan
  br i1 %.not14, label %24, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %6, i64 56
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !16
  %19 = add i32 %18, 3
  %.not15 = icmp eq i32 %17, %19
  br i1 %.not15, label %22, label %20

20:                                               ; preds = %15
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !16
  br label %22

22:                                               ; preds = %20, %15
  %23 = phi i32 [ %.pre, %20 ], [ %18, %15 ]
  tail call void @atomic_Store(ptr noundef nonnull %16, i32 noundef %23) #3
  br label %24

24:                                               ; preds = %22, %14
  %25 = getelementptr inbounds [134 x %struct.mcentral], ptr getelementptr inbounds (i8, ptr @heap_, i64 768), i64 0, i64 %4
  %26 = tail call ptr @central_cacheSpan(ptr noundef nonnull %25) #3
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %30

30:                                               ; preds = %28, %24
  %31 = getelementptr inbounds i8, ptr %26, i64 52
  %32 = load i16, ptr %31, align 4, !tbaa !9
  %33 = zext i16 %32 to i64
  %34 = getelementptr inbounds i8, ptr %26, i64 96
  %35 = load i64, ptr %34, align 8, !tbaa !14
  %36 = icmp eq i64 %35, %33
  br i1 %36, label %37, label %39

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

39:                                               ; preds = %37, %30
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @heap_, i64 720), align 8, !tbaa !16
  %41 = add i32 %40, 3
  %42 = getelementptr inbounds i8, ptr %26, i64 56
  store i32 %41, ptr %42, align 8, !tbaa !15
  store ptr %26, ptr %5, align 8, !tbaa !5
  ret void
}

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

declare ptr @central_cacheSpan(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #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, !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 = !{!10, !11, i64 96}
!15 = !{!10, !13, i64 56}
!16 = !{!17, !13, i64 720}
!17 = !{!"mheap", !7, i64 0, !18, i64 40, !18, i64 48, !19, i64 56, !7, i64 88, !20, i64 232, !20, i64 296, !20, i64 360, !20, i64 424, !20, i64 488, !20, i64 552, !21, i64 616, !19, 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}
!18 = !{!"mtreap", !6, i64 0}
!19 = !{!"", !6, i64 0, !13, i64 8, !11, i64 16, !13, i64 24}
!20 = !{!"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}
!21 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16}


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