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

; 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.lua_Debug = type { i32, ptr, ptr, ptr, ptr, i32, i32, i32, i8, i8, i8, i8, [60 x i8], ptr }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @luaL_traceback(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.lua_Debug, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 128, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 @lua_gettop(ptr noundef %13)
  store i32 %14, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i32 @countlevels(ptr noundef %15)
  store i32 %16, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = icmp sgt i32 %17, 22
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i32 12, i32 0
  store i32 %20, ptr %12, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call ptr (ptr, ptr, ...) @lua_pushfstring(ptr noundef %24, ptr noundef @.str, ptr noundef %25)
  br label %27

27:                                               ; preds = %23, %4
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call ptr @lua_pushlstring(ptr noundef %28, ptr noundef @.str.1, i64 noundef 16)
  br label %30

30:                                               ; preds = %76, %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = call i32 @lua_getstack(ptr noundef %31, i32 noundef %32, ptr noundef %9)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %77

36:                                               ; preds = %30
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %45

40:                                               ; preds = %36
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call ptr @lua_pushlstring(ptr noundef %41, ptr noundef @.str.2, i64 noundef 5)
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sub nsw i32 %43, 10
  store i32 %44, ptr %8, align 4, !tbaa !9
  br label %76

45:                                               ; preds = %36
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = call i32 @lua_getinfo(ptr noundef %46, ptr noundef @.str.3, ptr noundef %9)
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.lua_Debug, ptr %9, i32 0, i32 12
  %50 = getelementptr inbounds [60 x i8], ptr %49, i64 0, i64 0
  %51 = call ptr (ptr, ptr, ...) @lua_pushfstring(ptr noundef %48, ptr noundef @.str.4, ptr noundef %50)
  %52 = getelementptr inbounds %struct.lua_Debug, ptr %9, i32 0, i32 5
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %60

55:                                               ; preds = %45
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lua_Debug, ptr %9, i32 0, i32 5
  %58 = load i32, ptr %57, align 8, !tbaa !11
  %59 = call ptr (ptr, ptr, ...) @lua_pushfstring(ptr noundef %56, ptr noundef @.str.5, i32 noundef %58)
  br label %60

60:                                               ; preds = %55, %45
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call ptr @lua_pushlstring(ptr noundef %61, ptr noundef @.str.6, i64 noundef 4)
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  call void @pushfuncname(ptr noundef %63, ptr noundef %9)
  %64 = getelementptr inbounds %struct.lua_Debug, ptr %9, i32 0, i32 11
  %65 = load i8, ptr %64, align 1, !tbaa !13
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %60
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = call ptr @lua_pushlstring(ptr noundef %68, ptr noundef @.str.7, i64 noundef 20)
  br label %70

70:                                               ; preds = %67, %60
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = call i32 @lua_gettop(ptr noundef %72)
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = sub nsw i32 %73, %74
  call void @lua_concat(ptr noundef %71, i32 noundef %75)
  br label %76

76:                                               ; preds = %70, %40
  br label %30, !llvm.loop !14

77:                                               ; preds = %30
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = call i32 @lua_gettop(ptr noundef %79)
  %81 = load i32, ptr %10, align 4, !tbaa !9
  %82 = sub nsw i32 %80, %81
  call void @lua_concat(ptr noundef %78, i32 noundef %82)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr %9) #3
  ret void
}

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

declare i32 @lua_gettop(ptr noundef) #2

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

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

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

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

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

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

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

; 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 = { "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, !10, i64 40}
!12 = !{!"lua_Debug", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !7, i64 52, !7, i64 53, !7, i64 54, !7, i64 55, !7, i64 56, !6, i64 120}
!13 = !{!12, !7, i64 55}
!14 = distinct !{!14, !15}
!15 = !{!"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.lua_Debug = type { i32, ptr, ptr, ptr, ptr, i32, i32, i32, i8, i8, i8, i8, [60 x i8], ptr }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @luaL_traceback(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.lua_Debug, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #3
  %6 = tail call i32 @lua_gettop(ptr noundef %0) #3
  %7 = tail call i32 @countlevels(ptr noundef %1)
  %8 = icmp sgt i32 %7, 22
  %9 = select i1 %8, i32 12, i32 0
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %12, label %10

10:                                               ; preds = %4
  %11 = tail call ptr (ptr, ptr, ...) @lua_pushfstring(ptr noundef %0, ptr noundef nonnull @.str, ptr noundef nonnull %2) #3
  br label %12

12:                                               ; preds = %10, %4
  %13 = tail call ptr @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.1, i64 noundef 16) #3
  %14 = call i32 @lua_getstack(ptr noundef %1, i32 noundef %3, ptr noundef nonnull %5) #3
  %.not2729 = icmp eq i32 %14, 0
  br i1 %.not2729, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %15 = getelementptr inbounds i8, ptr %5, i64 56
  %16 = getelementptr inbounds i8, ptr %5, i64 40
  %17 = getelementptr inbounds i8, ptr %5, i64 55
  %18 = add nsw i32 %7, -10
  br label %19

19:                                               ; preds = %.lr.ph, %39
  %.in = phi i32 [ %3, %.lr.ph ], [ %.1, %39 ]
  %20 = add nsw i32 %.in, 1
  %21 = icmp eq i32 %20, %9
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  %23 = call ptr @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.2, i64 noundef 5) #3
  br label %39

24:                                               ; preds = %19
  %25 = call i32 @lua_getinfo(ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef nonnull %5) #3
  %26 = call ptr (ptr, ptr, ...) @lua_pushfstring(ptr noundef %0, ptr noundef nonnull @.str.4, ptr noundef nonnull %15) #3
  %27 = load i32, ptr %16, align 8, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = call ptr (ptr, ptr, ...) @lua_pushfstring(ptr noundef %0, ptr noundef nonnull @.str.5, i32 noundef %27) #3
  br label %31

31:                                               ; preds = %29, %24
  %32 = call ptr @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.6, i64 noundef 4) #3
  call void @pushfuncname(ptr noundef %0, ptr noundef nonnull %5)
  %33 = load i8, ptr %17, align 1, !tbaa !11
  %.not28 = icmp eq i8 %33, 0
  br i1 %.not28, label %36, label %34

34:                                               ; preds = %31
  %35 = call ptr @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.7, i64 noundef 20) #3
  br label %36

36:                                               ; preds = %34, %31
  %37 = call i32 @lua_gettop(ptr noundef %0) #3
  %38 = sub nsw i32 %37, %6
  call void @lua_concat(ptr noundef %0, i32 noundef %38) #3
  br label %39

39:                                               ; preds = %36, %22
  %.1 = phi i32 [ %18, %22 ], [ %20, %36 ]
  %40 = call i32 @lua_getstack(ptr noundef %1, i32 noundef %.1, ptr noundef nonnull %5) #3
  %.not27 = icmp eq i32 %40, 0
  br i1 %.not27, label %._crit_edge, label %19, !llvm.loop !12

._crit_edge:                                      ; preds = %39, %12
  %41 = call i32 @lua_gettop(ptr noundef %0) #3
  %42 = sub nsw i32 %41, %6
  call void @lua_concat(ptr noundef %0, i32 noundef %42) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #3
  ret void
}

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

declare i32 @lua_gettop(ptr noundef) local_unnamed_addr #2

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

declare ptr @lua_pushfstring(ptr noundef, ptr noundef, ...) local_unnamed_addr #2

declare ptr @lua_pushlstring(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @lua_getstack(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @lua_getinfo(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @lua_concat(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress 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 = { 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, !7, i64 40}
!6 = !{!"lua_Debug", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 44, !7, i64 48, !8, i64 52, !8, i64 53, !8, i64 54, !8, i64 55, !8, i64 56, !10, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !8, i64 55}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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