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

; 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.LoadState = type { ptr, ptr, ptr, ptr }
%struct.lua_State = type { ptr, i8, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.CallInfo, ptr, i64, i32, i32, i32, i16, i16, i8, i8 }
%struct.CallInfo = type { ptr, ptr, ptr, ptr, %union.anon, i64, i16, i8 }
%union.anon = type { %struct.anon.0 }
%struct.anon.0 = type { ptr, i64, i64 }
%struct.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }
%struct.LClosure = type { ptr, i8, i8, i8, ptr, ptr, [1 x ptr] }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define hidden ptr @luaU_undump(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.LoadState, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  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 ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = icmp eq i32 %15, 64
  br i1 %16, label %22, label %17

17:                                               ; preds = %4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 61
  br i1 %21, label %22, label %26

22:                                               ; preds = %17, %4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 1
  %25 = getelementptr inbounds %struct.LoadState, ptr %9, i32 0, i32 3
  store ptr %24, ptr %25, align 8, !tbaa !10
  br label %39

26:                                               ; preds = %17
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = load i8, ptr @.str, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 %29, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %26
  %34 = getelementptr inbounds %struct.LoadState, ptr %9, i32 0, i32 3
  store ptr @.str.1, ptr %34, align 8, !tbaa !10
  br label %38

35:                                               ; preds = %26
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LoadState, ptr %9, i32 0, i32 3
  store ptr %36, ptr %37, align 8, !tbaa !10
  br label %38

38:                                               ; preds = %35, %33
  br label %39

39:                                               ; preds = %38, %22
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.LoadState, ptr %9, i32 0, i32 0
  store ptr %40, ptr %41, align 8, !tbaa !12
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.LoadState, ptr %9, i32 0, i32 1
  store ptr %42, ptr %43, align 8, !tbaa !13
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.LoadState, ptr %9, i32 0, i32 2
  store ptr %44, ptr %45, align 8, !tbaa !14
  call void @checkHeader(ptr noundef %9)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call zeroext i8 @LoadByte(ptr noundef %9)
  %48 = zext i8 %47 to i32
  %49 = call ptr @luaF_newLclosure(ptr noundef %46, i32 noundef %48)
  store ptr %49, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.lua_State, ptr %50, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  store ptr %52, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %53, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.lua_TValue, ptr %55, i32 0, i32 0
  store ptr %54, ptr %56, align 8, !tbaa !9
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.lua_TValue, ptr %57, i32 0, i32 1
  store i32 70, ptr %58, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.lua_State, ptr %59, i32 0, i32 4
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = getelementptr inbounds %struct.lua_TValue, ptr %61, i32 1
  store ptr %62, ptr %60, align 8, !tbaa !15
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.lua_State, ptr %63, i32 0, i32 8
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.lua_State, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = ptrtoint ptr %65 to i64
  %70 = ptrtoint ptr %68 to i64
  %71 = sub i64 %69, %70
  %72 = sdiv exact i64 %71, 16
  %73 = icmp sle i64 %72, 0
  br i1 %73, label %74, label %76

74:                                               ; preds = %39
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  call void @luaD_growstack(ptr noundef %75, i32 noundef 0)
  br label %77

76:                                               ; preds = %39
  br label %77

77:                                               ; preds = %76, %74
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = call ptr @luaF_newproto(ptr noundef %78)
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.LClosure, ptr %80, i32 0, i32 5
  store ptr %79, ptr %81, align 8, !tbaa !24
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.LClosure, ptr %82, i32 0, i32 5
  %84 = load ptr, ptr %83, align 8, !tbaa !24
  call void @LoadFunction(ptr noundef %9, ptr noundef %84, ptr noundef null)
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  ret ptr %85
}

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

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

declare hidden ptr @luaF_newLclosure(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @LoadByte(ptr noundef) #0

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

declare hidden void @luaD_growstack(ptr noundef, i32 noundef) #2

declare hidden ptr @luaF_newproto(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @LoadFunction(ptr noundef, 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 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 24}
!11 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!12 = !{!11, !6, i64 0}
!13 = !{!11, !6, i64 8}
!14 = !{!11, !6, i64 16}
!15 = !{!16, !6, i64 16}
!16 = !{!"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, !6, i64 88, !17, i64 96, !6, i64 168, !18, i64 176, !20, i64 184, !20, i64 188, !20, i64 192, !19, i64 196, !19, i64 198, !7, i64 200, !7, i64 201}
!17 = !{!"CallInfo", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !18, i64 56, !19, i64 64, !7, i64 66}
!18 = !{!"long", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!22, !20, i64 8}
!22 = !{!"lua_TValue", !7, i64 0, !20, i64 8}
!23 = !{!16, !6, i64 48}
!24 = !{!25, !6, i64 24}
!25 = !{!"LClosure", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !6, i64 16, !6, i64 24, !7, i64 32}


; 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.LoadState = type { ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define hidden ptr @luaU_undump(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.LoadState, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  %6 = load i8, ptr %3, align 1, !tbaa !5
  switch i8 %6, label %10 [
    i8 64, label %7
    i8 61, label %7
  ]

7:                                                ; preds = %4, %4
  %8 = getelementptr inbounds i8, ptr %3, i64 1
  %9 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %8, ptr %9, align 8, !tbaa !8
  br label %16

10:                                               ; preds = %4
  %11 = load i8, ptr @.str, align 1, !tbaa !5
  %12 = icmp eq i8 %6, %11
  %13 = getelementptr inbounds i8, ptr %5, i64 24
  br i1 %12, label %14, label %15

14:                                               ; preds = %10
  store ptr @.str.1, ptr %13, align 8, !tbaa !8
  br label %16

15:                                               ; preds = %10
  store ptr %3, ptr %13, align 8, !tbaa !8
  br label %16

16:                                               ; preds = %14, %15, %7
  store ptr %0, ptr %5, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %1, ptr %17, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %2, ptr %18, align 8, !tbaa !13
  call void @checkHeader(ptr noundef nonnull %5)
  %19 = call zeroext i8 @LoadByte(ptr noundef nonnull %5)
  %20 = zext i8 %19 to i32
  %21 = call ptr @luaF_newLclosure(ptr noundef %0, i32 noundef %20) #3
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  store ptr %21, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  store i32 70, ptr %24, align 8, !tbaa !20
  %25 = load ptr, ptr %22, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  store ptr %26, ptr %22, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %0, i64 48
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = ptrtoint ptr %28 to i64
  %30 = ptrtoint ptr %26 to i64
  %31 = sub i64 %29, %30
  %32 = icmp slt i64 %31, 16
  br i1 %32, label %33, label %34

33:                                               ; preds = %16
  call void @luaD_growstack(ptr noundef nonnull %0, i32 noundef 0) #3
  br label %34

34:                                               ; preds = %16, %33
  %35 = call ptr @luaF_newproto(ptr noundef nonnull %0) #3
  %36 = getelementptr inbounds i8, ptr %21, i64 24
  store ptr %35, ptr %36, align 8, !tbaa !23
  call void @LoadFunction(ptr noundef nonnull %5, ptr noundef %35, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret ptr %21
}

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

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

declare hidden ptr @luaF_newLclosure(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @LoadByte(ptr noundef) local_unnamed_addr #0

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

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

declare hidden ptr @luaF_newproto(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @LoadFunction(ptr noundef, ptr noundef, ptr 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" }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 24}
!9 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!9, !10, i64 0}
!12 = !{!9, !10, i64 8}
!13 = !{!9, !10, i64 16}
!14 = !{!15, !10, i64 16}
!15 = !{!"lua_State", !10, i64 0, !6, i64 8, !6, i64 9, !6, i64 10, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !16, i64 96, !10, i64 168, !17, i64 176, !19, i64 184, !19, i64 188, !19, i64 192, !18, i64 196, !18, i64 198, !6, i64 200, !6, i64 201}
!16 = !{!"CallInfo", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !17, i64 56, !18, i64 64, !6, i64 66}
!17 = !{!"long", !6, i64 0}
!18 = !{!"short", !6, i64 0}
!19 = !{!"int", !6, i64 0}
!20 = !{!21, !19, i64 8}
!21 = !{!"lua_TValue", !6, i64 0, !19, i64 8}
!22 = !{!15, !10, i64 48}
!23 = !{!24, !10, i64 24}
!24 = !{!"LClosure", !10, i64 0, !6, i64 8, !6, i64 9, !6, i64 10, !10, i64 16, !10, i64 24, !6, i64 32}


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