; LLVM IR from Farama-Foundation/stable-retro :: third-party/luajit/src (lib_init)

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

@lj_lib_load = external hidden constant [11 x %struct.luaL_Reg], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@lj_lib_preload = external hidden constant [2 x %struct.luaL_Reg], align 16

; Function Attrs: nounwind uwtable
define dso_local void @luaL_openlibs(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr @lj_lib_load, ptr %3, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %19, %1
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.luaL_Reg, ptr %5, i32 0, i32 1
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %22

9:                                                ; preds = %4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.luaL_Reg, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  call void @lua_pushcclosure(ptr noundef %10, ptr noundef %13, i32 noundef 0)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.luaL_Reg, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  call void @lua_pushstring(ptr noundef %14, ptr noundef %17)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_call(ptr noundef %18, i32 noundef 1, i32 noundef 0)
  br label %19

19:                                               ; preds = %9
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.luaL_Reg, ptr %20, i32 1
  store ptr %21, ptr %3, align 8, !tbaa !5
  br label %4, !llvm.loop !12

22:                                               ; preds = %4
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call ptr @luaL_findtable(ptr noundef %23, i32 noundef -10000, ptr noundef @.str, i32 noundef 1)
  store ptr @lj_lib_preload, ptr %3, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %39, %22
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.luaL_Reg, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %42

30:                                               ; preds = %25
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.luaL_Reg, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  call void @lua_pushcclosure(ptr noundef %31, ptr noundef %34, i32 noundef 0)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.luaL_Reg, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  call void @lua_setfield(ptr noundef %35, i32 noundef -2, ptr noundef %38)
  br label %39

39:                                               ; preds = %30
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.luaL_Reg, ptr %40, i32 1
  store ptr %41, ptr %3, align 8, !tbaa !5
  br label %25, !llvm.loop !14

42:                                               ; preds = %25
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_settop(ptr noundef %43, i32 noundef -2)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

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

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

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

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

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

declare void @lua_settop(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, !6, i64 8}
!10 = !{!"luaL_Reg", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@lj_lib_load = external hidden local_unnamed_addr constant [11 x %struct.luaL_Reg], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@lj_lib_preload = external hidden local_unnamed_addr constant [2 x %struct.luaL_Reg], align 16

; Function Attrs: nounwind uwtable
define dso_local void @luaL_openlibs(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @lj_lib_load, i64 8), align 8, !tbaa !5
  %.not18 = icmp eq ptr %2, null
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %3 = phi ptr [ %7, %.lr.ph ], [ %2, %1 ]
  %.019 = phi ptr [ %5, %.lr.ph ], [ @lj_lib_load, %1 ]
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull %3, i32 noundef 0) #2
  %4 = load ptr, ptr %.019, align 8, !tbaa !10
  tail call void @lua_pushstring(ptr noundef %0, ptr noundef %4) #2
  tail call void @lua_call(ptr noundef %0, i32 noundef 1, i32 noundef 0) #2
  %5 = getelementptr inbounds i8, ptr %.019, i64 16
  %6 = getelementptr inbounds i8, ptr %.019, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %1
  %8 = tail call ptr @luaL_findtable(ptr noundef %0, i32 noundef -10000, ptr noundef nonnull @.str, i32 noundef 1) #2
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @lj_lib_preload, i64 8), align 8, !tbaa !5
  %.not1720 = icmp eq ptr %9, null
  br i1 %.not1720, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %._crit_edge, %.lr.ph23
  %10 = phi ptr [ %14, %.lr.ph23 ], [ %9, %._crit_edge ]
  %.121 = phi ptr [ %12, %.lr.ph23 ], [ @lj_lib_preload, %._crit_edge ]
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull %10, i32 noundef 0) #2
  %11 = load ptr, ptr %.121, align 8, !tbaa !10
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef %11) #2
  %12 = getelementptr inbounds i8, ptr %.121, i64 16
  %13 = getelementptr inbounds i8, ptr %.121, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.not17 = icmp eq ptr %14, null
  br i1 %.not17, label %._crit_edge24, label %.lr.ph23, !llvm.loop !13

._crit_edge24:                                    ; preds = %.lr.ph23, %._crit_edge
  tail call void @lua_settop(ptr noundef %0, i32 noundef -2) #2
  ret void
}

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

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

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

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

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

declare void @lua_settop(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, !7, i64 8}
!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 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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