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

%struct.GCcdataVar = type { i16, i16, i32 }
%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 }
%union.TValue = type { i64 }
%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.GCcdata = type { %struct.GCRef, i8, i8, i16 }
%struct.GChead = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.GCRef }

; 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: nounwind uwtable
define hidden ptr @lj_cdata_newv(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp ugt i32 %15, 3
  br i1 %16, label %17, label %21

17:                                               ; preds = %4
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = shl i32 1, %18
  %20 = sub i32 %19, 8
  br label %22

21:                                               ; preds = %4
  br label %22

22:                                               ; preds = %21, %17
  %23 = phi i32 [ %20, %17 ], [ 0, %21 ]
  %24 = zext i32 %23 to i64
  %25 = add i64 16, %24
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add i32 %28, %29
  %31 = call ptr @lj_mem_realloc(ptr noundef %27, ptr noundef null, i32 noundef 0, i32 noundef %30)
  store ptr %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = ptrtoint ptr %32 to i64
  %34 = add i64 %33, 8
  %35 = add i64 %34, 8
  store i64 %35, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = shl i32 1, %36
  %38 = sub i32 %37, 1
  %39 = zext i32 %38 to i64
  store i64 %39, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %40 = load i64, ptr %12, align 8, !tbaa !11
  %41 = load i64, ptr %13, align 8, !tbaa !11
  %42 = add i64 %40, %41
  %43 = load i64, ptr %13, align 8, !tbaa !11
  %44 = xor i64 %43, -1
  %45 = and i64 %42, %44
  %46 = sub i64 %45, 8
  %47 = inttoptr i64 %46 to ptr
  store ptr %47, ptr %14, align 8, !tbaa !5
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = ptrtoint ptr %48 to i64
  %51 = ptrtoint ptr %49 to i64
  %52 = sub i64 %50, %51
  %53 = trunc i64 %52 to i16
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 -8
  %56 = getelementptr inbounds %struct.GCcdataVar, ptr %55, i32 0, i32 0
  store i16 %53, ptr %56, align 4, !tbaa !13
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = trunc i32 %57 to i16
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 -8
  %61 = getelementptr inbounds %struct.GCcdataVar, ptr %60, i32 0, i32 1
  store i16 %58, ptr %61, align 2, !tbaa !16
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 -8
  %65 = getelementptr inbounds %struct.GCcdataVar, ptr %64, i32 0, i32 2
  store i32 %62, ptr %65, align 4, !tbaa !17
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.lua_State, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds %struct.anon, ptr %67, i32 0, i32 5
  %69 = getelementptr inbounds %struct.MRef, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !18
  %71 = zext i32 %70 to i64
  %72 = inttoptr i64 %71 to ptr
  store ptr %72, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.global_State, ptr %73, i32 0, i32 5
  %75 = getelementptr inbounds %struct.GCState, ptr %74, i32 0, i32 7
  %76 = getelementptr inbounds %struct.GCRef, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !19
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.GCcdata, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds %struct.GCRef, ptr %79, i32 0, i32 0
  store i32 %77, ptr %80, align 4, !tbaa !28
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = ptrtoint ptr %81 to i64
  %83 = trunc i64 %82 to i32
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.global_State, ptr %84, i32 0, i32 5
  %86 = getelementptr inbounds %struct.GCState, ptr %85, i32 0, i32 7
  %87 = getelementptr inbounds %struct.GCRef, ptr %86, i32 0, i32 0
  store i32 %83, ptr %87, align 8, !tbaa !19
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.global_State, ptr %88, i32 0, i32 5
  %90 = getelementptr inbounds %struct.GCState, ptr %89, i32 0, i32 2
  %91 = load i8, ptr %90, align 8, !tbaa !30
  %92 = zext i8 %91 to i32
  %93 = and i32 %92, 3
  %94 = trunc i32 %93 to i8
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.GChead, ptr %95, i32 0, i32 1
  store i8 %94, ptr %96, align 4, !tbaa !18
  %97 = load ptr, ptr %14, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.GCcdata, ptr %97, i32 0, i32 1
  %99 = load i8, ptr %98, align 4, !tbaa !31
  %100 = zext i8 %99 to i32
  %101 = or i32 %100, 128
  %102 = trunc i32 %101 to i8
  store i8 %102, ptr %98, align 4, !tbaa !31
  %103 = load ptr, ptr %14, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.GCcdata, ptr %103, i32 0, i32 2
  store i8 10, ptr %104, align 1, !tbaa !32
  %105 = load i32, ptr %6, align 4, !tbaa !9
  %106 = trunc i32 %105 to i16
  %107 = load ptr, ptr %14, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.GCcdata, ptr %107, i32 0, i32 3
  store i16 %106, ptr %108, align 2, !tbaa !33
  %109 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %109
}

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

attributes #0 = { 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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"GCcdataVar", !15, i64 0, !15, i64 2, !10, i64 4}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !15, i64 2}
!17 = !{!14, !10, i64 4}
!18 = !{!7, !7, i64 0}
!19 = !{!20, !10, i64 48}
!20 = !{!"global_State", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !21, i64 32, !10, i64 88, !24, i64 92, !25, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !22, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !26, i64 160, !27, i64 184, !10, i64 208, !10, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !10, i64 240, !10, i64 244, !22, i64 248, !23, i64 252, !23, i64 256, !7, i64 260}
!21 = !{!"GCState", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !10, i64 12, !22, i64 16, !23, i64 20, !22, i64 24, !22, i64 28, !22, i64 32, !22, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!22 = !{!"GCRef", !10, i64 0}
!23 = !{!"MRef", !10, i64 0}
!24 = !{!"SBuf", !23, i64 0, !23, i64 4, !23, i64 8, !23, i64 12}
!25 = !{!"GCstr", !22, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12}
!26 = !{!"Node", !7, i64 0, !7, i64 8, !23, i64 16, !23, i64 20}
!27 = !{!"GCupval", !22, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !23, i64 16, !10, i64 20}
!28 = !{!29, !10, i64 0}
!29 = !{!"GCcdata", !22, i64 0, !7, i64 4, !7, i64 5, !15, i64 6}
!30 = !{!20, !7, i64 40}
!31 = !{!29, !7, i64 4}
!32 = !{!29, !7, i64 5}
!33 = !{!29, !15, i64 6}


; 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: nounwind uwtable
define hidden noundef ptr @lj_cdata_newv(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp ugt i32 %3, 3
  %6 = shl nuw i32 1, %3
  %7 = add nuw i32 %6, 8
  %8 = select i1 %5, i32 %7, i32 16
  %9 = add i32 %8, %2
  %10 = tail call ptr @lj_mem_realloc(ptr noundef %0, ptr noundef null, i32 noundef 0, i32 noundef %9) #2
  %11 = ptrtoint ptr %10 to i64
  %12 = add i32 %6, -1
  %13 = zext i32 %12 to i64
  %14 = add nuw nsw i64 %13, 16
  %15 = add i64 %14, %11
  %16 = xor i64 %13, -1
  %17 = and i64 %15, %16
  %18 = add i64 %17, -8
  %19 = inttoptr i64 %18 to ptr
  %20 = sub i64 %18, %11
  %21 = trunc i64 %20 to i16
  %22 = getelementptr inbounds i8, ptr %19, i64 -8
  store i16 %21, ptr %22, align 4, !tbaa !5
  %23 = trunc i32 %8 to i16
  %24 = getelementptr inbounds i8, ptr %19, i64 -6
  store i16 %23, ptr %24, align 2, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %19, i64 -4
  store i32 %2, ptr %25, align 4, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  %30 = getelementptr inbounds i8, ptr %29, i64 48
  %31 = load i32, ptr %30, align 8, !tbaa !14
  store i32 %31, ptr %19, align 4, !tbaa !24
  %32 = trunc i64 %18 to i32
  store i32 %32, ptr %30, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %29, i64 40
  %34 = load i8, ptr %33, align 8, !tbaa !26
  %35 = and i8 %34, 3
  %36 = getelementptr inbounds i8, ptr %19, i64 4
  %37 = or disjoint i8 %35, -128
  store i8 %37, ptr %36, align 4, !tbaa !27
  %38 = getelementptr inbounds i8, ptr %19, i64 5
  store i8 10, ptr %38, align 1, !tbaa !28
  %39 = trunc i32 %1 to i16
  %40 = getelementptr inbounds i8, ptr %19, i64 6
  store i16 %39, ptr %40, align 2, !tbaa !29
  ret ptr %19
}

declare hidden ptr @lj_mem_realloc(ptr noundef, ptr noundef, i32 noundef, i32 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, !7, i64 0}
!6 = !{!"GCcdataVar", !7, i64 0, !7, i64 2, !10, i64 4}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 2}
!12 = !{!6, !10, i64 4}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !10, i64 48}
!15 = !{!"global_State", !16, i64 0, !10, i64 8, !10, i64 12, !16, i64 16, !16, i64 24, !17, i64 32, !10, i64 88, !20, i64 92, !21, i64 108, !8, i64 124, !8, i64 125, !8, i64 126, !8, i64 127, !18, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !22, i64 160, !23, i64 184, !10, i64 208, !10, i64 212, !16, i64 216, !16, i64 224, !16, i64 232, !10, i64 240, !10, i64 244, !18, i64 248, !19, i64 252, !19, i64 256, !8, i64 260}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"GCState", !10, i64 0, !10, i64 4, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !10, i64 12, !18, i64 16, !19, i64 20, !18, i64 24, !18, i64 28, !18, i64 32, !18, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!18 = !{!"GCRef", !10, i64 0}
!19 = !{!"MRef", !10, i64 0}
!20 = !{!"SBuf", !19, i64 0, !19, i64 4, !19, i64 8, !19, i64 12}
!21 = !{!"GCstr", !18, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !10, i64 8, !10, i64 12}
!22 = !{!"Node", !8, i64 0, !8, i64 8, !19, i64 16, !19, i64 20}
!23 = !{!"GCupval", !18, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !19, i64 16, !10, i64 20}
!24 = !{!25, !10, i64 0}
!25 = !{!"GCcdata", !18, i64 0, !8, i64 4, !8, i64 5, !7, i64 6}
!26 = !{!15, !8, i64 40}
!27 = !{!25, !8, i64 4}
!28 = !{!25, !8, i64 5}
!29 = !{!25, !7, i64 6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass