; LLVM IR from ejoy/ejoy2d :: lua (lcode)

; 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.expdesc = type { i32, %union.anon.1, i32, i32 }
%union.anon.1 = type { double }
%struct.FuncState = type { ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i16, i8, i8, i8 }

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

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

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

; Function Attrs: nounwind uwtable
define hidden i32 @luaK_exp2RK(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  call void @luaK_exp2val(ptr noundef %6, ptr noundef %7)
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.expdesc, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  switch i32 %10, label %75 [
    i32 2, label %11
    i32 3, label %11
    i32 1, label %11
    i32 6, label %43
    i32 5, label %53
    i32 4, label %63
  ]

11:                                               ; preds = %2, %2, %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.FuncState, ptr %12, i32 0, i32 7
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = icmp sle i32 %14, 255
  br i1 %15, label %16, label %42

16:                                               ; preds = %11
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.expdesc, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @nilK(ptr noundef %22)
  br label %32

24:                                               ; preds = %16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.expdesc, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = icmp eq i32 %28, 2
  %30 = zext i1 %29 to i32
  %31 = call i32 @boolK(ptr noundef %25, i32 noundef %30)
  br label %32

32:                                               ; preds = %24, %21
  %33 = phi i32 [ %23, %21 ], [ %31, %24 ]
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.expdesc, ptr %34, i32 0, i32 1
  store i32 %33, ptr %35, align 8, !tbaa !15
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.expdesc, ptr %36, i32 0, i32 0
  store i32 4, ptr %37, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.expdesc, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = or i32 %40, 256
  store i32 %41, ptr %3, align 4
  br label %80

42:                                               ; preds = %11
  br label %76

43:                                               ; preds = %2
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.expdesc, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = call i32 @luaK_intK(ptr noundef %44, i64 noundef %47)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.expdesc, ptr %49, i32 0, i32 1
  store i32 %48, ptr %50, align 8, !tbaa !15
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.expdesc, ptr %51, i32 0, i32 0
  store i32 4, ptr %52, align 8, !tbaa !9
  br label %64

53:                                               ; preds = %2
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.expdesc, ptr %55, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !15
  %58 = call i32 @luaK_numberK(ptr noundef %54, double noundef %57)
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.expdesc, ptr %59, i32 0, i32 1
  store i32 %58, ptr %60, align 8, !tbaa !15
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.expdesc, ptr %61, i32 0, i32 0
  store i32 4, ptr %62, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %53, %2
  br label %64

64:                                               ; preds = %63, %43
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.expdesc, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !15
  %68 = icmp sle i32 %67, 255
  br i1 %68, label %69, label %74

69:                                               ; preds = %64
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.expdesc, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 8, !tbaa !15
  %73 = or i32 %72, 256
  store i32 %73, ptr %3, align 4
  br label %80

74:                                               ; preds = %64
  br label %76

75:                                               ; preds = %2
  br label %76

76:                                               ; preds = %75, %74, %42
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = call i32 @luaK_exp2anyreg(ptr noundef %77, ptr noundef %78)
  store i32 %79, ptr %3, align 4
  br label %80

80:                                               ; preds = %76, %69, %32
  %81 = load i32, ptr %3, align 4
  ret i32 %81
}

; Function Attrs: nounwind uwtable
declare hidden i32 @nilK(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @luaK_numberK(ptr noundef, double noundef) #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"expdesc", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 44}
!13 = !{!"FuncState", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !14, i64 56, !7, i64 58, !7, i64 59, !7, i64 60}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !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"

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

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

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

; Function Attrs: nounwind uwtable
define hidden i32 @luaK_exp2RK(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  tail call void @luaK_exp2val(ptr noundef %0, ptr noundef %1)
  %3 = load i32, ptr %1, align 8, !tbaa !5
  switch i32 %3, label %33 [
    i32 2, label %4
    i32 3, label %4
    i32 1, label %4
    i32 6, label %20
    i32 5, label %24
    i32 4, label %._crit_edge
  ]

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 8
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !10
  br label %28

4:                                                ; preds = %2, %2, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 44
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = icmp slt i32 %6, 256
  br i1 %7, label %8, label %33

8:                                                ; preds = %4
  %9 = icmp eq i32 %3, 1
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  %11 = tail call i32 @nilK(ptr noundef nonnull %0)
  br label %16

12:                                               ; preds = %8
  %13 = icmp eq i32 %3, 2
  %14 = zext i1 %13 to i32
  %15 = tail call i32 @boolK(ptr noundef nonnull %0, i32 noundef %14)
  br label %16

16:                                               ; preds = %12, %10
  %17 = phi i32 [ %11, %10 ], [ %15, %12 ]
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %17, ptr %18, align 8, !tbaa !10
  store i32 4, ptr %1, align 8, !tbaa !5
  %19 = or i32 %17, 256
  br label %35

20:                                               ; preds = %2
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !10
  %23 = tail call i32 @luaK_intK(ptr noundef %0, i64 noundef %22)
  store i32 %23, ptr %21, align 8, !tbaa !10
  store i32 4, ptr %1, align 8, !tbaa !5
  br label %28

24:                                               ; preds = %2
  %25 = getelementptr inbounds i8, ptr %1, i64 8
  %26 = load double, ptr %25, align 8, !tbaa !10
  %27 = tail call i32 @luaK_numberK(ptr noundef %0, double noundef %26)
  store i32 %27, ptr %25, align 8, !tbaa !10
  store i32 4, ptr %1, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge, %24, %20
  %29 = phi i32 [ %.pre, %._crit_edge ], [ %27, %24 ], [ %23, %20 ]
  %30 = icmp slt i32 %29, 256
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = or i32 %29, 256
  br label %35

33:                                               ; preds = %2, %28, %4
  %34 = tail call i32 @luaK_exp2anyreg(ptr noundef %0, ptr noundef nonnull %1)
  br label %35

35:                                               ; preds = %33, %31, %16
  %.0 = phi i32 [ %34, %33 ], [ %32, %31 ], [ %19, %16 ]
  ret i32 %.0
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @luaK_numberK(ptr noundef, double 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 0}
!6 = !{!"expdesc", !7, i64 0, !8, i64 8, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !7, i64 44}
!12 = !{!"FuncState", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !14, i64 56, !8, i64 58, !8, i64 59, !8, i64 60}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"short", !8, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass