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

; 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.anon.0 = type { %union.anon.1, i32 }
%union.anon.1 = type { %struct.GCRef }
%struct.GCRef = type { i32 }
%struct.lua_State = type { %union.anon }
%union.anon = type { %struct.anon, [320 x i8] }
%struct.anon = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.MRef = type { i32 }
%struct.global_State = type { ptr, i32, i32, ptr, ptr, %struct.GCState, i32, %struct.SBuf, %struct.GCstr, i8, i8, i8, i8, %struct.GCRef, %union.TValue, %union.TValue, %union.TValue, %struct.Node, %struct.GCupval, i32, i32, ptr, ptr, ptr, i32, i32, %struct.GCRef, %struct.MRef, %struct.MRef, [38 x %struct.GCRef] }
%struct.GCState = type { i32, i32, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, i32, i32, i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%union.TValue = type { i64 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.4, %struct.MRef, i32 }
%union.anon.4 = type { %union.TValue }
%struct.GCudata = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, i32, %struct.GCRef, i32 }

; 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 hidden ptr @index2adr(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare hidden ptr @lj_str_new(ptr noundef, ptr noundef, i64 noundef) #3

declare hidden ptr @lj_tab_getstr(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @luaL_checkudata(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = call ptr @index2adr(ptr noundef %12, i32 noundef %13)
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.anon.0, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp eq i32 %17, -13
  br i1 %18, label %19, label %73

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.anon.0, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.GCRef, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  store ptr %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.lua_State, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds %struct.MRef, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = zext i32 %30 to i64
  %32 = inttoptr i64 %31 to ptr
  %33 = getelementptr inbounds %struct.global_State, ptr %32, i32 0, i32 14
  %34 = getelementptr inbounds %struct.anon.0, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.GCRef, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = inttoptr i64 %37 to ptr
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i64 @strlen(ptr noundef %41) #6
  %43 = call ptr @lj_str_new(ptr noundef %39, ptr noundef %40, i64 noundef %42)
  %44 = call ptr @lj_tab_getstr(ptr noundef %38, ptr noundef %43)
  store ptr %44, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %69

47:                                               ; preds = %19
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.anon.0, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = icmp eq i32 %50, -12
  br i1 %51, label %52, label %69

52:                                               ; preds = %47
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.anon.0, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.GCRef, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !11
  %57 = zext i32 %56 to i64
  %58 = inttoptr i64 %57 to ptr
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.GCudata, ptr %59, i32 0, i32 7
  %61 = getelementptr inbounds %struct.GCRef, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 4, !tbaa !12
  %63 = zext i32 %62 to i64
  %64 = inttoptr i64 %63 to ptr
  %65 = icmp eq ptr %58, %64
  br i1 %65, label %66, label %69

66:                                               ; preds = %52
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.GCudata, ptr %67, i64 1
  store ptr %68, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %70

69:                                               ; preds = %52, %47, %19
  store i32 0, ptr %11, align 4
  br label %70

70:                                               ; preds = %69, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %71 = load i32, ptr %11, align 4
  switch i32 %71, label %77 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72, %3
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  call void @lj_err_argtype(ptr noundef %74, i32 noundef %75, ptr noundef %76) #7
  unreachable

77:                                               ; preds = %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %78 = load ptr, ptr %4, align 8
  ret ptr %78
}

; Function Attrs: noreturn
declare hidden void @lj_err_argtype(ptr noundef, i32 noundef, ptr noundef) #4

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 = { nounwind willreturn memory(read) "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 = { "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 16}
!13 = !{!"GCudata", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !14, i64 8, !10, i64 12, !14, i64 16, !10, i64 20}
!14 = !{!"GCRef", !10, i64 0}


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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

declare hidden ptr @lj_str_new(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare hidden ptr @lj_tab_getstr(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local nonnull ptr @luaL_checkudata(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @index2adr(ptr noundef %0, i32 noundef %1)
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, -13
  br i1 %7, label %8, label %.thread

8:                                                ; preds = %3
  %9 = load i32, ptr %4, align 8, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = inttoptr i64 %10 to ptr
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = getelementptr inbounds i8, ptr %15, i64 136
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = zext i32 %17 to i64
  %19 = inttoptr i64 %18 to ptr
  %20 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #4
  %21 = tail call ptr @lj_str_new(ptr noundef %0, ptr noundef %2, i64 noundef %20) #5
  %22 = tail call ptr @lj_tab_getstr(ptr noundef %19, ptr noundef %21) #5
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %.thread, label %23

23:                                               ; preds = %8
  %24 = getelementptr inbounds i8, ptr %22, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %25, -12
  br i1 %26, label %27, label %.thread

27:                                               ; preds = %23
  %28 = load i32, ptr %22, align 8, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = inttoptr i64 %29 to ptr
  %31 = getelementptr inbounds i8, ptr %11, i64 16
  %32 = load i32, ptr %31, align 4, !tbaa !8
  %33 = zext i32 %32 to i64
  %34 = inttoptr i64 %33 to ptr
  %.not22 = icmp eq ptr %30, %34
  br i1 %.not22, label %35, label %.thread

.thread:                                          ; preds = %8, %23, %27, %3
  tail call void @lj_err_argtype(ptr noundef %0, i32 noundef %1, ptr noundef %2) #6
  unreachable

35:                                               ; preds = %27
  %36 = getelementptr inbounds i8, ptr %11, i64 24
  ret ptr %36
}

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

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #5 = { nounwind }
attributes #6 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 16}
!9 = !{!"GCudata", !10, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !10, i64 8, !11, i64 12, !10, i64 16, !11, i64 20}
!10 = !{!"GCRef", !11, i64 0}
!11 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass