; LLVM IR from seppo0010/rlite :: deps/lua/src (lua_cmsgpack)

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

@cmds = external hidden constant [5 x %struct.luaL_Reg], align 16
@.str.4 = external hidden unnamed_addr constant [14 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 i32 @luaopen_cmsgpack(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @luaopen_cmsgpack_safe(ptr noundef %0) #1 {
  %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 @luaopen_cmsgpack(ptr noundef %4)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %24, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = icmp ult i64 %8, 4
  br i1 %9, label %10, label %27

10:                                               ; preds = %6
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [5 x %struct.luaL_Reg], ptr @cmds, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.luaL_Reg, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 16, !tbaa !11
  call void @lua_getfield(ptr noundef %11, i32 noundef -1, ptr noundef %16)
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushcclosure(ptr noundef %17, ptr noundef @mp_safe, i32 noundef 1)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5 x %struct.luaL_Reg], ptr @cmds, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.luaL_Reg, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 16, !tbaa !11
  call void @lua_setfield(ptr noundef %18, i32 noundef -2, ptr noundef %23)
  br label %24

24:                                               ; preds = %10
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !13

27:                                               ; preds = %6
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_pushvalue(ptr noundef %28, i32 noundef -1)
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lua_setfield(ptr noundef %29, i32 noundef -10002, ptr noundef @.str.4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 1
}

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

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

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

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


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

@cmds = external hidden local_unnamed_addr constant [5 x %struct.luaL_Reg], align 16
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @luaopen_cmsgpack_safe(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @luaopen_cmsgpack(ptr noundef %0)
  %3 = load ptr, ptr @cmds, align 16, !tbaa !5
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -1, ptr noundef %3) #2
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull @mp_safe, i32 noundef 1) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef %3) #2
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @cmds, i64 16), align 16, !tbaa !5
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -1, ptr noundef %4) #2
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull @mp_safe, i32 noundef 1) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef %4) #2
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @cmds, i64 32), align 16, !tbaa !5
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -1, ptr noundef %5) #2
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull @mp_safe, i32 noundef 1) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef %5) #2
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @cmds, i64 48), align 16, !tbaa !5
  tail call void @lua_getfield(ptr noundef %0, i32 noundef -1, ptr noundef %6) #2
  tail call void @lua_pushcclosure(ptr noundef %0, ptr noundef nonnull @mp_safe, i32 noundef 1) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -2, ptr noundef %6) #2
  tail call void @lua_pushvalue(ptr noundef %0, i32 noundef -1) #2
  tail call void @lua_setfield(ptr noundef %0, i32 noundef -10002, ptr noundef nonnull @.str.4) #2
  ret i32 1
}

declare void @lua_getfield(ptr noundef, i32 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 @mp_safe(ptr noundef) #0

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass