; 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.bgcobject = type { ptr, i8, i8 }
%struct.bntvclos = type { ptr, i8, i8, i8, ptr, ptr }
%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.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

declare ptr @be_newgcobj(ptr noundef, i32 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @be_newntvclosure(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = mul i64 8, %11
  %13 = add i64 32, %12
  store i64 %13, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i64, ptr %7, align 8, !tbaa !11
  %16 = call ptr @be_newgcobj(ptr noundef %14, i32 noundef 70, i64 noundef %15)
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %27

19:                                               ; preds = %3
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.bgcobject, ptr %20, i32 0, i32 1
  %22 = load i8, ptr %21, align 8, !tbaa !13
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %23, 70
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  br label %28

27:                                               ; preds = %19, %3
  br label %28

28:                                               ; preds = %27, %25
  %29 = phi ptr [ %26, %25 ], [ null, %27 ]
  store ptr %29, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %63

32:                                               ; preds = %28
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.bntvclos, ptr %34, i32 0, i32 5
  store ptr %33, ptr %35, align 8, !tbaa !15
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = trunc i32 %36 to i8
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bntvclos, ptr %38, i32 0, i32 3
  store i8 %37, ptr %39, align 2, !tbaa !17
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %62

42:                                               ; preds = %32
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.bvm, ptr %44, i32 0, i32 8
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds %struct.bvalue, ptr %46, i32 0, i32 0
  store ptr %43, ptr %47, align 8, !tbaa !26
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bvm, ptr %48, i32 0, i32 8
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = getelementptr inbounds %struct.bvalue, ptr %50, i32 0, i32 1
  store i32 70, ptr %51, align 8, !tbaa !27
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bvm, ptr %52, i32 0, i32 8
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = getelementptr inbounds %struct.bvalue, ptr %54, i32 1
  store ptr %55, ptr %53, align 8, !tbaa !18
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  call void @init_upvals(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.bvm, ptr %58, i32 0, i32 8
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = getelementptr inbounds %struct.bvalue, ptr %60, i64 -1
  store ptr %61, ptr %59, align 8, !tbaa !18
  br label %62

62:                                               ; preds = %42, %32
  br label %63

63:                                               ; preds = %62, %28
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  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 ptr %64
}

; Function Attrs: nounwind uwtable
declare hidden void @init_upvals(ptr noundef, ptr noundef) #2

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


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

declare ptr @be_newgcobj(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @be_newntvclosure(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %2 to i64
  %5 = shl nsw i64 %4, 3
  %6 = add nsw i64 %5, 32
  %7 = tail call ptr @be_newgcobj(ptr noundef %0, i32 noundef 70, i64 noundef %6) #2
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.thread, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = load i8, ptr %9, align 8, !tbaa !5
  %11 = icmp eq i8 %10, 70
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %7, i64 24
  store ptr %1, ptr %13, align 8, !tbaa !10
  %14 = trunc i32 %2 to i8
  %15 = getelementptr inbounds i8, ptr %7, i64 10
  store i8 %14, ptr %15, align 2, !tbaa !12
  %.not21 = icmp eq i32 %2, 0
  br i1 %.not21, label %.thread, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 184
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %7, ptr %18, align 8, !tbaa !23
  %19 = load ptr, ptr %17, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  store i32 70, ptr %20, align 8, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %19, i64 16
  store ptr %21, ptr %17, align 8, !tbaa !13
  tail call void @init_upvals(ptr noundef %0, ptr noundef nonnull %7)
  %22 = load ptr, ptr %17, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %22, i64 -16
  store ptr %23, ptr %17, align 8, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %8, %3, %12, %16
  %24 = phi ptr [ %7, %12 ], [ %7, %16 ], [ null, %3 ], [ null, %8 ]
  ret ptr %24
}

; Function Attrs: nounwind uwtable
declare hidden void @init_upvals(ptr noundef, ptr noundef) local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass