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

; 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.4 = external hidden unnamed_addr constant [8 x i8], align 1

; 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
declare dso_local ptr @luaL_findtable(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @luaL_openlib(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %44

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call i32 @libsize(ptr noundef %15)
  store i32 %16, ptr %9, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call ptr @luaL_findtable(ptr noundef %17, i32 noundef -10000, ptr noundef @.str.4, i32 noundef 16)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lua_getfield(ptr noundef %19, i32 noundef -1, ptr noundef %20)
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i32 @lua_type(ptr noundef %21, i32 noundef -1)
  %23 = icmp eq i32 %22, 5
  br i1 %23, label %38, label %24

24:                                               ; preds = %14
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lua_settop(ptr noundef %25, i32 noundef -2)
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = call ptr @luaL_findtable(ptr noundef %26, i32 noundef -10002, ptr noundef %27, i32 noundef %28)
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %34

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  call void (ptr, i32, ...) @lj_err_callerv(ptr noundef %32, i32 noundef 1953, ptr noundef %33) #5
  unreachable

34:                                               ; preds = %24
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lua_pushvalue(ptr noundef %35, i32 noundef -1)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %36, i32 noundef -3, ptr noundef %37)
  br label %38

38:                                               ; preds = %34, %14
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lua_remove(ptr noundef %39, i32 noundef -2)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  %43 = sub nsw i32 0, %42
  call void @lua_insert(ptr noundef %40, i32 noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %44

44:                                               ; preds = %38, %4
  br label %45

45:                                               ; preds = %75, %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.luaL_Reg, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %78

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %59, %50
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %55, label %62

55:                                               ; preds = %51
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sub nsw i32 0, %57
  call void @lua_pushvalue(ptr noundef %56, i32 noundef %58)
  br label %59

59:                                               ; preds = %55
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %10, align 4, !tbaa !9
  br label %51, !llvm.loop !13

62:                                               ; preds = %51
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.luaL_Reg, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = load i32, ptr %8, align 4, !tbaa !9
  call void @lua_pushcclosure(ptr noundef %63, ptr noundef %66, i32 noundef %67)
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = add nsw i32 %69, 2
  %71 = sub nsw i32 0, %70
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.luaL_Reg, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  call void @lua_setfield(ptr noundef %68, i32 noundef %71, ptr noundef %74)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %75

75:                                               ; preds = %62
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.luaL_Reg, ptr %76, i32 1
  store ptr %77, ptr %7, align 8, !tbaa !5
  br label %45, !llvm.loop !16

78:                                               ; preds = %45
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i32, ptr %8, align 4, !tbaa !9
  %81 = sub nsw i32 0, %80
  %82 = sub nsw i32 %81, 1
  call void @lua_settop(ptr noundef %79, i32 noundef %82)
  ret void
}

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

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

; Function Attrs: noreturn
declare hidden void @lj_err_callerv(ptr noundef, i32 noundef, ...) #3

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

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

declare void @lua_pushcclosure(ptr noundef, ptr 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 = { noreturn "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 }
attributes #5 = { noreturn }

!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, !6, i64 0}
!12 = !{!"luaL_Reg", !6, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !14}


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

@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @luaL_findtable(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @luaL_openlib(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %16, label %5

5:                                                ; preds = %4
  %6 = tail call i32 @libsize(ptr noundef %2)
  %7 = tail call ptr @luaL_findtable(ptr noundef %0, i32 noundef -10000, ptr noundef nonnull @.str.4, i32 noundef 16)
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -1, ptr noundef nonnull %1) #3
  %8 = tail call i32 @lua_type(ptr noundef %0, i32 noundef -1) #3
  %9 = icmp eq i32 %8, 5
  br i1 %9, label %14, label %10

10:                                               ; preds = %5
  tail call void @lua_settop(ptr noundef %0, i32 noundef -2) #3
  %11 = tail call ptr @luaL_findtable(ptr noundef %0, i32 noundef -10002, ptr noundef nonnull %1, i32 noundef %6)
  %.not36 = icmp eq ptr %11, null
  br i1 %.not36, label %13, label %12

12:                                               ; preds = %10
  tail call void (ptr, i32, ...) @lj_err_callerv(ptr noundef %0, i32 noundef 1953, ptr noundef nonnull %1) #4
  unreachable

13:                                               ; preds = %10
  tail call void @lua_pushvalue(ptr noundef %0, i32 noundef -1) #3
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -3, ptr noundef nonnull %1) #3
  br label %14

14:                                               ; preds = %13, %5
  tail call void @lua_remove(ptr noundef %0, i32 noundef -2) #3
  %15 = xor i32 %3, -1
  tail call void @lua_insert(ptr noundef %0, i32 noundef %15) #3
  br label %16

16:                                               ; preds = %14, %4
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %.not3739 = icmp eq ptr %17, null
  br i1 %.not3739, label %._crit_edge41, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %16
  %18 = icmp sgt i32 %3, 0
  %19 = sub nsw i32 0, %3
  %20 = sub nsw i32 -2, %3
  br i1 %18, label %.preheader.us, label %.preheader

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %.03340.us = phi ptr [ %26, %._crit_edge.us ], [ %2, %.preheader.lr.ph ]
  br label %21

21:                                               ; preds = %.preheader.us, %21
  %.038.us = phi i32 [ 0, %.preheader.us ], [ %22, %21 ]
  tail call void @lua_pushvalue(ptr noundef %0, i32 noundef %19) #3
  %22 = add nuw nsw i32 %.038.us, 1
  %exitcond.not = icmp eq i32 %22, %3
  br i1 %exitcond.not, label %._crit_edge.us, label %21, !llvm.loop !10

._crit_edge.us:                                   ; preds = %21
  %23 = getelementptr inbounds i8, ptr %.03340.us, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef %24, i32 noundef %3) #3
  %25 = load ptr, ptr %.03340.us, align 8, !tbaa !5
  tail call void @lua_setfield(ptr noundef %0, i32 noundef %20, ptr noundef %25) #3
  %26 = getelementptr inbounds i8, ptr %.03340.us, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %.not37.us = icmp eq ptr %27, null
  br i1 %.not37.us, label %._crit_edge41, label %.preheader.us, !llvm.loop !13

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.03340 = phi ptr [ %31, %.preheader ], [ %2, %.preheader.lr.ph ]
  %28 = getelementptr inbounds i8, ptr %.03340, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef %29, i32 noundef %3) #3
  %30 = load ptr, ptr %.03340, align 8, !tbaa !5
  tail call void @lua_setfield(ptr noundef %0, i32 noundef %20, ptr noundef %30) #3
  %31 = getelementptr inbounds i8, ptr %.03340, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %.not37 = icmp eq ptr %32, null
  br i1 %.not37, label %._crit_edge41, label %.preheader, !llvm.loop !13

._crit_edge41:                                    ; preds = %.preheader, %._crit_edge.us, %16
  %33 = xor i32 %3, -1
  tail call void @lua_settop(ptr noundef %0, i32 noundef %33) #3
  ret void
}

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

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

; Function Attrs: noreturn
declare hidden void @lj_err_callerv(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

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

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

declare void @lua_pushcclosure(ptr 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 = { noreturn "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 }
attributes #4 = { noreturn 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 = !{!"luaL_Reg", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!6, !7, i64 8}
!13 = distinct !{!13, !11}


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