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

; 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.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.GCRef = type { i32 }
%struct.IRType1 = type { i8 }
%struct.FoldState = type { %union.IRIns, %union.IRIns, %union.IRIns }
%union.IRIns = type { %struct.anon.0 }
%struct.anon.0 = type { i32, %struct.IRType1, i8, i8, i8 }
%struct.MRef = type { i32 }
%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 }
%union.TValue = type { i64 }

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

; Function Attrs: nounwind uwtable
declare hidden void @mcode_allocarea(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @lj_mcode_abort(ptr noundef) #1

; Function Attrs: noreturn nounwind uwtable
define hidden void @lj_mcode_limiterr(ptr noundef %0, i64 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  call void @lj_mcode_abort(ptr noundef %7)
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.jit_State, ptr %8, i32 0, i32 40
  %10 = getelementptr inbounds [15 x i32], ptr %9, i64 0, i64 13
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = shl i64 %12, 10
  store i64 %13, ptr %5, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = add i64 %14, 4096
  %16 = sub i64 %15, 1
  %17 = and i64 %16, -4096
  store i64 %17, ptr %5, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.jit_State, ptr %18, i32 0, i32 40
  %20 = getelementptr inbounds [15 x i32], ptr %19, i64 0, i64 14
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = shl i64 %22, 10
  store i64 %23, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = icmp ugt i64 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %2
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  call void @lj_trace_err(ptr noundef %28, i32 noundef 28) #5
  unreachable

29:                                               ; preds = %2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.jit_State, ptr %30, i32 0, i32 58
  %32 = load i64, ptr %31, align 8, !tbaa !13
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = add i64 %32, %33
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp ugt i64 %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %29
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @lj_trace_err(ptr noundef %38, i32 noundef 27) #5
  unreachable

39:                                               ; preds = %29
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mcode_allocarea(ptr noundef %40)
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  call void @lj_trace_err(ptr noundef %41, i32 noundef 29) #5
  unreachable
}

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

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 = { 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 #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 }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 2480}
!14 = !{!"jit_State", !15, i64 0, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !12, i64 140, !12, i64 144, !7, i64 148, !7, i64 149, !19, i64 150, !7, i64 151, !20, i64 152, !6, i64 176, !12, i64 184, !12, i64 188, !12, i64 192, !12, i64 196, !12, i64 200, !12, i64 204, !12, i64 208, !18, i64 212, !7, i64 216, !6, i64 256, !12, i64 264, !12, i64 268, !12, i64 272, !12, i64 276, !6, i64 280, !6, i64 288, !12, i64 296, !12, i64 300, !7, i64 304, !6, i64 312, !12, i64 320, !12, i64 324, !6, i64 328, !7, i64 336, !7, i64 536, !7, i64 1556, !7, i64 1616, !7, i64 1744, !12, i64 2256, !12, i64 2260, !7, i64 2264, !12, i64 2392, !21, i64 2396, !6, i64 2416, !12, i64 2424, !12, i64 2428, !6, i64 2432, !12, i64 2440, !12, i64 2444, !6, i64 2448, !6, i64 2456, !6, i64 2464, !10, i64 2472, !10, i64 2480, !7, i64 2488, !6, i64 2496, !12, i64 2504, !12, i64 2508}
!15 = !{!"GCtrace", !16, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !12, i64 8, !16, i64 12, !6, i64 16, !12, i64 24, !17, i64 28, !17, i64 30, !6, i64 32, !6, i64 40, !16, i64 48, !18, i64 52, !12, i64 56, !12, i64 60, !6, i64 64, !12, i64 72, !17, i64 76, !17, i64 78, !17, i64 80, !17, i64 82, !17, i64 84, !17, i64 86, !17, i64 88, !7, i64 90, !7, i64 91}
!16 = !{!"GCRef", !12, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"MRef", !12, i64 0}
!19 = !{!"IRType1", !7, i64 0}
!20 = !{!"FoldState", !7, i64 0, !7, i64 8, !7, i64 16}
!21 = !{!"ScEvEntry", !18, i64 0, !17, i64 4, !17, i64 6, !17, i64 8, !17, i64 10, !19, i64 12, !7, i64 13}


; 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 void @mcode_allocarea(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @lj_mcode_abort(ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind uwtable
define hidden void @lj_mcode_limiterr(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  tail call void @lj_mcode_abort(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 1608
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 10
  %7 = add nsw i64 %6, 4095
  %8 = and i64 %7, -4096
  %9 = icmp ult i64 %8, %1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  tail call void @lj_trace_err(ptr noundef nonnull %0, i32 noundef 28) #3
  unreachable

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 1612
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = shl nsw i64 %14, 10
  %16 = getelementptr inbounds i8, ptr %0, i64 2480
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = add i64 %17, %8
  %19 = icmp ugt i64 %18, %15
  br i1 %19, label %20, label %21

20:                                               ; preds = %11
  tail call void @lj_trace_err(ptr noundef nonnull %0, i32 noundef 27) #3
  unreachable

21:                                               ; preds = %11
  tail call void @mcode_allocarea(ptr noundef nonnull %0)
  tail call void @lj_trace_err(ptr noundef nonnull %0, i32 noundef 29) #3
  unreachable
}

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

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 = { 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 = { 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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !19, i64 2480}
!10 = !{!"jit_State", !11, i64 0, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !6, i64 136, !6, i64 140, !6, i64 144, !7, i64 148, !7, i64 149, !16, i64 150, !7, i64 151, !17, i64 152, !13, i64 176, !6, i64 184, !6, i64 188, !6, i64 192, !6, i64 196, !6, i64 200, !6, i64 204, !6, i64 208, !15, i64 212, !7, i64 216, !13, i64 256, !6, i64 264, !6, i64 268, !6, i64 272, !6, i64 276, !13, i64 280, !13, i64 288, !6, i64 296, !6, i64 300, !7, i64 304, !13, i64 312, !6, i64 320, !6, i64 324, !13, i64 328, !7, i64 336, !7, i64 536, !7, i64 1556, !7, i64 1616, !7, i64 1744, !6, i64 2256, !6, i64 2260, !7, i64 2264, !6, i64 2392, !18, i64 2396, !13, i64 2416, !6, i64 2424, !6, i64 2428, !13, i64 2432, !6, i64 2440, !6, i64 2444, !13, i64 2448, !13, i64 2456, !13, i64 2464, !19, i64 2472, !19, i64 2480, !7, i64 2488, !13, i64 2496, !6, i64 2504, !6, i64 2508}
!11 = !{!"GCtrace", !12, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !6, i64 8, !12, i64 12, !13, i64 16, !6, i64 24, !14, i64 28, !14, i64 30, !13, i64 32, !13, i64 40, !12, i64 48, !15, i64 52, !6, i64 56, !6, i64 60, !13, i64 64, !6, i64 72, !14, i64 76, !14, i64 78, !14, i64 80, !14, i64 82, !14, i64 84, !14, i64 86, !14, i64 88, !7, i64 90, !7, i64 91}
!12 = !{!"GCRef", !6, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"MRef", !6, i64 0}
!16 = !{!"IRType1", !7, i64 0}
!17 = !{!"FoldState", !7, i64 0, !7, i64 8, !7, i64 16}
!18 = !{!"ScEvEntry", !15, i64 0, !14, i64 4, !14, i64 6, !14, i64 8, !14, i64 10, !16, i64 12, !7, i64 13}
!19 = !{!"long", !7, i64 0}


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