; 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.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 }
%struct.GCRef = type { i32 }
%struct.anon = type { %union.anon.0, i32 }
%union.anon.0 = type { %struct.GCRef }
%struct.anon.1 = type { %struct.GCRef, %union.FrameLink }
%union.FrameLink = type { i32 }
%union.TValue = type { i64 }

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

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @lj_err_optype(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: noinline noreturn nounwind uwtable
define hidden void @lj_err_optype_call(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.lua_State, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds %struct.anon.5, ptr %8, i32 0, i32 13
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = ptrtoint ptr %10 to i64
  %12 = and i64 %11, -4
  %13 = inttoptr i64 %12 to ptr
  %14 = getelementptr inbounds i8, ptr %13, i64 28
  %15 = getelementptr inbounds %struct.MRef, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = zext i32 %16 to i64
  %18 = inttoptr i64 %17 to ptr
  store ptr %18, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = and i64 %20, 3
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %70

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.anon, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp ule i32 %26, -65537
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  br label %43

29:                                               ; preds = %23
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.anon, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = ashr i32 %32, 15
  %34 = icmp eq i32 %33, -2
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  br label %41

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.anon, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = xor i32 %39, -1
  br label %41

41:                                               ; preds = %36, %35
  %42 = phi i32 [ 3, %35 ], [ %40, %36 ]
  br label %43

43:                                               ; preds = %41, %28
  %44 = phi i32 [ 13, %28 ], [ %42, %41 ]
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  store ptr %47, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = ptrtoint ptr %48 to i64
  %50 = trunc i64 %49 to i32
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.anon.1, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.MRef, ptr %52, i32 0, i32 0
  store i32 %50, ptr %53, align 4, !tbaa !9
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = ptrtoint ptr %54 to i64
  %56 = trunc i64 %55 to i32
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.anon.1, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %struct.GCRef, ptr %58, i32 0, i32 0
  store i32 %56, ptr %59, align 8, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %union.TValue, ptr %60, i64 1
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.lua_State, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds %struct.anon.5, ptr %63, i32 0, i32 7
  store ptr %61, ptr %64, align 8, !tbaa !9
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lua_State, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.anon.5, ptr %66, i32 0, i32 8
  store ptr %61, ptr %67, align 8, !tbaa !9
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void (ptr, i32, ...) @err_msgv(ptr noundef %68, i32 noundef 214, ptr noundef %69) #3
  unreachable

70:                                               ; preds = %2
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lj_err_optype(ptr noundef %71, ptr noundef %72, i32 noundef 398) #3
  unreachable
}

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 = { nounwind }
attributes #3 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"MRef", !12, i64 0}
!12 = !{!"int", !7, 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_obj_itypename = external hidden local_unnamed_addr constant [14 x ptr], align 16

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

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @lj_err_optype(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: noinline noreturn nounwind uwtable
define hidden void @lj_err_optype_call(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = ptrtoint ptr %4 to i64
  %6 = and i64 %5, -4
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %7, i64 28
  %9 = load i32, ptr %8, align 4, !tbaa !8
  %10 = and i32 %9, 3
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %29, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ult i32 %13, -65536
  br i1 %14, label %20, label %15

15:                                               ; preds = %11
  %.mask = and i32 %13, -32768
  %16 = icmp eq i32 %.mask, -65536
  br i1 %16, label %20, label %17

17:                                               ; preds = %15
  %18 = xor i32 %13, -1
  %19 = zext nneg i32 %18 to i64
  br label %20

20:                                               ; preds = %17, %15, %11
  %21 = phi i64 [ 13, %11 ], [ %19, %17 ], [ 3, %15 ]
  %22 = getelementptr inbounds [14 x ptr], ptr @lj_obj_itypename, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  store i32 %9, ptr %12, align 4, !tbaa !5
  %24 = ptrtoint ptr %0 to i64
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %1, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %26, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %26, ptr %28, align 8, !tbaa !5
  tail call void (ptr, i32, ...) @err_msgv(ptr noundef nonnull %0, i32 noundef 214, ptr noundef %23) #1
  unreachable

29:                                               ; preds = %2
  tail call void @lj_err_optype(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 398) #1
  unreachable
}

attributes #0 = { 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 #1 = { 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, !10, i64 0}
!9 = !{!"MRef", !10, i64 0}
!10 = !{!"int", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !6, i64 0}


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