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

; 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.GCproto = type { %struct.GCRef, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.MRef, i32, i32, i32, i8, i8, i16, %struct.GCRef, i32, i32, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCRef = type { i32 }
%struct.MRef = 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.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.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.6, %struct.MRef, i32 }
%union.anon.6 = 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.0 }
%struct.anon.0 = 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: nounwind uwtable
declare hidden void @trace_flushroot(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define hidden void @lj_trace_flushproto(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %11, %2
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.GCproto, ptr %6, i32 0, i32 14
  %8 = load i16, ptr %7, align 2, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %29

11:                                               ; preds = %5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 -384
  %14 = getelementptr inbounds %struct.GG_State, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 -384
  %17 = getelementptr inbounds %struct.GG_State, ptr %16, i32 0, i32 2
  %18 = getelementptr inbounds %struct.jit_State, ptr %17, i32 0, i32 34
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.GCproto, ptr %20, i32 0, i32 14
  %22 = load i16, ptr %21, align 2, !tbaa !9
  %23 = zext i16 %22 to i64
  %24 = getelementptr inbounds %struct.GCRef, ptr %19, i64 %23
  %25 = getelementptr inbounds %struct.GCRef, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !30
  %27 = zext i32 %26 to i64
  %28 = inttoptr i64 %27 to ptr
  call void @trace_flushroot(ptr noundef %14, ptr noundef %28)
  br label %5, !llvm.loop !31

29:                                               ; preds = %5
  ret void
}

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" }

!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, !14, i64 38}
!10 = !{!"GCproto", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !12, i64 8, !11, i64 12, !13, i64 16, !13, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !7, i64 36, !7, i64 37, !14, i64 38, !11, i64 40, !12, i64 44, !12, i64 48, !13, i64 52, !13, i64 56, !13, i64 60}
!11 = !{!"GCRef", !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"MRef", !12, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 1112}
!16 = !{!"GG_State", !17, i64 0, !18, i64 384, !24, i64 800, !7, i64 3312, !7, i64 3440, !7, i64 5384}
!17 = !{!"lua_State", !7, i64 0}
!18 = !{!"global_State", !6, i64 0, !12, i64 8, !12, i64 12, !6, i64 16, !6, i64 24, !19, i64 32, !12, i64 88, !20, i64 92, !21, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !11, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !22, i64 160, !23, i64 184, !12, i64 208, !12, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !12, i64 240, !12, i64 244, !11, i64 248, !13, i64 252, !13, i64 256, !7, i64 260}
!19 = !{!"GCState", !12, i64 0, !12, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !12, i64 12, !11, i64 16, !13, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52}
!20 = !{!"SBuf", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!21 = !{!"GCstr", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !12, i64 8, !12, i64 12}
!22 = !{!"Node", !7, i64 0, !7, i64 8, !13, i64 16, !13, i64 20}
!23 = !{!"GCupval", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !13, i64 16, !12, i64 20}
!24 = !{!"jit_State", !25, 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, !26, i64 150, !7, i64 151, !27, 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, !13, 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, !28, 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, !29, i64 2472, !29, i64 2480, !7, i64 2488, !6, i64 2496, !12, i64 2504, !12, i64 2508}
!25 = !{!"GCtrace", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !12, i64 8, !11, i64 12, !6, i64 16, !12, i64 24, !14, i64 28, !14, i64 30, !6, i64 32, !6, i64 40, !11, i64 48, !13, i64 52, !12, i64 56, !12, i64 60, !6, i64 64, !12, 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}
!26 = !{!"IRType1", !7, i64 0}
!27 = !{!"FoldState", !7, i64 0, !7, i64 8, !7, i64 16}
!28 = !{!"ScEvEntry", !13, i64 0, !14, i64 4, !14, i64 6, !14, i64 8, !14, i64 10, !26, i64 12, !7, i64 13}
!29 = !{!"long", !7, i64 0}
!30 = !{!11, !12, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}


; 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"

%struct.GCRef = type { i32 }

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

; Function Attrs: nounwind uwtable
define hidden void @lj_trace_flushproto(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 38
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %.not4 = icmp eq i16 %4, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 416
  %6 = getelementptr inbounds i8, ptr %0, i64 728
  br label %7

7:                                                ; preds = %.lr.ph, %7
  %8 = phi i16 [ %4, %.lr.ph ], [ %15, %7 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !13
  %10 = zext i16 %8 to i64
  %11 = getelementptr inbounds %struct.GCRef, ptr %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !29
  %13 = zext i32 %12 to i64
  %14 = inttoptr i64 %13 to ptr
  tail call void @trace_flushroot(ptr noundef nonnull %5, ptr noundef %14)
  %15 = load i16, ptr %3, align 2, !tbaa !5
  %.not = icmp eq i16 %15, 0
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !30

._crit_edge:                                      ; preds = %7, %2
  ret void
}

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" }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass