; 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: nounwind uwtable
declare dso_local void @be_os_free(ptr noundef) #0

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

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

11:                                               ; preds = %14, %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %20

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %15, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.gc16_t, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @be_os_free(ptr noundef %19)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %11, !llvm.loop !21

20:                                               ; preds = %11
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.bvm, ptr %21, i32 0, i32 16
  %23 = getelementptr inbounds %struct.bgc, ptr %22, i32 0, i32 3
  store ptr null, ptr %23, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bvm, ptr %24, i32 0, i32 16
  %26 = getelementptr inbounds %struct.bgc, ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  store ptr %27, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %31, %20
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %37

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %32, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gc32_t, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !24
  store ptr %35, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @be_os_free(ptr noundef %36)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %28, !llvm.loop !26

37:                                               ; preds = %28
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bvm, ptr %38, i32 0, i32 16
  %40 = getelementptr inbounds %struct.bgc, ptr %39, i32 0, i32 4
  store ptr null, ptr %40, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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


; 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: nounwind uwtable
declare dso_local void @be_os_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @be_gc_free_memory_pools(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 336
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not14 = icmp eq ptr %3, null
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.015 = phi ptr [ %5, %.lr.ph ], [ %3, %1 ]
  %4 = getelementptr inbounds i8, ptr %.015, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !18
  tail call void @be_os_free(ptr noundef nonnull %.015)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph, %1
  store ptr null, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 344
  %7 = load ptr, ptr %6, align 8, !tbaa !22
  %.not1316 = icmp eq ptr %7, null
  br i1 %.not1316, label %._crit_edge20, label %.lr.ph19

.lr.ph19:                                         ; preds = %._crit_edge, %.lr.ph19
  %.01217 = phi ptr [ %9, %.lr.ph19 ], [ %7, %._crit_edge ]
  %8 = getelementptr inbounds i8, ptr %.01217, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !23
  tail call void @be_os_free(ptr noundef nonnull %.01217)
  %.not13 = icmp eq ptr %9, null
  br i1 %.not13, label %._crit_edge20, label %.lr.ph19, !llvm.loop !25

._crit_edge20:                                    ; preds = %.lr.ph19, %._crit_edge
  store ptr null, ptr %6, align 8, !tbaa !22
  ret void
}

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

!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, !9, i64 336}
!6 = !{!"bvm", !7, i64 0, !9, i64 80, !9, i64 88, !9, i64 96, !12, i64 104, !12, i64 136, !9, i64 168, !9, i64 176, !9, i64 184, !9, i64 192, !9, i64 200, !12, i64 208, !14, i64 240, !15, i64 256, !12, i64 272, !9, i64 304, !16, i64 312, !9, i64 376, !10, i64 384, !17, i64 392, !9, i64 400, !13, i64 408, !13, i64 412, !13, i64 416, !13, i64 420, !13, i64 424, !13, i64 428, !13, i64 432, !13, i64 436, !13, i64 440, !13, i64 444, !13, i64 448, !13, i64 452, !13, i64 456, !13, i64 460, !13, i64 464, !13, i64 468, !13, i64 472, !13, i64 476, !13, i64 480, !13, i64 484, !13, i64 488, !13, i64 492, !13, i64 496}
!7 = !{!"", !8, i64 0, !8, i64 40}
!8 = !{!"", !9, i64 0, !12, i64 8}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"bvector", !13, i64 0, !13, i64 4, !13, i64 8, !9, i64 16, !9, i64 24}
!13 = !{!"int", !10, i64 0}
!14 = !{!"bmoduledesc", !9, i64 0, !9, i64 8}
!15 = !{!"bstringtable", !9, i64 0, !13, i64 8, !13, i64 12}
!16 = !{!"bgc", !9, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !9, i64 32, !17, i64 40, !17, i64 48, !10, i64 56, !10, i64 57}
!17 = !{!"long", !10, i64 0}
!18 = !{!19, !9, i64 8}
!19 = !{!"gc16_t", !13, i64 0, !9, i64 8, !10, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !9, i64 344}
!23 = !{!24, !9, i64 8}
!24 = !{!"gc32_t", !13, i64 0, !9, i64 8, !10, i64 16}
!25 = distinct !{!25, !21}


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