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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @lua_rawset(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = call ptr @index2addr(ptr noundef %8, i32 noundef %9)
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lua_TValue, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.lua_State, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = getelementptr inbounds %struct.lua_TValue, ptr %18, i64 -2
  %20 = call ptr @luaH_set(ptr noundef %14, ptr noundef %15, ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_State, ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct.lua_TValue, ptr %24, i64 -1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %21, ptr align 8 %25, i64 16, i1 false), !tbaa.struct !17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Table, ptr %27, i32 0, i32 3
  store i8 0, ptr %28, align 2, !tbaa !18
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.lua_State, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds %struct.lua_TValue, ptr %31, i64 -1
  %33 = getelementptr inbounds %struct.lua_TValue, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !20
  %35 = and i32 %34, 64
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %59

37:                                               ; preds = %2
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Table, ptr %38, i32 0, i32 2
  %40 = load i8, ptr %39, align 1, !tbaa !22
  %41 = zext i8 %40 to i32
  %42 = and i32 %41, 4
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %59

44:                                               ; preds = %37
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.lua_State, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds %struct.lua_TValue, ptr %47, i64 -1
  %49 = getelementptr inbounds %struct.lua_TValue, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.GCObject, ptr %50, i32 0, i32 2
  %52 = load i8, ptr %51, align 1, !tbaa !23
  %53 = zext i8 %52 to i32
  %54 = and i32 %53, 3
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %44
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @luaC_barrierback_(ptr noundef %57, ptr noundef %58)
  br label %59

59:                                               ; preds = %56, %44, %37, %2
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.lua_State, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !12
  %63 = getelementptr inbounds %struct.lua_TValue, ptr %62, i64 -2
  store ptr %63, ptr %61, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare hidden ptr @luaH_set(ptr noundef, ptr noundef, ptr noundef) #3

declare hidden void @luaC_barrierback_(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #4 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"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, !14, i64 96, !6, i64 168, !15, i64 176, !10, i64 184, !10, i64 188, !10, i64 192, !16, i64 196, !16, i64 198, !7, i64 200, !7, i64 201}
!14 = !{!"CallInfo", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !15, i64 56, !16, i64 64, !7, i64 66}
!15 = !{!"long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{i64 0, i64 8, !11, i64 8, i64 4, !9}
!18 = !{!19, !7, i64 10}
!19 = !{!"Table", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!20 = !{!21, !10, i64 8}
!21 = !{!"lua_TValue", !7, i64 0, !10, i64 8}
!22 = !{!19, !7, i64 9}
!23 = !{!24, !7, i64 9}
!24 = !{!"GCObject", !6, i64 0, !7, i64 8, !7, i64 9}


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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @lua_rawset(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @index2addr(ptr noundef %0, i32 noundef %1)
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %6, i64 -32
  %8 = tail call ptr @luaH_set(ptr noundef %0, ptr noundef %4, ptr noundef nonnull %7) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !8
  %10 = getelementptr inbounds i8, ptr %9, i64 -16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(16) %10, i64 16, i1 false), !tbaa.struct !15
  %11 = getelementptr inbounds i8, ptr %4, i64 10
  store i8 0, ptr %11, align 2, !tbaa !17
  %12 = load ptr, ptr %5, align 8, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %12, i64 -16
  %14 = getelementptr inbounds i8, ptr %12, i64 -8
  %15 = load i32, ptr %14, align 8, !tbaa !19
  %16 = and i32 %15, 64
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %27, label %17

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %4, i64 9
  %19 = load i8, ptr %18, align 1, !tbaa !21
  %20 = and i8 %19, 4
  %.not15 = icmp eq i8 %20, 0
  br i1 %.not15, label %27, label %21

21:                                               ; preds = %17
  %22 = load ptr, ptr %13, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 9
  %24 = load i8, ptr %23, align 1, !tbaa !22
  %25 = and i8 %24, 3
  %.not16 = icmp eq i8 %25, 0
  br i1 %.not16, label %27, label %26

26:                                               ; preds = %21
  tail call void @luaC_barrierback_(ptr noundef nonnull %0, ptr noundef nonnull %4) #3
  %.pre = load ptr, ptr %5, align 8, !tbaa !8
  br label %27

27:                                               ; preds = %26, %21, %17, %2
  %28 = phi ptr [ %.pre, %26 ], [ %12, %21 ], [ %12, %17 ], [ %12, %2 ]
  %29 = getelementptr inbounds i8, ptr %28, i64 -32
  store ptr %29, ptr %5, align 8, !tbaa !8
  ret void
}

declare hidden ptr @luaH_set(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 16}
!9 = !{!"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, !11, i64 96, !10, i64 168, !12, i64 176, !14, i64 184, !14, i64 188, !14, i64 192, !13, i64 196, !13, i64 198, !6, i64 200, !6, i64 201}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"CallInfo", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !12, i64 56, !13, i64 64, !6, i64 66}
!12 = !{!"long", !6, i64 0}
!13 = !{!"short", !6, i64 0}
!14 = !{!"int", !6, i64 0}
!15 = !{i64 0, i64 8, !5, i64 8, i64 4, !16}
!16 = !{!14, !14, i64 0}
!17 = !{!18, !6, i64 10}
!18 = !{!"Table", !10, i64 0, !6, i64 8, !6, i64 9, !6, i64 10, !6, i64 11, !14, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!19 = !{!20, !14, i64 8}
!20 = !{!"lua_TValue", !6, i64 0, !14, i64 8}
!21 = !{!18, !6, i64 9}
!22 = !{!23, !6, i64 9}
!23 = !{!"GCObject", !10, i64 0, !6, i64 8, !6, i64 9}


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