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

; 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.bnfuncinfo = type { ptr, ptr }

@be_nfunc_open.members = external hidden constant [13 x %struct.bnfuncinfo], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @be_nfunc_open(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @be_top(ptr noundef %9)
  store i32 %10, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp sge i32 %11, 1
  br i1 %12, label %13, label %19

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call zeroext i1 @be_isstring(ptr noundef %14, i32 noundef 1)
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call ptr @be_tostring(ptr noundef %17, i32 noundef 1)
  br label %20

19:                                               ; preds = %13, %1
  br label %20

20:                                               ; preds = %19, %16
  %21 = phi ptr [ %18, %16 ], [ null, %19 ]
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = icmp sge i32 %22, 2
  br i1 %23, label %24, label %30

24:                                               ; preds = %20
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call zeroext i1 @be_isstring(ptr noundef %25, i32 noundef 2)
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call ptr @be_tostring(ptr noundef %28, i32 noundef 2)
  br label %31

30:                                               ; preds = %24, %20
  br label %31

31:                                               ; preds = %30, %27
  %32 = phi ptr [ %29, %27 ], [ @.str.12, %30 ]
  store ptr %32, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %56

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call ptr @be_fopen(ptr noundef %36, ptr noundef %37)
  store ptr %38, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %46

41:                                               ; preds = %35
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call ptr (ptr, ptr, ...) @be_pushfstring(ptr noundef %43, ptr noundef @.str.14, ptr noundef %44)
  call void @be_raise(ptr noundef %42, ptr noundef @.str.13, ptr noundef %45) #5
  unreachable

46:                                               ; preds = %35
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  call void @be_pushclass(ptr noundef %47, ptr noundef @.str.15, ptr noundef @be_nfunc_open.members)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  call void @be_call(ptr noundef %48, i32 noundef 0)
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  call void @be_pushcomptr(ptr noundef %49, ptr noundef %50)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = call zeroext i1 @be_setmember(ptr noundef %51, i32 noundef -2, ptr noundef @.str)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  call void @be_pop(ptr noundef %53, i32 noundef 1)
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call i32 @be_returnvalue(ptr noundef %54)
  store i32 %55, ptr %2, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %59

56:                                               ; preds = %31
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = call i32 @be_returnnilvalue(ptr noundef %57)
  store i32 %58, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %59

59:                                               ; preds = %56, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %60 = load i32, ptr %2, align 4
  ret i32 %60
}

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

declare i32 @be_top(ptr noundef) #2

declare zeroext i1 @be_isstring(ptr noundef, i32 noundef) #2

declare ptr @be_tostring(ptr noundef, i32 noundef) #2

declare ptr @be_fopen(ptr noundef, ptr noundef) #2

; Function Attrs: noreturn
declare void @be_raise(ptr noundef, ptr noundef, ptr noundef) #3

declare ptr @be_pushfstring(ptr noundef, ptr noundef, ...) #2

declare void @be_pushclass(ptr noundef, ptr noundef, ptr noundef) #2

declare void @be_call(ptr noundef, i32 noundef) #2

declare void @be_pushcomptr(ptr noundef, ptr noundef) #2

declare zeroext i1 @be_setmember(ptr noundef, i32 noundef, ptr noundef) #2

declare void @be_pop(ptr noundef, i32 noundef) #2

declare i32 @be_returnvalue(ptr noundef) #2

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

declare i32 @be_returnnilvalue(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn "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 #4 = { nounwind }
attributes #5 = { noreturn }

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


; 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.bnfuncinfo = type { ptr, ptr }

@be_nfunc_open.members = external hidden constant [13 x %struct.bnfuncinfo], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @be_nfunc_open(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @be_top(ptr noundef %0) #3
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %4, label %.thread24

4:                                                ; preds = %1
  %5 = tail call zeroext i1 @be_isstring(ptr noundef %0, i32 noundef 1) #3
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = tail call ptr @be_tostring(ptr noundef %0, i32 noundef 1) #3
  br label %8

8:                                                ; preds = %4, %6
  %9 = phi ptr [ %7, %6 ], [ null, %4 ]
  %.not26 = icmp eq i32 %2, 1
  br i1 %.not26, label %14, label %10

10:                                               ; preds = %8
  %11 = tail call zeroext i1 @be_isstring(ptr noundef %0, i32 noundef 2) #3
  br i1 %11, label %12, label %14

12:                                               ; preds = %10
  %13 = tail call ptr @be_tostring(ptr noundef %0, i32 noundef 2) #3
  br label %14

14:                                               ; preds = %8, %10, %12
  %15 = phi ptr [ %13, %12 ], [ @.str.12, %10 ], [ @.str.12, %8 ]
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.thread24, label %16

16:                                               ; preds = %14
  %17 = tail call ptr @be_fopen(ptr noundef nonnull %9, ptr noundef %15) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = tail call ptr (ptr, ptr, ...) @be_pushfstring(ptr noundef %0, ptr noundef nonnull @.str.14, ptr noundef nonnull %9) #3
  tail call void @be_raise(ptr noundef %0, ptr noundef nonnull @.str.13, ptr noundef %20) #4
  unreachable

21:                                               ; preds = %16
  tail call void @be_pushclass(ptr noundef %0, ptr noundef nonnull @.str.15, ptr noundef nonnull @be_nfunc_open.members) #3
  tail call void @be_call(ptr noundef %0, i32 noundef 0) #3
  tail call void @be_pushcomptr(ptr noundef %0, ptr noundef nonnull %17) #3
  %22 = tail call zeroext i1 @be_setmember(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str) #3
  tail call void @be_pop(ptr noundef %0, i32 noundef 1) #3
  %23 = tail call i32 @be_returnvalue(ptr noundef %0) #3
  br label %25

.thread24:                                        ; preds = %1, %14
  %24 = tail call i32 @be_returnnilvalue(ptr noundef %0) #3
  br label %25

25:                                               ; preds = %.thread24, %21
  %.0 = phi i32 [ %23, %21 ], [ %24, %.thread24 ]
  ret i32 %.0
}

declare i32 @be_top(ptr noundef) local_unnamed_addr #1

declare zeroext i1 @be_isstring(ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @be_tostring(ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @be_fopen(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @be_raise(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @be_pushfstring(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare void @be_pushclass(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @be_call(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @be_pushcomptr(ptr noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i1 @be_setmember(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @be_pop(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @be_returnvalue(ptr noundef) local_unnamed_addr #1

declare i32 @be_returnnilvalue(ptr noundef) local_unnamed_addr #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 = { "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 = { noreturn "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 }
attributes #4 = { noreturn 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass