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

16:                                               ; preds = %41, %1
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %42

19:                                               ; preds = %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.gc16_t, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !19
  %23 = zext i32 %22 to i64
  %24 = icmp eq i64 %23, 2147483647
  br i1 %24, label %25, label %35

25:                                               ; preds = %19
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gc16_t, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %28, ptr %29, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %30, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.gc16_t, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !21
  store ptr %33, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %34) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %41

35:                                               ; preds = %19
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gc16_t, ptr %36, i32 0, i32 1
  store ptr %37, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gc16_t, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !21
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %35, %25
  br label %16, !llvm.loop !22

42:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.bvm, ptr %43, i32 0, i32 16
  %45 = getelementptr inbounds %struct.bgc, ptr %44, i32 0, i32 4
  store ptr %45, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bvm, ptr %46, i32 0, i32 16
  %48 = getelementptr inbounds %struct.bgc, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !24
  store ptr %49, ptr %7, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %75, %42
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %76

53:                                               ; preds = %50
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gc32_t, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !25
  %57 = zext i32 %56 to i64
  %58 = icmp eq i64 %57, 32767
  br i1 %58, label %59, label %69

59:                                               ; preds = %53
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.gc32_t, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !27
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %62, ptr %63, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %64, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gc32_t, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !27
  store ptr %67, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %68) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %75

69:                                               ; preds = %53
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.gc32_t, ptr %70, i32 0, i32 1
  store ptr %71, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gc32_t, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !27
  store ptr %74, ptr %7, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %69, %59
  br label %50, !llvm.loop !28

76:                                               ; preds = %50
  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 %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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, !14, i64 0}
!20 = !{!"gc16_t", !14, i64 0, !6, i64 8, !7, i64 16}
!21 = !{!20, !6, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!10, !6, i64 344}
!25 = !{!26, !14, i64 0}
!26 = !{!"gc32_t", !14, i64 0, !6, i64 8, !7, i64 16}
!27 = !{!26, !6, i64 8}
!28 = distinct !{!28, !23}


; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

.lr.ph:                                           ; preds = %1, %9
  %.031 = phi ptr [ %.1, %9 ], [ %2, %1 ]
  %.02630 = phi ptr [ %7, %9 ], [ %3, %1 ]
  %4 = load i32, ptr %.02630, align 8, !tbaa !18
  %5 = icmp eq i32 %4, 2147483647
  %6 = getelementptr inbounds i8, ptr %.02630, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !20
  br i1 %5, label %8, label %9

8:                                                ; preds = %.lr.ph
  store ptr %7, ptr %.031, align 8, !tbaa !21
  tail call void @free(ptr noundef nonnull %.02630) #2
  br label %9

9:                                                ; preds = %.lr.ph, %8
  %.1 = phi ptr [ %.031, %8 ], [ %6, %.lr.ph ]
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %9, %1
  %10 = getelementptr inbounds i8, ptr %0, i64 344
  %11 = load ptr, ptr %10, align 8, !tbaa !24
  %.not2832 = icmp eq ptr %11, null
  br i1 %.not2832, label %._crit_edge37, label %.lr.ph36

.lr.ph36:                                         ; preds = %._crit_edge, %17
  %.02234 = phi ptr [ %15, %17 ], [ %11, %._crit_edge ]
  %.02433 = phi ptr [ %.125, %17 ], [ %10, %._crit_edge ]
  %12 = load i32, ptr %.02234, align 8, !tbaa !25
  %13 = icmp eq i32 %12, 32767
  %14 = getelementptr inbounds i8, ptr %.02234, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !27
  br i1 %13, label %16, label %17

16:                                               ; preds = %.lr.ph36
  store ptr %15, ptr %.02433, align 8, !tbaa !21
  tail call void @free(ptr noundef nonnull %.02234) #2
  br label %17

17:                                               ; preds = %.lr.ph36, %16
  %.125 = phi ptr [ %.02433, %16 ], [ %14, %.lr.ph36 ]
  %.not28 = icmp eq ptr %15, null
  br i1 %.not28, label %._crit_edge37, label %.lr.ph36, !llvm.loop !28

._crit_edge37:                                    ; preds = %17, %._crit_edge
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !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, !13, i64 0}
!19 = !{!"gc16_t", !13, i64 0, !9, i64 8, !10, i64 16}
!20 = !{!19, !9, i64 8}
!21 = !{!9, !9, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!6, !9, i64 344}
!25 = !{!26, !13, i64 0}
!26 = !{!"gc32_t", !13, i64 0, !9, i64 8, !10, i64 16}
!27 = !{!26, !9, i64 8}
!28 = distinct !{!28, !23}


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