; LLVM IR from berry-lang/berry :: src (be_mem)

; 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.bvm = type { %struct.bglobaldesc, ptr, ptr, ptr, %struct.bvector, %struct.bvector, ptr, ptr, ptr, ptr, ptr, %struct.bvector, %struct.bmoduledesc, %struct.bstringtable, %struct.bvector, ptr, %struct.bgc, ptr, i8, i64, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.bglobaldesc = type { %struct.anon, %struct.anon.0 }
%struct.anon = type { ptr, %struct.bvector }
%struct.anon.0 = type { ptr, %struct.bvector }
%struct.bmoduledesc = type { ptr, ptr }
%struct.bstringtable = type { ptr, i32, i32 }
%struct.bvector = type { i32, i32, i32, ptr, ptr }
%struct.bgc = type { ptr, ptr, ptr, ptr, ptr, i64, i64, i8, i8 }
%struct.gc16_t = type { i32, ptr, [31 x [16 x i8]] }
%struct.gc32_t = type { i32, ptr, [15 x [32 x i8]] }

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

; 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 @be_gc_memory_pools_info(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.bvm, ptr %11, i32 0, i32 16
  %13 = getelementptr inbounds %struct.bgc, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %9, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %18, %3
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %32

18:                                               ; preds = %15
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = add i64 %19, 31
  store i64 %20, ptr %8, align 8, !tbaa !9
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gc16_t, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !20
  %24 = call i32 @llvm.ctpop.i32(i32 %23)
  %25 = sub nsw i32 31, %24
  %26 = sext i32 %25 to i64
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = add i64 %27, %26
  store i64 %28, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gc16_t, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  store ptr %31, ptr %9, align 8, !tbaa !5
  br label %15, !llvm.loop !23

32:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bvm, ptr %33, i32 0, i32 16
  %35 = getelementptr inbounds %struct.bgc, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !25
  store ptr %36, ptr %10, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %40, %32
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %54

40:                                               ; preds = %37
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = add i64 %41, 15
  store i64 %42, ptr %8, align 8, !tbaa !9
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gc32_t, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !26
  %46 = call i32 @llvm.ctpop.i32(i32 %45)
  %47 = sub nsw i32 15, %46
  %48 = sext i32 %47 to i64
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = add i64 %49, %48
  store i64 %50, ptr %7, align 8, !tbaa !9
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.gc32_t, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !28
  store ptr %53, ptr %10, align 8, !tbaa !5
  br label %37, !llvm.loop !29

54:                                               ; preds = %37
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %60

57:                                               ; preds = %54
  %58 = load i64, ptr %7, align 8, !tbaa !9
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %58, ptr %59, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %57, %54
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %66

63:                                               ; preds = %60
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %63, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 336}
!12 = !{!"bvm", !13, i64 0, !6, i64 80, !6, i64 88, !6, i64 96, !15, i64 104, !15, i64 136, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !15, i64 208, !17, i64 240, !18, i64 256, !15, i64 272, !6, i64 304, !19, i64 312, !6, i64 376, !7, i64 384, !10, i64 392, !6, i64 400, !16, i64 408, !16, i64 412, !16, i64 416, !16, i64 420, !16, i64 424, !16, i64 428, !16, i64 432, !16, i64 436, !16, i64 440, !16, i64 444, !16, i64 448, !16, i64 452, !16, i64 456, !16, i64 460, !16, i64 464, !16, i64 468, !16, i64 472, !16, i64 476, !16, i64 480, !16, i64 484, !16, i64 488, !16, i64 492, !16, i64 496}
!13 = !{!"", !14, i64 0, !14, i64 40}
!14 = !{!"", !6, i64 0, !15, i64 8}
!15 = !{!"bvector", !16, i64 0, !16, i64 4, !16, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"int", !7, i64 0}
!17 = !{!"bmoduledesc", !6, i64 0, !6, i64 8}
!18 = !{!"bstringtable", !6, i64 0, !16, i64 8, !16, i64 12}
!19 = !{!"bgc", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !7, i64 57}
!20 = !{!21, !16, i64 0}
!21 = !{!"gc16_t", !16, i64 0, !6, i64 8, !7, i64 16}
!22 = !{!21, !6, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!12, !6, i64 344}
!26 = !{!27, !16, i64 0}
!27 = !{!"gc32_t", !16, i64 0, !6, i64 8, !7, i64 16}
!28 = !{!27, !6, i64 8}
!29 = distinct !{!29, !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"

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @be_gc_memory_pools_info(ptr nocapture noundef readonly %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 336
  %.01726 = load ptr, ptr %4, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.01726, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.01730 = phi ptr [ %.017, %.lr.ph ], [ %.01726, %3 ]
  %.01829 = phi i64 [ %5, %.lr.ph ], [ 0, %3 ]
  %.01928 = phi i64 [ %10, %.lr.ph ], [ 0, %3 ]
  %5 = add i64 %.01829, 31
  %6 = load i32, ptr %.01730, align 8, !tbaa !9
  %7 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %6)
  %8 = sub nsw i32 31, %7
  %9 = sext i32 %8 to i64
  %10 = add i64 %.01928, %9
  %11 = getelementptr inbounds i8, ptr %.01730, i64 8
  %.017 = load ptr, ptr %11, align 8, !tbaa !5
  %.not = icmp eq ptr %.017, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.019.lcssa = phi i64 [ 0, %3 ], [ %10, %.lr.ph ]
  %.018.lcssa = phi i64 [ 0, %3 ], [ %5, %.lr.ph ]
  %12 = getelementptr inbounds i8, ptr %0, i64 344
  %.032 = load ptr, ptr %12, align 8, !tbaa !5
  %.not2333 = icmp eq ptr %.032, null
  br i1 %.not2333, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %._crit_edge, %.lr.ph38
  %.036 = phi ptr [ %.0, %.lr.ph38 ], [ %.032, %._crit_edge ]
  %.135 = phi i64 [ %13, %.lr.ph38 ], [ %.018.lcssa, %._crit_edge ]
  %.12034 = phi i64 [ %18, %.lr.ph38 ], [ %.019.lcssa, %._crit_edge ]
  %13 = add i64 %.135, 15
  %14 = load i32, ptr %.036, align 8, !tbaa !14
  %15 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %14)
  %16 = sub nsw i32 15, %15
  %17 = sext i32 %16 to i64
  %18 = add i64 %.12034, %17
  %19 = getelementptr inbounds i8, ptr %.036, i64 8
  %.0 = load ptr, ptr %19, align 8, !tbaa !5
  %.not23 = icmp eq ptr %.0, null
  br i1 %.not23, label %._crit_edge39, label %.lr.ph38, !llvm.loop !16

._crit_edge39:                                    ; preds = %.lr.ph38, %._crit_edge
  %.120.lcssa = phi i64 [ %.019.lcssa, %._crit_edge ], [ %18, %.lr.ph38 ]
  %.1.lcssa = phi i64 [ %.018.lcssa, %._crit_edge ], [ %13, %.lr.ph38 ]
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %21, label %20

20:                                               ; preds = %._crit_edge39
  store i64 %.120.lcssa, ptr %1, align 8, !tbaa !17
  br label %21

21:                                               ; preds = %20, %._crit_edge39
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %23, label %22

22:                                               ; preds = %21
  store i64 %.1.lcssa, ptr %2, align 8, !tbaa !17
  br label %23

23:                                               ; preds = %22, %21
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #1

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !11, i64 0}
!10 = !{!"gc16_t", !11, i64 0, !6, i64 8, !7, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !11, i64 0}
!15 = !{!"gc32_t", !11, i64 0, !6, i64 8, !7, i64 16}
!16 = distinct !{!16, !13}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass