; 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 }
%struct.MCLink = type { ptr, i64 }

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_mcode_patch(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %37

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.jit_State, ptr %13, i32 0, i32 54
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %15, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mcode_protect(ptr noundef %19, i32 noundef 5)
  br label %36

20:                                               ; preds = %12
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MCLink, ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !21
  %25 = call i32 @mcode_setprot(ptr noundef %21, i64 noundef %24, i32 noundef 5)
  %26 = icmp ne i32 %25, 0
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = zext i1 %28 to i32
  %30 = sext i32 %29 to i64
  %31 = call i64 @llvm.expect.i64(i64 %30, i64 0)
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %20
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mcode_protfail(ptr noundef %34)
  br label %35

35:                                               ; preds = %33, %20
  br label %36

36:                                               ; preds = %35, %18
  store ptr null, ptr %4, align 8
  br label %90

37:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.jit_State, ptr %38, i32 0, i32 54
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp uge ptr %41, %42
  br i1 %43, label %44, label %55

44:                                               ; preds = %37
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.jit_State, ptr %47, i32 0, i32 57
  %49 = load i64, ptr %48, align 8, !tbaa !23
  %50 = getelementptr inbounds i8, ptr %46, i64 %49
  %51 = icmp ult ptr %45, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %44
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mcode_protect(ptr noundef %53, i32 noundef 3)
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %54, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %89

55:                                               ; preds = %44, %37
  br label %56

56:                                               ; preds = %88, %55
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.MCLink, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !24
  store ptr %59, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = icmp uge ptr %60, %61
  br i1 %62, label %63, label %88

63:                                               ; preds = %56
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.MCLink, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !21
  %69 = getelementptr inbounds i8, ptr %65, i64 %68
  %70 = icmp ult ptr %64, %69
  br i1 %70, label %71, label %88

71:                                               ; preds = %63
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.MCLink, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %74, align 8, !tbaa !21
  %76 = call i32 @mcode_setprot(ptr noundef %72, i64 noundef %75, i32 noundef 3)
  %77 = icmp ne i32 %76, 0
  %78 = xor i1 %77, true
  %79 = xor i1 %78, true
  %80 = zext i1 %79 to i32
  %81 = sext i32 %80 to i64
  %82 = call i64 @llvm.expect.i64(i64 %81, i64 0)
  %83 = icmp ne i64 %82, 0
  br i1 %83, label %84, label %86

84:                                               ; preds = %71
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mcode_protfail(ptr noundef %85)
  br label %86

86:                                               ; preds = %84, %71
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %87, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %89

88:                                               ; preds = %63, %56
  br label %56

89:                                               ; preds = %86, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %90

90:                                               ; preds = %89, %36
  %91 = load ptr, ptr %4, align 8
  ret ptr %91
}

; Function Attrs: nounwind uwtable
declare hidden i32 @mcode_setprot(ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

; Function Attrs: noinline nounwind uwtable
declare hidden void @mcode_protfail(ptr 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { noinline 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 #4 = { 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 = !{!12, !6, i64 2448}
!12 = !{!"jit_State", !13, 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, !17, i64 150, !7, i64 151, !18, 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, !16, 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, !19, 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, !20, i64 2472, !20, i64 2480, !7, i64 2488, !6, i64 2496, !10, i64 2504, !10, i64 2508}
!13 = !{!"GCtrace", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !14, i64 12, !6, i64 16, !10, i64 24, !15, i64 28, !15, i64 30, !6, i64 32, !6, i64 40, !14, i64 48, !16, i64 52, !10, i64 56, !10, i64 60, !6, i64 64, !10, i64 72, !15, i64 76, !15, i64 78, !15, i64 80, !15, i64 82, !15, i64 84, !15, i64 86, !15, i64 88, !7, i64 90, !7, i64 91}
!14 = !{!"GCRef", !10, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"MRef", !10, i64 0}
!17 = !{!"IRType1", !7, i64 0}
!18 = !{!"FoldState", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!"ScEvEntry", !16, i64 0, !15, i64 4, !15, i64 6, !15, i64 8, !15, i64 10, !17, i64 12, !7, i64 13}
!20 = !{!"long", !7, i64 0}
!21 = !{!22, !20, i64 8}
!22 = !{!"MCLink", !6, i64 0, !20, i64 8}
!23 = !{!12, !20, i64 2472}
!24 = !{!22, !6, 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 void @mcode_protect(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden ptr @lj_mcode_patch(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  %4 = getelementptr inbounds i8, ptr %0, i64 2448
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  br i1 %.not, label %14, label %6

6:                                                ; preds = %3
  %7 = icmp eq ptr %5, %1
  br i1 %7, label %8, label %9

8:                                                ; preds = %6
  tail call void @mcode_protect(ptr noundef nonnull %0, i32 noundef 5)
  br label %31

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !19
  %12 = tail call i32 @mcode_setprot(ptr noundef %1, i64 noundef %11, i32 noundef 5)
  %.not33 = icmp eq i32 %12, 0
  br i1 %.not33, label %31, label %13, !prof !21

13:                                               ; preds = %9
  tail call void @mcode_protfail(ptr noundef nonnull %0)
  br label %31

14:                                               ; preds = %3
  %.not30 = icmp ugt ptr %5, %1
  br i1 %.not30, label %.preheader, label %15

.preheader:                                       ; preds = %15, %14
  br label %21

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 2472
  %17 = load i64, ptr %16, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %5, i64 %17
  %19 = icmp ugt ptr %18, %1
  br i1 %19, label %20, label %.preheader

20:                                               ; preds = %15
  tail call void @mcode_protect(ptr noundef nonnull %0, i32 noundef 3)
  br label %31

21:                                               ; preds = %.backedge, %.preheader
  %.0 = phi ptr [ %5, %.preheader ], [ %22, %.backedge ]
  %22 = load ptr, ptr %.0, align 8, !tbaa !23
  %.not31 = icmp ugt ptr %22, %1
  br i1 %.not31, label %.backedge, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %22, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %22, i64 %25
  %27 = icmp ugt ptr %26, %1
  br i1 %27, label %28, label %.backedge

.backedge:                                        ; preds = %23, %21
  br label %21

28:                                               ; preds = %23
  %29 = tail call i32 @mcode_setprot(ptr noundef nonnull %22, i64 noundef %25, i32 noundef 3)
  %.not32 = icmp eq i32 %29, 0
  br i1 %.not32, label %31, label %30, !prof !21

30:                                               ; preds = %28
  tail call void @mcode_protfail(ptr noundef %0)
  br label %31

31:                                               ; preds = %20, %30, %28, %8, %13, %9
  %.1 = phi ptr [ null, %9 ], [ null, %13 ], [ null, %8 ], [ %5, %20 ], [ %22, %30 ], [ %22, %28 ]
  ret ptr %.1
}

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

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

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 = { noinline 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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass