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

; 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 = type { %union.anon.0, i32 }
%union.anon.0 = type { %struct.GCRef }
%struct.GCRef = type { i32 }
%struct.lua_State = type { %union.anon.4 }
%union.anon.4 = type { %struct.anon.5, [320 x i8] }
%struct.anon.5 = 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 }
%union.TValue = type { i64 }
%struct.anon.1 = type { %struct.GCRef, %union.FrameLink }
%union.FrameLink = type { i32 }
%struct.GCfuncC = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, ptr, [1 x %union.TValue] }
%struct.GCfuncL = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.MRef, [1 x %struct.GCRef] }

@lj_err_allmsg = external hidden global ptr, align 8
@lj_obj_itypename = external hidden constant [14 x ptr], align 16

; 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: noinline noreturn nounwind uwtable
declare dso_local void @err_msgv(ptr noundef, i32 noundef, ...) #1

; Function Attrs: noinline noreturn nounwind uwtable
define hidden void @lj_err_optype(ptr noundef %0, ptr noundef %1, i32 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 ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp ule i32 %15, -65537
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  br label %32

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = ashr i32 %21, 15
  %23 = icmp eq i32 %22, -2
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  br label %30

25:                                               ; preds = %18
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.anon, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = xor i32 %28, -1
  br label %30

30:                                               ; preds = %25, %24
  %31 = phi i32 [ 3, %24 ], [ %29, %25 ]
  br label %32

32:                                               ; preds = %30, %17
  %33 = phi i32 [ 13, %17 ], [ %31, %30 ]
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  store ptr %36, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %37 = load ptr, ptr @lj_err_allmsg, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.lua_State, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.anon.5, ptr %42, i32 0, i32 7
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds %union.TValue, ptr %44, i64 -1
  %46 = getelementptr inbounds %struct.anon.1, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds %struct.GCRef, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = inttoptr i64 %49 to ptr
  %51 = getelementptr inbounds %struct.GCfuncC, ptr %50, i32 0, i32 3
  %52 = load i8, ptr %51, align 2, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %107

55:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lua_State, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.anon.5, ptr %57, i32 0, i32 7
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = getelementptr inbounds %union.TValue, ptr %59, i64 -1
  %61 = getelementptr inbounds %struct.anon.1, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.GCRef, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = zext i32 %63 to i64
  %65 = inttoptr i64 %64 to ptr
  %66 = getelementptr inbounds %struct.GCfuncL, ptr %65, i32 0, i32 7
  %67 = getelementptr inbounds %struct.MRef, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !11
  %69 = zext i32 %68 to i64
  %70 = inttoptr i64 %69 to ptr
  %71 = getelementptr inbounds i8, ptr %70, i64 -64
  store ptr %71, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.lua_State, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.anon.5, ptr %73, i32 0, i32 13
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = ptrtoint ptr %75 to i64
  %77 = and i64 %76, -4
  %78 = inttoptr i64 %77 to ptr
  %79 = getelementptr inbounds i8, ptr %78, i64 28
  %80 = getelementptr inbounds %struct.MRef, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 4, !tbaa !12
  %82 = zext i32 %81 to i64
  %83 = inttoptr i64 %82 to ptr
  %84 = getelementptr inbounds i32, ptr %83, i64 -1
  store ptr %84, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.lua_State, ptr %88, i32 0, i32 0
  %90 = getelementptr inbounds %struct.anon.5, ptr %89, i32 0, i32 7
  %91 = load ptr, ptr %90, align 8, !tbaa !11
  %92 = ptrtoint ptr %87 to i64
  %93 = ptrtoint ptr %91 to i64
  %94 = sub i64 %92, %93
  %95 = sdiv exact i64 %94, 8
  %96 = trunc i64 %95 to i32
  %97 = call ptr @lj_debug_slotname(ptr noundef %85, ptr noundef %86, i32 noundef %96, ptr noundef %11)
  store ptr %97, ptr %12, align 8, !tbaa !5
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = icmp ne ptr %98, null
  br i1 %99, label %100, label %106

100:                                              ; preds = %55
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  %104 = load ptr, ptr %11, align 8, !tbaa !5
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  call void (ptr, i32, ...) @err_msgv(ptr noundef %101, i32 noundef 241, ptr noundef %102, ptr noundef %103, ptr noundef %104, ptr noundef %105) #4
  unreachable

106:                                              ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %107

107:                                              ; preds = %106, %32
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  call void (ptr, i32, ...) @err_msgv(ptr noundef %108, i32 noundef 276, ptr noundef %109, ptr noundef %110) #4
  unreachable
}

declare hidden ptr @lj_debug_slotname(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn 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 }
attributes #4 = { 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 0}
!13 = !{!"MRef", !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"

@lj_err_allmsg = external hidden local_unnamed_addr global ptr, align 8
@lj_obj_itypename = external hidden local_unnamed_addr constant [14 x ptr], align 16

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

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

; Function Attrs: noinline noreturn nounwind uwtable
declare dso_local void @err_msgv(ptr noundef, i32 noundef, ...) local_unnamed_addr #1

; Function Attrs: noinline noreturn nounwind uwtable
define hidden void @lj_err_optype(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp ult i32 %6, -65536
  br i1 %7, label %13, label %8

8:                                                ; preds = %3
  %.mask = and i32 %6, -32768
  %9 = icmp eq i32 %.mask, -65536
  br i1 %9, label %13, label %10

10:                                               ; preds = %8
  %11 = xor i32 %6, -1
  %12 = zext nneg i32 %11 to i64
  br label %13

13:                                               ; preds = %10, %8, %3
  %14 = phi i64 [ 13, %3 ], [ %12, %10 ], [ 3, %8 ]
  %15 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !8
  %17 = load ptr, ptr @lj_err_allmsg, align 8, !tbaa !8
  %18 = sext i32 %2 to i64
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 -8
  %23 = load i32, ptr %22, align 8, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  %26 = getelementptr inbounds i8, ptr %25, i64 6
  %27 = load i8, ptr %26, align 2, !tbaa !5
  %28 = icmp eq i8 %27, 0
  br i1 %28, label %29, label %54

29:                                               ; preds = %13
  %30 = getelementptr inbounds i8, ptr %25, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = inttoptr i64 %32 to ptr
  %34 = getelementptr inbounds i8, ptr %33, i64 -64
  %35 = getelementptr inbounds i8, ptr %0, i64 48
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = ptrtoint ptr %36 to i64
  %38 = and i64 %37, -4
  %39 = inttoptr i64 %38 to ptr
  %40 = getelementptr inbounds i8, ptr %39, i64 28
  %41 = load i32, ptr %40, align 4, !tbaa !10
  %42 = zext i32 %41 to i64
  %43 = inttoptr i64 %42 to ptr
  %44 = getelementptr inbounds i8, ptr %43, i64 -4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !8
  %45 = ptrtoint ptr %1 to i64
  %46 = ptrtoint ptr %21 to i64
  %47 = sub i64 %45, %46
  %48 = lshr exact i64 %47, 3
  %49 = trunc i64 %48 to i32
  %50 = call ptr @lj_debug_slotname(ptr noundef nonnull %34, ptr noundef nonnull %44, i32 noundef %49, ptr noundef nonnull %4) #3
  %.not = icmp eq ptr %50, null
  br i1 %.not, label %53, label %51

51:                                               ; preds = %29
  %52 = load ptr, ptr %4, align 8, !tbaa !8
  call void (ptr, i32, ...) @err_msgv(ptr noundef nonnull %0, i32 noundef 241, ptr noundef %19, ptr noundef nonnull %50, ptr noundef %52, ptr noundef %16) #4
  unreachable

53:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %54

54:                                               ; preds = %53, %13
  call void (ptr, i32, ...) @err_msgv(ptr noundef nonnull %0, i32 noundef 276, ptr noundef %19, ptr noundef %16) #4
  unreachable
}

declare hidden ptr @lj_debug_slotname(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn 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 }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"MRef", !12, i64 0}
!12 = !{!"int", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass