; LLVM IR from ramsdell/lineqpp :: lua (ldo)

; 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_State = type { ptr, i8, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i16, i16, i8, i8, i32, i32, ptr, %struct.lua_TValue, %struct.lua_TValue, ptr, ptr, ptr, i64 }
%struct.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }
%struct.CallInfo = type { ptr, ptr, ptr, ptr, i32, i32 }

@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lua_resume(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.lua_State, ptr %8, i32 0, i32 3
  %10 = load i8, ptr %9, align 2, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = icmp ne i32 %11, 1
  br i1 %12, label %13, label %30

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.lua_State, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 2, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %27, label %19

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.lua_State, ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lua_State, ptr %23, i32 0, i32 12
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = icmp ne ptr %22, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %19, %13
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call i32 @resume_error(ptr noundef %28, ptr noundef @.str.3)
  store i32 %29, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

30:                                               ; preds = %19, %2
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.lua_State, ptr %31, i32 0, i32 15
  %33 = load i16, ptr %32, align 8, !tbaa !18
  %34 = zext i16 %33 to i32
  %35 = icmp sge i32 %34, 200
  br i1 %35, label %36, label %39

36:                                               ; preds = %30
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call i32 @resume_error(ptr noundef %37, ptr noundef @.str.2)
  store i32 %38, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

39:                                               ; preds = %30
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.lua_State, ptr %41, i32 0, i32 15
  %43 = load i16, ptr %42, align 8, !tbaa !18
  %44 = add i16 %43, 1
  store i16 %44, ptr %42, align 8, !tbaa !18
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.lua_State, ptr %45, i32 0, i32 16
  store i16 %44, ptr %46, align 2, !tbaa !19
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.lua_State, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = sub i64 0, %52
  %54 = getelementptr inbounds %struct.lua_TValue, ptr %50, i64 %53
  %55 = call i32 @luaD_rawrunprotected(ptr noundef %47, ptr noundef @resume, ptr noundef %54)
  store i32 %55, ptr %6, align 4, !tbaa !9
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %75

58:                                               ; preds = %39
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.lua_State, ptr %61, i32 0, i32 3
  store i8 %60, ptr %62, align 2, !tbaa !11
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lua_State, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !20
  call void @luaD_seterrorobj(ptr noundef %63, i32 noundef %64, ptr noundef %67)
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.lua_State, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %69, align 8, !tbaa !20
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.lua_State, ptr %71, i32 0, i32 7
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = getelementptr inbounds %struct.CallInfo, ptr %73, i32 0, i32 2
  store ptr %70, ptr %74, align 8, !tbaa !21
  br label %80

75:                                               ; preds = %39
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.lua_State, ptr %76, i32 0, i32 3
  %78 = load i8, ptr %77, align 2, !tbaa !11
  %79 = zext i8 %78 to i32
  store i32 %79, ptr %6, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %75, %58
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.lua_State, ptr %81, i32 0, i32 15
  %83 = load i16, ptr %82, align 8, !tbaa !18
  %84 = add i16 %83, -1
  store i16 %84, ptr %82, align 8, !tbaa !18
  %85 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %85, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

86:                                               ; preds = %80, %36, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

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

; Function Attrs: nounwind uwtable
declare hidden void @resume(ptr noundef, ptr 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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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, !7, i64 10}
!12 = !{!"lua_State", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !13, i64 96, !13, i64 98, !7, i64 100, !7, i64 101, !10, i64 104, !10, i64 108, !6, i64 112, !14, i64 120, !14, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !15, i64 176}
!13 = !{!"short", !7, i64 0}
!14 = !{!"lua_TValue", !7, i64 0, !10, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 40}
!17 = !{!12, !6, i64 80}
!18 = !{!12, !13, i64 96}
!19 = !{!12, !13, i64 98}
!20 = !{!12, !6, i64 16}
!21 = !{!22, !6, i64 16}
!22 = !{!"CallInfo", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}


; 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_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }

@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lua_resume(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 10
  %4 = load i8, ptr %3, align 2, !tbaa !5
  switch i8 %4, label %10 [
    i8 1, label %12
    i8 0, label %5
  ]

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %.not28 = icmp eq ptr %7, %9
  br i1 %.not28, label %12, label %10

10:                                               ; preds = %2, %5
  %11 = tail call i32 @resume_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.3)
  br label %40

12:                                               ; preds = %2, %5
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = load i16, ptr %13, align 8, !tbaa !16
  %15 = icmp ugt i16 %14, 199
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = tail call i32 @resume_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.2)
  br label %40

18:                                               ; preds = %12
  %19 = add nuw nsw i16 %14, 1
  store i16 %19, ptr %13, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %0, i64 98
  store i16 %19, ptr %20, align 2, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = sext i32 %1 to i64
  %24 = sub nsw i64 0, %23
  %25 = getelementptr inbounds %struct.lua_TValue, ptr %22, i64 %24
  %26 = tail call i32 @luaD_rawrunprotected(ptr noundef nonnull %0, ptr noundef nonnull @resume, ptr noundef %25)
  %.not29 = icmp eq i32 %26, 0
  br i1 %.not29, label %34, label %27

27:                                               ; preds = %18
  %28 = trunc i32 %26 to i8
  store i8 %28, ptr %3, align 2, !tbaa !5
  %29 = load ptr, ptr %21, align 8, !tbaa !18
  tail call void @luaD_seterrorobj(ptr noundef nonnull %0, i32 noundef %26, ptr noundef %29)
  %30 = load ptr, ptr %21, align 8, !tbaa !18
  %31 = getelementptr inbounds i8, ptr %0, i64 40
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store ptr %30, ptr %33, align 8, !tbaa !19
  br label %37

34:                                               ; preds = %18
  %35 = load i8, ptr %3, align 2, !tbaa !5
  %36 = zext i8 %35 to i32
  br label %37

37:                                               ; preds = %34, %27
  %.0 = phi i32 [ %26, %27 ], [ %36, %34 ]
  %38 = load i16, ptr %13, align 8, !tbaa !16
  %39 = add i16 %38, -1
  store i16 %39, ptr %13, align 8, !tbaa !16
  br label %40

40:                                               ; preds = %37, %16, %10
  %.024 = phi i32 [ %11, %10 ], [ %17, %16 ], [ %.0, %37 ]
  ret i32 %.024
}

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

; Function Attrs: nounwind uwtable
declare hidden void @resume(ptr noundef, ptr 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, !8, i64 10}
!6 = !{!"lua_State", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !10, i64 92, !11, i64 96, !11, i64 98, !8, i64 100, !8, i64 101, !10, i64 104, !10, i64 108, !7, i64 112, !12, i64 120, !12, i64 136, !7, i64 152, !7, i64 160, !7, i64 168, !13, i64 176}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"lua_TValue", !8, i64 0, !10, i64 8}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !7, i64 40}
!15 = !{!6, !7, i64 80}
!16 = !{!6, !11, i64 96}
!17 = !{!6, !11, i64 98}
!18 = !{!6, !7, i64 16}
!19 = !{!20, !7, i64 16}
!20 = !{!"CallInfo", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}


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