; LLVM IR from paintdream/DontStarveLuaJIT :: src/lua51/src (lstate)

; 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, [8 x i8] }
%struct.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }

; Function Attrs: alwaysinline nounwind uwtable
define dso_local void @preinit_state(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.lua_State, ptr %6, i32 0, i32 6
  store ptr %5, ptr %7, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.lua_State, ptr %8, i32 0, i32 10
  store ptr null, ptr %9, align 8, !tbaa !15
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.lua_State, ptr %10, i32 0, i32 13
  store i32 0, ptr %11, align 8, !tbaa !16
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.lua_State, ptr %12, i32 0, i32 26
  store ptr null, ptr %13, align 8, !tbaa !17
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.lua_State, ptr %14, i32 0, i32 21
  store ptr null, ptr %15, align 8, !tbaa !18
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.lua_State, ptr %16, i32 0, i32 17
  store i8 0, ptr %17, align 4, !tbaa !19
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.lua_State, ptr %18, i32 0, i32 19
  store i32 0, ptr %19, align 8, !tbaa !20
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.lua_State, ptr %20, i32 0, i32 18
  store i8 1, ptr %21, align 1, !tbaa !21
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_State, ptr %22, i32 0, i32 19
  %24 = load i32, ptr %23, align 8, !tbaa !20
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.lua_State, ptr %25, i32 0, i32 20
  store i32 %24, ptr %26, align 4, !tbaa !22
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lua_State, ptr %27, i32 0, i32 24
  store ptr null, ptr %28, align 8, !tbaa !23
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.lua_State, ptr %29, i32 0, i32 14
  store i32 0, ptr %30, align 4, !tbaa !24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.lua_State, ptr %31, i32 0, i32 16
  store i16 0, ptr %32, align 2, !tbaa !25
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.lua_State, ptr %33, i32 0, i32 15
  store i16 0, ptr %34, align 8, !tbaa !26
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.lua_State, ptr %35, i32 0, i32 3
  store i8 0, ptr %36, align 2, !tbaa !27
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.lua_State, ptr %37, i32 0, i32 7
  store ptr null, ptr %38, align 8, !tbaa !28
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.lua_State, ptr %39, i32 0, i32 12
  store ptr null, ptr %40, align 8, !tbaa !29
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.lua_State, ptr %41, i32 0, i32 8
  store ptr null, ptr %42, align 8, !tbaa !30
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lua_State, ptr %43, i32 0, i32 27
  store i64 0, ptr %44, align 8, !tbaa !31
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.lua_State, ptr %45, i32 0, i32 22
  %47 = getelementptr inbounds %struct.lua_TValue, ptr %46, i32 0, i32 1
  store i32 0, ptr %47, align 8, !tbaa !32
  ret void
}

attributes #0 = { alwaysinline 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"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, !11, i64 88, !11, i64 92, !12, i64 96, !12, i64 98, !7, i64 100, !7, i64 101, !11, i64 104, !11, i64 108, !6, i64 112, !13, i64 120, !13, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !14, i64 176, !7, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"lua_TValue", !7, i64 0, !11, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !6, i64 64}
!16 = !{!10, !11, i64 88}
!17 = !{!10, !6, i64 168}
!18 = !{!10, !6, i64 112}
!19 = !{!10, !7, i64 100}
!20 = !{!10, !11, i64 104}
!21 = !{!10, !7, i64 101}
!22 = !{!10, !11, i64 108}
!23 = !{!10, !6, i64 152}
!24 = !{!10, !11, i64 92}
!25 = !{!10, !12, i64 98}
!26 = !{!10, !12, i64 96}
!27 = !{!10, !7, i64 10}
!28 = !{!10, !6, i64 40}
!29 = !{!10, !6, i64 80}
!30 = !{!10, !6, i64 48}
!31 = !{!10, !14, i64 176}
!32 = !{!10, !11, i64 128}


; 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: alwaysinline mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @preinit_state(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr null, ptr %4, align 8, !tbaa !14
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  store i32 0, ptr %5, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 168
  store ptr null, ptr %6, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %0, i64 112
  store ptr null, ptr %7, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %0, i64 100
  store i8 0, ptr %8, align 4, !tbaa !18
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  store i32 0, ptr %9, align 8, !tbaa !19
  %10 = getelementptr inbounds i8, ptr %0, i64 101
  store i8 1, ptr %10, align 1, !tbaa !20
  %11 = getelementptr inbounds i8, ptr %0, i64 108
  store i32 0, ptr %11, align 4, !tbaa !21
  %12 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr null, ptr %12, align 8, !tbaa !22
  %13 = getelementptr inbounds i8, ptr %0, i64 92
  %14 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 0, ptr %14, align 2, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr null, ptr %16, align 8, !tbaa !24
  %17 = getelementptr inbounds i8, ptr %0, i64 176
  store i64 0, ptr %17, align 8, !tbaa !25
  %18 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 0, ptr %18, align 8, !tbaa !26
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %15, i8 0, i64 16, i1 false)
  store i64 0, ptr %13, align 4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { alwaysinline mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 nounwind willreturn memory(argmem: write) }

!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, !7, i64 32}
!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, !8, i64 184}
!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 64}
!15 = !{!6, !10, i64 88}
!16 = !{!6, !7, i64 168}
!17 = !{!6, !7, i64 112}
!18 = !{!6, !8, i64 100}
!19 = !{!6, !10, i64 104}
!20 = !{!6, !8, i64 101}
!21 = !{!6, !10, i64 108}
!22 = !{!6, !7, i64 152}
!23 = !{!6, !8, i64 10}
!24 = !{!6, !7, i64 80}
!25 = !{!6, !13, i64 176}
!26 = !{!6, !10, i64 128}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass