; LLVM IR from gabekz/GoodsackEngine :: goodsack/gsk/gsk/wrapper/lua (lua_debug)

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

@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [28 x i8], align 1

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

declare ptr @lua_tolstring(ptr noundef, i32 noundef, ptr noundef) #1

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

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

14:                                               ; preds = %57, %2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp sge i32 %15, 1
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %60

18:                                               ; preds = %14
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = call i32 @lua_type(ptr noundef %21, i32 noundef %22)
  %24 = call ptr @lua_typename(ptr noundef %20, i32 noundef %23)
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %19, ptr noundef %24)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = call i32 @lua_type(ptr noundef %26, i32 noundef %27)
  switch i32 %28, label %49 [
    i32 3, label %29
    i32 4, label %34
    i32 1, label %39
    i32 0, label %47
  ]

29:                                               ; preds = %18
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = call double @lua_tonumberx(ptr noundef %30, i32 noundef %31, ptr noundef null)
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, double noundef %32)
  br label %54

34:                                               ; preds = %18
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = call ptr @lua_tolstring(ptr noundef %35, i32 noundef %36, ptr noundef null)
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %37)
  br label %54

39:                                               ; preds = %18
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = call i32 @lua_toboolean(ptr noundef %40, i32 noundef %41)
  %43 = icmp ne i32 %42, 0
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, ptr @.str.7, ptr @.str.8
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %45)
  br label %54

47:                                               ; preds = %18
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef @.str.9)
  br label %54

49:                                               ; preds = %18
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = call ptr @lua_topointer(ptr noundef %50, i32 noundef %51)
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef %52)
  br label %54

54:                                               ; preds = %49, %47, %39, %34, %29
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %6, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %54
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !11

60:                                               ; preds = %17
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

declare i32 @printf(ptr noundef, ...) #1

declare i32 @lua_gettop(ptr noundef) #1

declare ptr @lua_typename(ptr noundef, i32 noundef) #1

declare i32 @lua_type(ptr noundef, i32 noundef) #1

declare double @lua_tonumberx(ptr noundef, i32 noundef, ptr noundef) #1

declare i32 @lua_toboolean(ptr noundef, i32 noundef) #1

declare ptr @lua_topointer(ptr noundef, i32 noundef) #1

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 = distinct !{!11, !12}
!12 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [28 x i8], align 1

declare ptr @lua_tolstring(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @dumpstack(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %1)
  %5 = tail call i32 @lua_gettop(ptr noundef %0) #3
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %28, %2
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  ret void

.lr.ph:                                           ; preds = %2, %28
  %.021 = phi i32 [ %30, %28 ], [ %5, %2 ]
  %.01920 = phi i32 [ %29, %28 ], [ -1, %2 ]
  %9 = tail call i32 @lua_type(ptr noundef %0, i32 noundef %.021) #3
  %10 = tail call ptr @lua_typename(ptr noundef %0, i32 noundef %9) #3
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.01920, ptr noundef %10)
  %12 = tail call i32 @lua_type(ptr noundef %0, i32 noundef %.021) #3
  switch i32 %12, label %25 [
    i32 3, label %13
    i32 4, label %16
    i32 1, label %19
    i32 0, label %23
  ]

13:                                               ; preds = %.lr.ph
  %14 = tail call double @lua_tonumberx(ptr noundef %0, i32 noundef %.021, ptr noundef null) #3
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, double noundef %14)
  br label %28

16:                                               ; preds = %.lr.ph
  %17 = tail call ptr @lua_tolstring(ptr noundef %0, i32 noundef %.021, ptr noundef null) #3
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %17)
  br label %28

19:                                               ; preds = %.lr.ph
  %20 = tail call i32 @lua_toboolean(ptr noundef %0, i32 noundef %.021) #3
  %.not = icmp eq i32 %20, 0
  %21 = select i1 %.not, ptr @.str.8, ptr @.str.7
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %21)
  br label %28

23:                                               ; preds = %.lr.ph
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull @.str.9)
  br label %28

25:                                               ; preds = %.lr.ph
  %26 = tail call ptr @lua_topointer(ptr noundef %0, i32 noundef %.021) #3
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, ptr noundef %26)
  br label %28

28:                                               ; preds = %25, %23, %19, %16, %13
  %29 = add nsw i32 %.01920, -1
  %30 = add nsw i32 %.021, -1
  %31 = icmp sgt i32 %.021, 1
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !5
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare i32 @lua_gettop(ptr noundef) local_unnamed_addr #0

declare ptr @lua_typename(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @lua_type(ptr noundef, i32 noundef) local_unnamed_addr #0

declare double @lua_tonumberx(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare i32 @lua_toboolean(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @lua_topointer(ptr noundef, i32 noundef) local_unnamed_addr #0

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 = { nofree nounwind "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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