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

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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@package_lib = external hidden constant [4 x %struct.luaL_Reg], align 16
@package_loaders = external hidden constant [5 x ptr], align 16
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [117 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [8 x i8], align 1
@package_global = external hidden constant [3 x %struct.luaL_Reg], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @luaopen_package(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i32 @luaL_newmetatable(ptr noundef %5, ptr noundef @.str)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @lj_lib_pushcc(ptr noundef %7, ptr noundef @lj_cf_package_unloadlib, i32 noundef 1, i32 noundef 0)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %9, i32 noundef -2, ptr noundef @.str.1)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  call void @luaL_register(ptr noundef %10, ptr noundef @.str.2, ptr noundef @package_lib)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushvalue(ptr noundef %11, i32 noundef -1)
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_replace(ptr noundef %12, i32 noundef -10001)
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_createtable(ptr noundef %13, i32 noundef 4, i32 noundef 0)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %30, %1
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x ptr], ptr @package_loaders, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %33

20:                                               ; preds = %14
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [5 x ptr], ptr @package_loaders, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = call ptr @lj_lib_pushcc(ptr noundef %21, ptr noundef %25, i32 noundef 1, i32 noundef 0)
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  call void @lua_rawseti(ptr noundef %27, i32 noundef -2, i32 noundef %29)
  br label %30

30:                                               ; preds = %20
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !9
  br label %14, !llvm.loop !11

33:                                               ; preds = %14
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %34, i32 noundef -2, ptr noundef @.str.3)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_getfield(ptr noundef %35, i32 noundef -10000, ptr noundef @.str.4)
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call i32 @lua_toboolean(ptr noundef %36, i32 noundef -1)
  store i32 %37, ptr %4, align 4, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_settop(ptr noundef %38, i32 noundef -2)
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !9
  call void @setpath(ptr noundef %39, ptr noundef @.str.5, ptr noundef @.str.6, ptr noundef @.str.7, i32 noundef %40)
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !9
  call void @setpath(ptr noundef %41, ptr noundef @.str.8, ptr noundef @.str.9, ptr noundef @.str.10, i32 noundef %42)
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushlstring(ptr noundef %43, ptr noundef @.str.11, i64 noundef 9)
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %44, i32 noundef -2, ptr noundef @.str.12)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call ptr @luaL_findtable(ptr noundef %45, i32 noundef -10000, ptr noundef @.str.13, i32 noundef 16)
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %47, i32 noundef -2, ptr noundef @.str.14)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = call ptr @luaL_findtable(ptr noundef %48, i32 noundef -10000, ptr noundef @.str.15, i32 noundef 4)
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %50, i32 noundef -2, ptr noundef @.str.16)
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushvalue(ptr noundef %51, i32 noundef -10002)
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  call void @luaL_register(ptr noundef %52, ptr noundef null, ptr noundef @package_global)
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_settop(ptr noundef %53, i32 noundef -2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 1
}

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

declare i32 @luaL_newmetatable(ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @lj_cf_package_unloadlib(ptr noundef) #0

declare void @lua_setfield(ptr noundef, i32 noundef, ptr noundef) #2

declare void @luaL_register(ptr noundef, ptr noundef, ptr noundef) #2

declare void @lua_pushvalue(ptr noundef, i32 noundef) #2

declare void @lua_replace(ptr noundef, i32 noundef) #2

declare void @lua_createtable(ptr noundef, i32 noundef, i32 noundef) #2

declare void @lua_rawseti(ptr noundef, i32 noundef, i32 noundef) #2

declare void @lua_getfield(ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @lua_toboolean(ptr noundef, i32 noundef) #2

declare void @lua_settop(ptr noundef, i32 noundef) #2

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

declare void @lua_pushlstring(ptr noundef, ptr noundef, i64 noundef) #2

declare ptr @luaL_findtable(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@package_lib = external hidden constant [4 x %struct.luaL_Reg], align 16
@package_loaders = external hidden local_unnamed_addr constant [5 x ptr], align 16
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [117 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [8 x i8], align 1
@package_global = external hidden constant [3 x %struct.luaL_Reg], align 16

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @luaopen_package(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @luaL_newmetatable(ptr noundef %0, ptr noundef nonnull @.str) #2
  %3 = tail call ptr @lj_lib_pushcc(ptr noundef %0, ptr noundef nonnull @lj_cf_package_unloadlib, i32 noundef 1, i32 noundef 0) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.1) #2
  tail call void @luaL_register(ptr noundef %0, ptr noundef nonnull @.str.2, ptr noundef nonnull @package_lib) #2
  tail call void @lua_pushvalue(ptr noundef %0, i32 noundef -1) #2
  tail call void @lua_replace(ptr noundef %0, i32 noundef -10001) #2
  tail call void @lua_createtable(ptr noundef %0, i32 noundef 4, i32 noundef 0) #2
  %4 = load ptr, ptr @package_loaders, align 16, !tbaa !5
  %.not30 = icmp eq ptr %4, null
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %5 = phi ptr [ %9, %.lr.ph ], [ %4, %1 ]
  %6 = tail call ptr @lj_lib_pushcc(ptr noundef %0, ptr noundef nonnull %5, i32 noundef 1, i32 noundef 0) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = trunc nuw i64 %indvars.iv.next to i32
  tail call void @lua_rawseti(ptr noundef %0, i32 noundef -2, i32 noundef %7) #2
  %8 = getelementptr inbounds [5 x ptr], ptr @package_loaders, i64 0, i64 %indvars.iv.next
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %1
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.3) #2
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -10000, ptr noundef nonnull @.str.4) #2
  %10 = tail call i32 @lua_toboolean(ptr noundef %0, i32 noundef -1) #2
  tail call void @lua_settop(ptr noundef %0, i32 noundef -2) #2
  tail call void @setpath(ptr noundef %0, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.7, i32 noundef %10)
  tail call void @setpath(ptr noundef %0, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.10, i32 noundef %10)
  tail call void @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.11, i64 noundef 9) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.12) #2
  %11 = tail call ptr @luaL_findtable(ptr noundef %0, i32 noundef -10000, ptr noundef nonnull @.str.13, i32 noundef 16) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.14) #2
  %12 = tail call ptr @luaL_findtable(ptr noundef %0, i32 noundef -10000, ptr noundef nonnull @.str.15, i32 noundef 4) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.16) #2
  tail call void @lua_pushvalue(ptr noundef %0, i32 noundef -10002) #2
  tail call void @luaL_register(ptr noundef %0, ptr noundef null, ptr noundef nonnull @package_global) #2
  tail call void @lua_settop(ptr noundef %0, i32 noundef -2) #2
  ret i32 1
}

declare i32 @luaL_newmetatable(ptr noundef, ptr noundef) local_unnamed_addr #1

declare hidden ptr @lj_lib_pushcc(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @lj_cf_package_unloadlib(ptr noundef) #0

declare void @lua_setfield(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @luaL_register(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @lua_pushvalue(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @lua_replace(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @lua_createtable(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @lua_rawseti(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @lua_getfield(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @lua_toboolean(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @lua_settop(ptr noundef, i32 noundef) local_unnamed_addr #1

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

declare void @lua_pushlstring(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @luaL_findtable(ptr noundef, i32 noundef, ptr 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass