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

; 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.bupval = type { ptr, %union.anon, i32 }
%union.anon = type { %struct.bvalue }
%struct.bvalue = type { %union.bvaldata, i32 }
%union.bvaldata = type { double }

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

13:                                               ; preds = %50, %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %52

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.bupval, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.bupval, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !20
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = icmp uge ptr %22, %23
  br i1 %24, label %25, label %47

25:                                               ; preds = %16
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.bupval, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !22
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %34, label %30

30:                                               ; preds = %25
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call ptr @be_realloc(ptr noundef %31, ptr noundef %32, i64 noundef 32, i64 noundef 0)
  br label %44

34:                                               ; preds = %25
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.bupval, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.bupval, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr align 8 %39, i64 16, i1 false), !tbaa.struct !23
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.bupval, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.bupval, ptr %42, i32 0, i32 0
  store ptr %41, ptr %43, align 8, !tbaa !20
  br label %44

44:                                               ; preds = %34, %30
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %45, ptr %46, align 8, !tbaa !5
  br label %50

47:                                               ; preds = %16
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bupval, ptr %48, i32 0, i32 1
  store ptr %49, ptr %7, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %47, %44
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %51, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !25

52:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare ptr @be_realloc(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 96}
!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 = !{!7, !7, i64 0}
!20 = !{!21, !6, i64 0}
!21 = !{!"bupval", !6, i64 0, !7, i64 8, !14, i64 24}
!22 = !{!21, !14, i64 24}
!23 = !{i64 0, i64 8, !19, i64 8, i64 4, !24}
!24 = !{!14, !14, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; 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
define dso_local void @be_upvals_close(ptr noundef %0, ptr noundef readnone %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not21 = icmp eq ptr %4, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %15
  %.023 = phi ptr [ %.1, %15 ], [ %3, %2 ]
  %.01722 = phi ptr [ %6, %15 ], [ %4, %2 ]
  %5 = getelementptr inbounds i8, ptr %.01722, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !18
  %7 = load ptr, ptr %.01722, align 8, !tbaa !19
  %.not19 = icmp ult ptr %7, %1
  br i1 %.not19, label %15, label %8

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.01722, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !21
  %.not20 = icmp eq i32 %10, 0
  br i1 %.not20, label %11, label %13

11:                                               ; preds = %8
  %12 = tail call ptr @be_realloc(ptr noundef %0, ptr noundef nonnull %.01722, i64 noundef 32, i64 noundef 0) #3
  br label %14

13:                                               ; preds = %8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(16) %7, i64 16, i1 false), !tbaa.struct !22
  store ptr %5, ptr %.01722, align 8, !tbaa !19
  br label %14

14:                                               ; preds = %13, %11
  store ptr %6, ptr %.023, align 8, !tbaa !24
  br label %15

15:                                               ; preds = %.lr.ph, %14
  %.1 = phi ptr [ %.023, %14 ], [ %5, %.lr.ph ]
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !25

._crit_edge:                                      ; preds = %15, %2
  ret void
}

declare ptr @be_realloc(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !9, i64 96}
!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 = !{!10, !10, i64 0}
!19 = !{!20, !9, i64 0}
!20 = !{!"bupval", !9, i64 0, !10, i64 8, !13, i64 24}
!21 = !{!20, !13, i64 24}
!22 = !{i64 0, i64 8, !18, i64 8, i64 4, !23}
!23 = !{!13, !13, i64 0}
!24 = !{!9, !9, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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