; LLVM IR from paintdream/DontStarveLuaJIT :: src/luajit/src (lj_cdata)

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

%union.TValue = type { i64 }
%struct.lua_State = type { %union.anon }
%union.anon = type { %struct.anon, [320 x i8] }
%struct.anon = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.MRef = type { i32 }
%struct.GCRef = type { i32 }
%struct.global_State = type { ptr, i32, i32, ptr, ptr, %struct.GCState, i32, %struct.SBuf, %struct.GCstr, i8, i8, i8, i8, %struct.GCRef, %union.TValue, %union.TValue, %union.TValue, %struct.Node, %struct.GCupval, i32, i32, ptr, ptr, ptr, i32, i32, %struct.GCRef, %struct.MRef, %struct.MRef, [38 x %struct.GCRef] }
%struct.GCState = type { i32, i32, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, i32, i32, i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.4, %struct.MRef, i32 }
%union.anon.4 = type { %union.TValue }
%struct.CTState = type { ptr, i32, i32, ptr, ptr, ptr, ptr, %struct.CCallback, [128 x i16] }
%struct.CCallback = type { [8 x %union.FPRCBArg], [8 x i64], ptr, ptr, ptr, i32, i32, i32 }
%union.FPRCBArg = type { double }
%struct.GCtab = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, %struct.MRef, i32, i32 }
%struct.GChead = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.GCRef }
%struct.anon.0 = type { %union.anon.1, i32 }
%union.anon.1 = type { %struct.GCRef }
%struct.GCcdata = type { %struct.GCRef, i8, i8, i16 }

; 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 nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind uwtable
define hidden void @lj_cdata_setfin(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %union.TValue, 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 i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.lua_State, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 5
  %15 = getelementptr inbounds %struct.MRef, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = inttoptr i64 %17 to ptr
  %19 = getelementptr inbounds %struct.global_State, ptr %18, i32 0, i32 28
  %20 = getelementptr inbounds %struct.MRef, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !12
  %22 = zext i32 %21 to i64
  %23 = inttoptr i64 %22 to ptr
  %24 = getelementptr inbounds %struct.CTState, ptr %23, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.GCtab, ptr %26, i32 0, i32 7
  %28 = getelementptr inbounds %struct.GCRef, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !24
  %30 = zext i32 %29 to i64
  %31 = inttoptr i64 %30 to ptr
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %84

33:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  call void @setcdataV(ptr noundef %34, ptr noundef %11, ptr noundef %35)
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.GChead, ptr %36, i32 0, i32 1
  %38 = load i8, ptr %37, align 4, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = and i32 %39, 4
  %41 = icmp ne i32 %40, 0
  %42 = xor i1 %41, true
  %43 = xor i1 %42, true
  %44 = zext i1 %43 to i32
  %45 = sext i32 %44 to i64
  %46 = call i64 @llvm.expect.i64(i64 %45, i64 0)
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %57

48:                                               ; preds = %33
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.lua_State, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.anon, ptr %50, i32 0, i32 5
  %52 = getelementptr inbounds %struct.MRef, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = zext i32 %53 to i64
  %55 = inttoptr i64 %54 to ptr
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  call void @lj_gc_barrierback(ptr noundef %55, ptr noundef %56)
  br label %57

57:                                               ; preds = %48, %33
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = call ptr @lj_tab_set(ptr noundef %58, ptr noundef %59, ptr noundef %11)
  store ptr %60, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  call void @setgcV(ptr noundef %61, ptr noundef %62, ptr noundef %63, i32 noundef %64)
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.anon.0, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = icmp eq i32 %67, -1
  br i1 %68, label %76, label %69

69:                                               ; preds = %57
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.GCcdata, ptr %70, i32 0, i32 1
  %72 = load i8, ptr %71, align 4, !tbaa !26
  %73 = zext i8 %72 to i32
  %74 = or i32 %73, 16
  %75 = trunc i32 %74 to i8
  store i8 %75, ptr %71, align 4, !tbaa !26
  br label %83

76:                                               ; preds = %57
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.GCcdata, ptr %77, i32 0, i32 1
  %79 = load i8, ptr %78, align 4, !tbaa !26
  %80 = zext i8 %79 to i32
  %81 = and i32 %80, -17
  %82 = trunc i32 %81 to i8
  store i8 %82, ptr %78, align 4, !tbaa !26
  br label %83

83:                                               ; preds = %76, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %84

84:                                               ; preds = %83, %4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setcdataV(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @lj_gc_barrierback(ptr noundef, ptr noundef) #3

declare hidden ptr @lj_tab_set(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setgcV(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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" }
attributes #4 = { "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 #5 = { 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, !10, i64 256}
!13 = !{!"global_State", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !14, i64 32, !10, i64 88, !17, i64 92, !18, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !15, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !19, i64 160, !20, i64 184, !10, i64 208, !10, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !10, i64 240, !10, i64 244, !15, i64 248, !16, i64 252, !16, i64 256, !7, i64 260}
!14 = !{!"GCState", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !10, i64 12, !15, i64 16, !16, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!15 = !{!"GCRef", !10, i64 0}
!16 = !{!"MRef", !10, i64 0}
!17 = !{!"SBuf", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12}
!18 = !{!"GCstr", !15, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12}
!19 = !{!"Node", !7, i64 0, !7, i64 8, !16, i64 16, !16, i64 20}
!20 = !{!"GCupval", !15, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !16, i64 16, !10, i64 20}
!21 = !{!22, !6, i64 32}
!22 = !{!"CTState", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !23, i64 48, !7, i64 216}
!23 = !{!"CCallback", !7, i64 0, !7, i64 64, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !10, i64 156, !10, i64 160}
!24 = !{!25, !10, i64 16}
!25 = !{!"GCtab", !15, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !16, i64 8, !15, i64 12, !15, i64 16, !6, i64 24, !16, i64 32, !10, i64 36, !10, i64 40}
!26 = !{!27, !7, i64 4}
!27 = !{!"GCcdata", !15, i64 0, !7, i64 4, !7, i64 5, !28, i64 6}
!28 = !{!"short", !7, i64 0}


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

%union.TValue = type { i64 }

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

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

; Function Attrs: nounwind uwtable
define hidden void @lj_cdata_setfin(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca %union.TValue, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = inttoptr i64 %8 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 256
  %11 = load i32, ptr %10, align 8, !tbaa !8
  %12 = zext i32 %11 to i64
  %13 = inttoptr i64 %12 to ptr
  %14 = getelementptr inbounds i8, ptr %13, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load i32, ptr %16, align 8, !tbaa !22
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %34, label %18

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @setcdataV(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef %1)
  %19 = getelementptr inbounds i8, ptr %15, i64 4
  %20 = load i8, ptr %19, align 4, !tbaa !5
  %21 = and i8 %20, 4
  %.not15 = icmp eq i8 %21, 0
  br i1 %.not15, label %26, label %22, !prof !24

22:                                               ; preds = %18
  %23 = load i32, ptr %6, align 8, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  call void @lj_gc_barrierback(ptr noundef %25, ptr noundef nonnull %15)
  br label %26

26:                                               ; preds = %22, %18
  %27 = call ptr @lj_tab_set(ptr noundef nonnull %0, ptr noundef nonnull %15, ptr noundef nonnull %5) #4
  call void @setgcV(ptr noundef nonnull %0, ptr noundef %27, ptr noundef %2, i32 noundef %3)
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %29, -1
  %31 = getelementptr inbounds i8, ptr %1, i64 4
  %32 = load i8, ptr %31, align 4, !tbaa !25
  %33 = and i8 %32, -17
  %masksel = select i1 %30, i8 0, i8 16
  %.sink = or disjoint i8 %33, %masksel
  store i8 %.sink, ptr %31, align 4, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %34

34:                                               ; preds = %26, %4
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setcdataV(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @lj_gc_barrierback(ptr noundef, ptr noundef) local_unnamed_addr #2

declare hidden ptr @lj_tab_set(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @setgcV(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync 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 = { 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" }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 256}
!9 = !{!"global_State", !10, i64 0, !11, i64 8, !11, i64 12, !10, i64 16, !10, i64 24, !12, i64 32, !11, i64 88, !15, i64 92, !16, i64 108, !6, i64 124, !6, i64 125, !6, i64 126, !6, i64 127, !13, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !17, i64 160, !18, i64 184, !11, i64 208, !11, i64 212, !10, i64 216, !10, i64 224, !10, i64 232, !11, i64 240, !11, i64 244, !13, i64 248, !14, i64 252, !14, i64 256, !6, i64 260}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"GCState", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 9, !6, i64 10, !6, i64 11, !11, i64 12, !13, i64 16, !14, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!13 = !{!"GCRef", !11, i64 0}
!14 = !{!"MRef", !11, i64 0}
!15 = !{!"SBuf", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!16 = !{!"GCstr", !13, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !11, i64 8, !11, i64 12}
!17 = !{!"Node", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 20}
!18 = !{!"GCupval", !13, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !6, i64 8, !14, i64 16, !11, i64 20}
!19 = !{!20, !10, i64 32}
!20 = !{!"CTState", !10, i64 0, !11, i64 8, !11, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !21, i64 48, !6, i64 216}
!21 = !{!"CCallback", !6, i64 0, !6, i64 64, !10, i64 128, !10, i64 136, !10, i64 144, !11, i64 152, !11, i64 156, !11, i64 160}
!22 = !{!23, !11, i64 16}
!23 = !{!"GCtab", !13, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !14, i64 8, !13, i64 12, !13, i64 16, !10, i64 24, !14, i64 32, !11, i64 36, !11, i64 40}
!24 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!25 = !{!26, !6, i64 4}
!26 = !{!"GCcdata", !13, i64 0, !6, i64 4, !6, i64 5, !27, i64 6}
!27 = !{!"short", !6, i64 0}


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