; 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.GG_State = type { %struct.lua_State, %struct.global_State, %struct.jit_State, [64 x i16], [243 x ptr], [57 x 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, %struct.MRef, i32 }
%union.anon = type { %union.TValue }
%struct.jit_State = type { %struct.GCtrace, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i8, i8, %struct.IRType1, i8, %struct.FoldState, ptr, i32, i32, i32, i32, i32, i32, i32, %struct.MRef, [5 x %union.TValue], ptr, i32, i32, i32, i32, ptr, ptr, i32, i32, i8, ptr, i32, i32, ptr, [100 x i16], [255 x i32], [15 x i32], [16 x ptr], [64 x %struct.HotPenalty], i32, i32, [16 x %struct.BPropEntry], i32, %struct.ScEvEntry, ptr, i32, i32, ptr, i32, i32, ptr, ptr, ptr, i64, i64, %union.TValue, ptr, i32, i32 }
%struct.GCtrace = type { %struct.GCRef, i8, i8, i8, i8, i32, %struct.GCRef, ptr, i32, i16, i16, ptr, ptr, %struct.GCRef, %struct.MRef, i32, i32, ptr, i32, i16, i16, i16, i16, i16, i16, i16, i8, i8 }
%struct.IRType1 = type { i8 }
%struct.FoldState = type { %union.IRIns, %union.IRIns, %union.IRIns }
%union.IRIns = type { %struct.anon.7 }
%struct.anon.7 = type { i32, %struct.IRType1, i8, i8, i8 }
%struct.HotPenalty = type { %struct.MRef, i16, i16 }
%struct.BPropEntry = type { i16, i16, i32 }
%struct.ScEvEntry = type { %struct.MRef, i16, i16, i16, i16, %struct.IRType1, i8 }

; 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
define hidden void @lj_err_throw(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.lua_State, ptr %6, i32 0, i32 0
  %8 = getelementptr inbounds %struct.anon.5, ptr %7, i32 0, i32 5
  %9 = getelementptr inbounds %struct.MRef, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = zext i32 %10 to i64
  %12 = inttoptr i64 %11 to ptr
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 -384
  %15 = getelementptr inbounds %struct.GG_State, ptr %14, i32 0, i32 2
  %16 = getelementptr inbounds %struct.jit_State, ptr %15, i32 0, i32 16
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = and i32 %17, -17
  store i32 %18, ptr %16, align 4, !tbaa !12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.global_State, ptr %19, i32 0, i32 27
  %21 = getelementptr inbounds %struct.MRef, ptr %20, i32 0, i32 0
  store i32 0, ptr %21, align 4, !tbaa !30
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_State, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon.5, ptr %23, i32 0, i32 4
  store i8 0, ptr %24, align 1, !tbaa !11
  %25 = load i32, ptr %4, align 4, !tbaa !9
  call void @err_raise_ext(i32 noundef %25)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.lua_State, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon.5, 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 23
  %34 = load ptr, ptr %33, align 8, !tbaa !31
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %48

36:                                               ; preds = %2
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.lua_State, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.anon.5, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds %struct.MRef, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = zext i32 %41 to i64
  %43 = inttoptr i64 %42 to ptr
  %44 = getelementptr inbounds %struct.global_State, ptr %43, i32 0, i32 23
  %45 = load ptr, ptr %44, align 8, !tbaa !31
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = call i32 %45(ptr noundef %46)
  br label %48

48:                                               ; preds = %36, %2
  call void @exit(i32 noundef 1) #5
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @err_raise_ext(i32 noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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 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 #3 = { noreturn nounwind "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 }
attributes #5 = { 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 = !{!"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 988}
!13 = !{!"GG_State", !14, i64 0, !15, i64 384, !23, i64 800, !7, i64 3312, !7, i64 3440, !7, i64 5384}
!14 = !{!"lua_State", !7, i64 0}
!15 = !{!"global_State", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !16, i64 32, !10, i64 88, !19, i64 92, !20, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !17, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !21, i64 160, !22, i64 184, !10, i64 208, !10, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !10, i64 240, !10, i64 244, !17, i64 248, !18, i64 252, !18, i64 256, !7, i64 260}
!16 = !{!"GCState", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !10, i64 12, !17, i64 16, !18, i64 20, !17, i64 24, !17, i64 28, !17, i64 32, !17, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!17 = !{!"GCRef", !10, i64 0}
!18 = !{!"MRef", !10, i64 0}
!19 = !{!"SBuf", !18, i64 0, !18, i64 4, !18, i64 8, !18, i64 12}
!20 = !{!"GCstr", !17, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12}
!21 = !{!"Node", !7, i64 0, !7, i64 8, !18, i64 16, !18, i64 20}
!22 = !{!"GCupval", !17, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !18, i64 16, !10, i64 20}
!23 = !{!"jit_State", !24, i64 0, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !10, i64 140, !10, i64 144, !7, i64 148, !7, i64 149, !26, i64 150, !7, i64 151, !27, i64 152, !6, i64 176, !10, i64 184, !10, i64 188, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !18, i64 212, !7, i64 216, !6, i64 256, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !6, i64 280, !6, i64 288, !10, i64 296, !10, i64 300, !7, i64 304, !6, i64 312, !10, i64 320, !10, i64 324, !6, i64 328, !7, i64 336, !7, i64 536, !7, i64 1556, !7, i64 1616, !7, i64 1744, !10, i64 2256, !10, i64 2260, !7, i64 2264, !10, i64 2392, !28, i64 2396, !6, i64 2416, !10, i64 2424, !10, i64 2428, !6, i64 2432, !10, i64 2440, !10, i64 2444, !6, i64 2448, !6, i64 2456, !6, i64 2464, !29, i64 2472, !29, i64 2480, !7, i64 2488, !6, i64 2496, !10, i64 2504, !10, i64 2508}
!24 = !{!"GCtrace", !17, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !17, i64 12, !6, i64 16, !10, i64 24, !25, i64 28, !25, i64 30, !6, i64 32, !6, i64 40, !17, i64 48, !18, i64 52, !10, i64 56, !10, i64 60, !6, i64 64, !10, i64 72, !25, i64 76, !25, i64 78, !25, i64 80, !25, i64 82, !25, i64 84, !25, i64 86, !25, i64 88, !7, i64 90, !7, i64 91}
!25 = !{!"short", !7, i64 0}
!26 = !{!"IRType1", !7, i64 0}
!27 = !{!"FoldState", !7, i64 0, !7, i64 8, !7, i64 16}
!28 = !{!"ScEvEntry", !18, i64 0, !25, i64 4, !25, i64 6, !25, i64 8, !25, i64 10, !26, i64 12, !7, i64 13}
!29 = !{!"long", !7, i64 0}
!30 = !{!15, !10, i64 252}
!31 = !{!15, !6, i64 232}


; 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: noinline noreturn nounwind uwtable
define hidden void @lj_err_throw(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = inttoptr i64 %5 to ptr
  %7 = getelementptr inbounds i8, ptr %6, i64 604
  %8 = load i32, ptr %7, align 4, !tbaa !8
  %9 = and i32 %8, -17
  store i32 %9, ptr %7, align 4, !tbaa !8
  %10 = getelementptr inbounds i8, ptr %6, i64 252
  store i32 0, ptr %10, align 4, !tbaa !28
  %11 = getelementptr inbounds i8, ptr %0, i64 7
  store i8 0, ptr %11, align 1, !tbaa !5
  tail call void @err_raise_ext(i32 noundef %1)
  %12 = load i32, ptr %3, align 8, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = inttoptr i64 %13 to ptr
  %15 = getelementptr inbounds i8, ptr %14, i64 232
  %16 = load ptr, ptr %15, align 8, !tbaa !29
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %19, label %17

17:                                               ; preds = %2
  %18 = tail call i32 %16(ptr noundef nonnull %0) #3
  br label %19

19:                                               ; preds = %17, %2
  tail call void @exit(i32 noundef 1) #4
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @err_raise_ext(i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

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 = { 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 = { noreturn nounwind "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 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, !13, i64 988}
!9 = !{!"GG_State", !10, i64 0, !11, i64 384, !21, i64 800, !6, i64 3312, !6, i64 3440, !6, i64 5384}
!10 = !{!"lua_State", !6, i64 0}
!11 = !{!"global_State", !12, i64 0, !13, i64 8, !13, i64 12, !12, i64 16, !12, i64 24, !14, i64 32, !13, i64 88, !17, i64 92, !18, i64 108, !6, i64 124, !6, i64 125, !6, i64 126, !6, i64 127, !15, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !19, i64 160, !20, i64 184, !13, i64 208, !13, i64 212, !12, i64 216, !12, i64 224, !12, i64 232, !13, i64 240, !13, i64 244, !15, i64 248, !16, i64 252, !16, i64 256, !6, i64 260}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!"GCState", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 9, !6, i64 10, !6, i64 11, !13, i64 12, !15, i64 16, !16, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52}
!15 = !{!"GCRef", !13, i64 0}
!16 = !{!"MRef", !13, i64 0}
!17 = !{!"SBuf", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12}
!18 = !{!"GCstr", !15, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !13, i64 8, !13, i64 12}
!19 = !{!"Node", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 20}
!20 = !{!"GCupval", !15, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !6, i64 8, !16, i64 16, !13, i64 20}
!21 = !{!"jit_State", !22, i64 0, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !13, i64 136, !13, i64 140, !13, i64 144, !6, i64 148, !6, i64 149, !24, i64 150, !6, i64 151, !25, i64 152, !12, i64 176, !13, i64 184, !13, i64 188, !13, i64 192, !13, i64 196, !13, i64 200, !13, i64 204, !13, i64 208, !16, i64 212, !6, i64 216, !12, i64 256, !13, i64 264, !13, i64 268, !13, i64 272, !13, i64 276, !12, i64 280, !12, i64 288, !13, i64 296, !13, i64 300, !6, i64 304, !12, i64 312, !13, i64 320, !13, i64 324, !12, i64 328, !6, i64 336, !6, i64 536, !6, i64 1556, !6, i64 1616, !6, i64 1744, !13, i64 2256, !13, i64 2260, !6, i64 2264, !13, i64 2392, !26, i64 2396, !12, i64 2416, !13, i64 2424, !13, i64 2428, !12, i64 2432, !13, i64 2440, !13, i64 2444, !12, i64 2448, !12, i64 2456, !12, i64 2464, !27, i64 2472, !27, i64 2480, !6, i64 2488, !12, i64 2496, !13, i64 2504, !13, i64 2508}
!22 = !{!"GCtrace", !15, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !13, i64 8, !15, i64 12, !12, i64 16, !13, i64 24, !23, i64 28, !23, i64 30, !12, i64 32, !12, i64 40, !15, i64 48, !16, i64 52, !13, i64 56, !13, i64 60, !12, i64 64, !13, i64 72, !23, i64 76, !23, i64 78, !23, i64 80, !23, i64 82, !23, i64 84, !23, i64 86, !23, i64 88, !6, i64 90, !6, i64 91}
!23 = !{!"short", !6, i64 0}
!24 = !{!"IRType1", !6, i64 0}
!25 = !{!"FoldState", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = !{!"ScEvEntry", !16, i64 0, !23, i64 4, !23, i64 6, !23, i64 8, !23, i64 10, !24, i64 12, !6, i64 13}
!27 = !{!"long", !6, i64 0}
!28 = !{!11, !13, i64 252}
!29 = !{!11, !12, i64 232}


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