; LLVM IR from ramsdell/lineqpp :: lua (loadlib)

; 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
@pk_funcs = external hidden constant [3 x %struct.luaL_Reg], align 16
@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 [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [138 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [8 x i8], align 1
@ll_funcs = 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
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = call i32 @luaL_newmetatable(ptr noundef %4, ptr noundef @.str)
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushcclosure(ptr noundef %6, ptr noundef @gctm, i32 noundef 0)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %7, i32 noundef -2, ptr noundef @.str.1)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  call void @luaL_register(ptr noundef %8, ptr noundef @.str.2, ptr noundef @pk_funcs)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushvalue(ptr noundef %9, i32 noundef -1)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_replace(ptr noundef %10, i32 noundef -10001)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_createtable(ptr noundef %11, i32 noundef 4, i32 noundef 0)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %12

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

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

27:                                               ; preds = %18
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !9
  br label %12, !llvm.loop !11

30:                                               ; preds = %12
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %31, i32 noundef -2, ptr noundef @.str.3)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  call void @setpath(ptr noundef %32, ptr noundef @.str.4, ptr noundef @.str.5, ptr noundef @.str.6)
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void @setpath(ptr noundef %33, ptr noundef @.str.7, ptr noundef @.str.8, ptr noundef @.str.9)
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushlstring(ptr noundef %34, ptr noundef @.str.10, i64 noundef 9)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %35, i32 noundef -2, ptr noundef @.str.11)
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call ptr @luaL_findtable(ptr noundef %36, i32 noundef -10000, ptr noundef @.str.12, i32 noundef 2)
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %38, i32 noundef -2, ptr noundef @.str.13)
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_createtable(ptr noundef %39, i32 noundef 0, i32 noundef 0)
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %40, i32 noundef -2, ptr noundef @.str.14)
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushvalue(ptr noundef %41, i32 noundef -10002)
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @luaL_register(ptr noundef %42, ptr noundef null, ptr noundef @ll_funcs)
  %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 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 void @lua_pushcclosure(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @gctm(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

; Function Attrs: nounwind uwtable
declare hidden void @setpath(ptr noundef, ptr noundef, ptr noundef, ptr 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

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, !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
@pk_funcs = external hidden constant [3 x %struct.luaL_Reg], align 16
@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 [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [138 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [8 x i8], align 1
@ll_funcs = 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
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull @gctm, 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 @pk_funcs) #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
  %3 = load ptr, ptr @loaders, align 16, !tbaa !5
  %.not25 = icmp eq ptr %3, null
  br i1 %.not25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %4 = phi ptr [ %7, %.lr.ph ], [ %3, %1 ]
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull %4, i32 noundef 0) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = trunc nuw i64 %indvars.iv.next to i32
  tail call void @lua_rawseti(ptr noundef %0, i32 noundef -2, i32 noundef %5) #2
  %6 = getelementptr inbounds [5 x ptr], ptr @loaders, i64 0, i64 %indvars.iv.next
  %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 !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 @setpath(ptr noundef %0, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6)
  tail call void @setpath(ptr noundef %0, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9)
  tail call void @lua_pushlstring(ptr noundef %0, ptr noundef nonnull @.str.10, i64 noundef 9) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.11) #2
  %8 = tail call ptr @luaL_findtable(ptr noundef %0, i32 noundef -10000, ptr noundef nonnull @.str.12, i32 noundef 2) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.13) #2
  tail call void @lua_createtable(ptr noundef %0, i32 noundef 0, i32 noundef 0) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef nonnull @.str.14) #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 @ll_funcs) #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 void @lua_pushcclosure(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @gctm(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

; Function Attrs: nounwind uwtable
declare hidden void @setpath(ptr noundef, ptr noundef, ptr noundef, ptr 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

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, !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