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

; 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.13 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [30 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: nounwind uwtable
declare dso_local i32 @luaL_error(ptr noundef, ptr noundef, ...) #1

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

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

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

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

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

declare void @lua_setfield(ptr noundef, i32 noundef, ptr 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 %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %44

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

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

30:                                               ; preds = %23
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i32 (ptr, ptr, ...) @luaL_error(ptr noundef %31, ptr noundef @.str.14, ptr noundef %32)
  br label %34

34:                                               ; preds = %30, %23
  %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, %13
  %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) #3
  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) #3
  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) #3
  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

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

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 = { 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, !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.13 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [30 x i8], align 1

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

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

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

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

declare void @lua_pushvalue(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_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 %17, 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.13, i32 noundef 1)
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -1, ptr noundef nonnull %1) #2
  %8 = tail call i32 @lua_type(ptr noundef %0, i32 noundef -1) #2
  %9 = icmp eq i32 %8, 5
  br i1 %9, label %15, label %10

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

12:                                               ; preds = %10
  %13 = tail call i32 (ptr, ptr, ...) @luaL_error(ptr noundef %0, ptr noundef nonnull @.str.14, ptr noundef nonnull %1)
  br label %14

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

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

17:                                               ; preds = %15, %4
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %.not3638 = icmp eq ptr %18, null
  br i1 %.not3638, label %._crit_edge40, label %.preheader.lr.ph

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

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %.03239.us = phi ptr [ %27, %._crit_edge.us ], [ %2, %.preheader.lr.ph ]
  br label %22

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

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

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

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

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

; 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_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 = { 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