; 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.bclosure = type { ptr, i8, i8, i8, ptr, ptr, [1 x ptr] }
%struct.bproto = type { ptr, i8, i8, i8, i8, i8, i8, i16, i16, i16, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, i32 }
%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.bcallframe = type { ptr, ptr, ptr, ptr, i32 }
%struct.bvalue = type { %union.bvaldata, i32 }
%union.bvaldata = type { double }
%struct.bupvaldesc = type { ptr, i8, i8 }
%struct.bupval = type { ptr, %union.anon, i32 }
%union.anon = type { %struct.bvalue }

; Function Attrs: nounwind uwtable
define dso_local void @be_initupvals(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = 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 4, ptr %5) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.bclosure, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.bproto, ptr %13, i32 0, i32 4
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  store i32 %16, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.bclosure, ptr %17, i32 0, i32 5
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.bproto, ptr %19, i32 0, i32 11
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  store ptr %21, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.bvm, ptr %22, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  store ptr %24, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.bclosure, ptr %25, i32 0, i32 6
  %27 = getelementptr inbounds [1 x ptr], ptr %26, i64 0, i64 0
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.bvm, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !26
  %31 = getelementptr inbounds %struct.bcallframe, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !27
  %33 = getelementptr inbounds %struct.bvalue, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !29
  %35 = getelementptr inbounds %struct.bclosure, ptr %34, i32 0, i32 6
  %36 = getelementptr inbounds [1 x ptr], ptr %35, i64 0, i64 0
  store ptr %36, ptr %9, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %73, %2
  %38 = load i32, ptr %5, align 4, !tbaa !15
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr %5, align 4, !tbaa !15
  %40 = icmp ne i32 %38, 0
  br i1 %40, label %41, label %78

41:                                               ; preds = %37
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.bupvaldesc, ptr %42, i32 0, i32 1
  %44 = load i8, ptr %43, align 8, !tbaa !30
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %46, label %58

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bupvaldesc, ptr %48, i32 0, i32 2
  %50 = load i8, ptr %49, align 1, !tbaa !32
  %51 = zext i8 %50 to i32
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.bvalue, ptr %47, i64 %52
  store ptr %53, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = call ptr @findupval(ptr noundef %54, ptr noundef %55)
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %56, ptr %57, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %67

58:                                               ; preds = %41
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.bupvaldesc, ptr %60, i32 0, i32 2
  %62 = load i8, ptr %61, align 1, !tbaa !32
  %63 = zext i8 %62 to i64
  %64 = getelementptr inbounds ptr, ptr %59, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %65, ptr %66, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %58, %46
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.bupval, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !33
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %70, align 8, !tbaa !33
  br label %73

73:                                               ; preds = %67
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.bupvaldesc, ptr %74, i32 1
  store ptr %75, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds ptr, ptr %76, i32 1
  store ptr %77, ptr %8, align 8, !tbaa !5
  br label %37, !llvm.loop !35

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @findupval(ptr noundef, ptr noundef) #0

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

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 24}
!10 = !{!"bclosure", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !6, i64 16, !6, i64 24, !7, i64 32}
!11 = !{!12, !7, i64 11}
!12 = !{!"bproto", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !13, i64 14, !13, i64 16, !13, i64 18, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !14, i64 88, !6, i64 96, !14, i64 104}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!12, !6, i64 32}
!17 = !{!18, !6, i64 176}
!18 = !{!"bvm", !19, i64 0, !6, i64 80, !6, i64 88, !6, i64 96, !21, i64 104, !21, i64 136, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !21, i64 208, !22, i64 240, !23, i64 256, !21, i64 272, !6, i64 304, !24, i64 312, !6, i64 376, !7, i64 384, !25, 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}
!19 = !{!"", !20, i64 0, !20, i64 40}
!20 = !{!"", !6, i64 0, !21, i64 8}
!21 = !{!"bvector", !14, i64 0, !14, i64 4, !14, i64 8, !6, i64 16, !6, i64 24}
!22 = !{!"bmoduledesc", !6, i64 0, !6, i64 8}
!23 = !{!"bstringtable", !6, i64 0, !14, i64 8, !14, i64 12}
!24 = !{!"bgc", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !25, i64 40, !25, i64 48, !7, i64 56, !7, i64 57}
!25 = !{!"long", !7, i64 0}
!26 = !{!18, !6, i64 168}
!27 = !{!28, !6, i64 0}
!28 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!29 = !{!7, !7, i64 0}
!30 = !{!31, !7, i64 8}
!31 = !{!"", !6, i64 0, !7, i64 8, !7, i64 9}
!32 = !{!31, !7, i64 9}
!33 = !{!34, !14, i64 24}
!34 = !{!"bupval", !6, i64 0, !7, i64 8, !14, i64 24}
!35 = distinct !{!35, !36}
!36 = !{!"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"

%struct.bvalue = type { %union.bvaldata, i32 }
%union.bvaldata = type { double }

; Function Attrs: nounwind uwtable
define dso_local void @be_initupvals(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 11
  %6 = load i8, ptr %5, align 1, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %0, i64 176
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 168
  %10 = load ptr, ptr %9, align 8, !tbaa !23
  %11 = load ptr, ptr %10, align 8, !tbaa !24
  %12 = load ptr, ptr %11, align 8, !tbaa !26
  %13 = getelementptr inbounds i8, ptr %12, i64 32
  %.not20 = icmp eq i8 %6, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  %15 = getelementptr inbounds i8, ptr %4, i64 32
  %16 = load ptr, ptr %15, align 8, !tbaa !27
  %17 = zext i8 %6 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %30
  %.in = phi i32 [ %18, %30 ], [ %17, %.lr.ph.preheader ]
  %.01722 = phi ptr [ %34, %30 ], [ %16, %.lr.ph.preheader ]
  %.01821 = phi ptr [ %35, %30 ], [ %14, %.lr.ph.preheader ]
  %18 = add nsw i32 %.in, -1
  %19 = getelementptr inbounds i8, ptr %.01722, i64 8
  %20 = load i8, ptr %19, align 8, !tbaa !28
  %.not19 = icmp eq i8 %20, 0
  %21 = getelementptr inbounds i8, ptr %.01722, i64 9
  %22 = load i8, ptr %21, align 1, !tbaa !30
  %23 = zext i8 %22 to i64
  br i1 %.not19, label %27, label %24

24:                                               ; preds = %.lr.ph
  %25 = getelementptr inbounds %struct.bvalue, ptr %8, i64 %23
  %26 = tail call ptr @findupval(ptr noundef %0, ptr noundef %25)
  br label %30

27:                                               ; preds = %.lr.ph
  %28 = getelementptr inbounds ptr, ptr %13, i64 %23
  %29 = load ptr, ptr %28, align 8, !tbaa !31
  br label %30

30:                                               ; preds = %27, %24
  %storemerge = phi ptr [ %29, %27 ], [ %26, %24 ]
  store ptr %storemerge, ptr %.01821, align 8, !tbaa !31
  %31 = getelementptr inbounds i8, ptr %storemerge, i64 24
  %32 = load i32, ptr %31, align 8, !tbaa !32
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 8, !tbaa !32
  %34 = getelementptr inbounds i8, ptr %.01722, i64 16
  %35 = getelementptr inbounds i8, ptr %.01821, i64 8
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !34

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

; Function Attrs: nounwind uwtable
declare hidden ptr @findupval(ptr noundef, ptr noundef) local_unnamed_addr #0

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, !7, i64 24}
!6 = !{!"bclosure", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !7, i64 16, !7, i64 24, !8, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !8, i64 11}
!11 = !{!"bproto", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !12, i64 14, !12, i64 16, !12, i64 18, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !13, i64 88, !7, i64 96, !13, i64 104}
!12 = !{!"short", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!15, !7, i64 176}
!15 = !{!"bvm", !16, i64 0, !7, i64 80, !7, i64 88, !7, i64 96, !18, i64 104, !18, i64 136, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !18, i64 208, !19, i64 240, !20, i64 256, !18, i64 272, !7, i64 304, !21, i64 312, !7, i64 376, !8, i64 384, !22, i64 392, !7, 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}
!16 = !{!"", !17, i64 0, !17, i64 40}
!17 = !{!"", !7, i64 0, !18, i64 8}
!18 = !{!"bvector", !13, i64 0, !13, i64 4, !13, i64 8, !7, i64 16, !7, i64 24}
!19 = !{!"bmoduledesc", !7, i64 0, !7, i64 8}
!20 = !{!"bstringtable", !7, i64 0, !13, i64 8, !13, i64 12}
!21 = !{!"bgc", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !22, i64 40, !22, i64 48, !8, i64 56, !8, i64 57}
!22 = !{!"long", !8, i64 0}
!23 = !{!15, !7, i64 168}
!24 = !{!25, !7, i64 0}
!25 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !13, i64 32}
!26 = !{!8, !8, i64 0}
!27 = !{!11, !7, i64 32}
!28 = !{!29, !8, i64 8}
!29 = !{!"", !7, i64 0, !8, i64 8, !8, i64 9}
!30 = !{!29, !8, i64 9}
!31 = !{!7, !7, i64 0}
!32 = !{!33, !13, i64 24}
!33 = !{!"bupval", !7, i64 0, !8, i64 8, !13, i64 24}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}


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