; 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.global_State = type { %struct.stringtable, ptr, ptr, i8, i8, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.Mbuffer, i64, i64, i64, i64, i32, i32, ptr, %struct.lua_TValue, ptr, %struct.UpVal, [9 x ptr], [17 x ptr] }
%struct.stringtable = type { ptr, i32, i32 }
%struct.Mbuffer = type { ptr, i64, i64 }
%struct.UpVal = type { ptr, i8, i8, ptr, %union.anon }
%union.anon = type { %struct.lua_TValue }

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

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

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

; Function Attrs: nounwind uwtable
define hidden void @luaD_call(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.lua_State, ptr %7, i32 0, i32 15
  %9 = load i16, ptr %8, align 8, !tbaa !11
  %10 = add i16 %9, 1
  store i16 %10, ptr %8, align 8, !tbaa !11
  %11 = zext i16 %10 to i32
  %12 = icmp sge i32 %11, 200
  br i1 %12, label %13, label %31

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

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  call void (ptr, ptr, ...) @luaG_runerror(ptr noundef %20, ptr noundef @.str.2)
  br label %30

21:                                               ; preds = %13
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_State, ptr %22, i32 0, i32 15
  %24 = load i16, ptr %23, align 8, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = icmp sge i32 %25, 225
  br i1 %26, label %27, label %29

27:                                               ; preds = %21
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  call void @luaD_throw(ptr noundef %28, i32 noundef 5)
  br label %29

29:                                               ; preds = %27, %21
  br label %30

30:                                               ; preds = %29, %19
  br label %31

31:                                               ; preds = %30, %3
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = call i32 @luaD_precall(ptr noundef %32, ptr noundef %33, i32 noundef %34)
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @luaV_execute(ptr noundef %38, i32 noundef 1)
  br label %39

39:                                               ; preds = %37, %31
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.lua_State, ptr %40, i32 0, i32 15
  %42 = load i16, ptr %41, align 8, !tbaa !11
  %43 = add i16 %42, -1
  store i16 %43, ptr %41, align 8, !tbaa !11
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.lua_State, ptr %44, i32 0, i32 6
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = getelementptr inbounds %struct.global_State, ptr %46, i32 0, i32 14
  %48 = load i64, ptr %47, align 8, !tbaa !17
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.lua_State, ptr %49, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = getelementptr inbounds %struct.global_State, ptr %51, i32 0, i32 13
  %53 = load i64, ptr %52, align 8, !tbaa !22
  %54 = icmp uge i64 %48, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %39
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @luaC_step(ptr noundef %56)
  br label %57

57:                                               ; preds = %55, %39
  ret void
}

declare hidden void @luaG_runerror(ptr noundef, ptr noundef, ...) #1

declare hidden void @luaV_execute(ptr noundef, i32 noundef) #1

declare hidden void @luaC_step(ptr noundef) #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" }

!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, !13, i64 96}
!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 32}
!17 = !{!18, !15, i64 120}
!18 = !{!"global_State", !19, i64 0, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !10, i64 36, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !20, i64 88, !15, i64 112, !15, i64 120, !15, i64 128, !15, i64 136, !10, i64 144, !10, i64 148, !6, i64 152, !14, i64 160, !6, i64 176, !21, i64 184, !7, i64 224, !7, i64 296}
!19 = !{!"stringtable", !6, i64 0, !10, i64 8, !10, i64 12}
!20 = !{!"Mbuffer", !6, i64 0, !15, i64 8, !15, i64 16}
!21 = !{!"UpVal", !6, i64 0, !7, i64 8, !7, i64 9, !6, i64 16, !7, i64 24}
!22 = !{!18, !15, i64 112}


; 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 [17 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define hidden void @luaD_call(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load i16, ptr %4, align 8, !tbaa !5
  %6 = add i16 %5, 1
  store i16 %6, ptr %4, align 8, !tbaa !5
  %7 = icmp ugt i16 %6, 199
  br i1 %7, label %8, label %14

8:                                                ; preds = %3
  %9 = icmp eq i16 %6, 200
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  tail call void (ptr, ptr, ...) @luaG_runerror(ptr noundef nonnull %0, ptr noundef nonnull @.str.2) #2
  br label %14

11:                                               ; preds = %8
  %12 = icmp ugt i16 %6, 224
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  tail call void @luaD_throw(ptr noundef nonnull %0, i32 noundef 5)
  br label %14

14:                                               ; preds = %10, %13, %11, %3
  %15 = tail call i32 @luaD_precall(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %2)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  tail call void @luaV_execute(ptr noundef nonnull %0, i32 noundef 1) #2
  br label %18

18:                                               ; preds = %17, %14
  %19 = load i16, ptr %4, align 8, !tbaa !5
  %20 = add i16 %19, -1
  store i16 %20, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %22, i64 120
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %22, i64 112
  %26 = load i64, ptr %25, align 8, !tbaa !20
  %.not = icmp ult i64 %24, %26
  br i1 %.not, label %28, label %27

27:                                               ; preds = %18
  tail call void @luaC_step(ptr noundef nonnull %0) #2
  br label %28

28:                                               ; preds = %27, %18
  ret void
}

declare hidden void @luaG_runerror(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

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

declare hidden void @luaC_step(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 = { 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, !11, i64 96}
!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 32}
!15 = !{!16, !13, i64 120}
!16 = !{!"global_State", !17, i64 0, !7, i64 16, !7, i64 24, !8, i64 32, !8, i64 33, !10, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !18, i64 88, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !10, i64 144, !10, i64 148, !7, i64 152, !12, i64 160, !7, i64 176, !19, i64 184, !8, i64 224, !8, i64 296}
!17 = !{!"stringtable", !7, i64 0, !10, i64 8, !10, i64 12}
!18 = !{!"Mbuffer", !7, i64 0, !13, i64 8, !13, i64 16}
!19 = !{!"UpVal", !7, i64 0, !8, i64 8, !8, i64 9, !7, i64 16, !8, i64 24}
!20 = !{!16, !13, i64 112}


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