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

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

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

; Function Attrs: nounwind uwtable
define hidden void @lj_record_tailcall(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load i64, ptr %6, align 8, !tbaa !11
  call void @rec_call_setup(ptr noundef %8, i32 noundef %9, i64 noundef %10)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.jit_State, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.lua_State, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.anon.5, ptr %14, i32 0, i32 7
  %16 = load ptr, ptr %15, align 8, !tbaa !22
  %17 = getelementptr inbounds %union.TValue, ptr %16, i64 -1
  %18 = getelementptr inbounds %struct.anon.0, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !22
  %20 = sext i32 %19 to i64
  %21 = and i64 %20, 7
  %22 = icmp eq i64 %21, 3
  br i1 %22, label %23, label %59

23:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.jit_State, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %struct.lua_State, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon.5, ptr %27, i32 0, i32 7
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %30 = getelementptr inbounds %union.TValue, ptr %29, i64 -1
  %31 = getelementptr inbounds %struct.anon.0, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !22
  %33 = sext i32 %32 to i64
  %34 = ashr i64 %33, 3
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %7, align 4, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.jit_State, ptr %36, i32 0, i32 20
  %38 = load i32, ptr %37, align 4, !tbaa !23
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr %37, align 4, !tbaa !23
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %23
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lj_trace_err(ptr noundef %42, i32 noundef 16) #5
  unreachable

43:                                               ; preds = %23
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.jit_State, ptr %45, i32 0, i32 8
  %47 = load i32, ptr %46, align 8, !tbaa !24
  %48 = sub i32 %47, %44
  store i32 %48, ptr %46, align 8, !tbaa !24
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.jit_State, ptr %50, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !25
  %53 = zext i32 %49 to i64
  %54 = sub i64 0, %53
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  store ptr %55, ptr %51, align 8, !tbaa !25
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = add i32 %57, %56
  store i32 %58, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %59

59:                                               ; preds = %43, %3
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.jit_State, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !25
  %63 = getelementptr inbounds i32, ptr %62, i64 -1
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.jit_State, ptr %64, i32 0, i32 5
  %66 = load ptr, ptr %65, align 8, !tbaa !25
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.jit_State, ptr %70, i32 0, i32 7
  %72 = load i32, ptr %71, align 4, !tbaa !26
  %73 = add i32 %72, 1
  %74 = zext i32 %73 to i64
  %75 = mul i64 4, %74
  call void @llvm.memmove.p0.p0.i64(ptr align 4 %63, ptr align 4 %69, i64 %75, i1 false)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.jit_State, ptr %76, i32 0, i32 19
  %78 = load i32, ptr %77, align 8, !tbaa !27
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %77, align 8, !tbaa !27
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.jit_State, ptr %80, i32 0, i32 18
  %82 = load i32, ptr %81, align 4, !tbaa !28
  %83 = icmp sgt i32 %79, %82
  br i1 %83, label %84, label %86

84:                                               ; preds = %59
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lj_trace_err(ptr noundef %85, i32 noundef 10) #5
  unreachable

86:                                               ; preds = %59
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 96}
!14 = !{!"jit_State", !15, 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, !19, i64 150, !7, i64 151, !20, 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, !21, 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, !12, i64 2472, !12, i64 2480, !7, i64 2488, !6, i64 2496, !10, i64 2504, !10, i64 2508}
!15 = !{!"GCtrace", !16, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !16, i64 12, !6, i64 16, !10, i64 24, !17, i64 28, !17, i64 30, !6, i64 32, !6, i64 40, !16, i64 48, !18, i64 52, !10, i64 56, !10, i64 60, !6, i64 64, !10, 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", !10, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"MRef", !10, 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}
!22 = !{!7, !7, i64 0}
!23 = !{!14, !10, i64 204}
!24 = !{!14, !10, i64 144}
!25 = !{!14, !6, i64 128}
!26 = !{!14, !10, i64 140}
!27 = !{!14, !10, i64 200}
!28 = !{!14, !10, i64 196}


; 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 @rec_call_setup(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden void @lj_record_tailcall(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  tail call void @rec_call_setup(ptr noundef %0, i32 noundef %1, i64 noundef %2)
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %7, i64 -4
  %9 = load i32, ptr %8, align 4, !tbaa !19
  %10 = and i32 %9, 7
  %11 = icmp eq i32 %10, 3
  br i1 %11, label %12, label %._crit_edge

._crit_edge:                                      ; preds = %3
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 128
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !20
  br label %29

12:                                               ; preds = %3
  %13 = getelementptr inbounds i8, ptr %0, i64 204
  %14 = load i32, ptr %13, align 4, !tbaa !21
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %13, align 4, !tbaa !21
  %16 = icmp slt i32 %14, 1
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  tail call void @lj_trace_err(ptr noundef nonnull %0, i32 noundef 16) #3
  unreachable

18:                                               ; preds = %12
  %19 = ashr i32 %9, 3
  %20 = getelementptr inbounds i8, ptr %0, i64 144
  %21 = load i32, ptr %20, align 8, !tbaa !22
  %22 = sub i32 %21, %19
  store i32 %22, ptr %20, align 8, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %0, i64 128
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  %25 = zext i32 %19 to i64
  %26 = sub nsw i64 0, %25
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  store ptr %27, ptr %23, align 8, !tbaa !20
  %28 = add i32 %19, %1
  br label %29

29:                                               ; preds = %._crit_edge, %18
  %30 = phi ptr [ %27, %18 ], [ %.pre, %._crit_edge ]
  %.0 = phi i32 [ %28, %18 ], [ %1, %._crit_edge ]
  %31 = getelementptr inbounds i8, ptr %30, i64 -4
  %32 = zext i32 %.0 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = getelementptr inbounds i8, ptr %0, i64 140
  %35 = load i32, ptr %34, align 4, !tbaa !23
  %36 = add i32 %35, 1
  %37 = zext i32 %36 to i64
  %38 = shl nuw nsw i64 %37, 2
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 4 %31, ptr align 4 %33, i64 %38, i1 false)
  %39 = getelementptr inbounds i8, ptr %0, i64 200
  %40 = load i32, ptr %39, align 8, !tbaa !24
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %39, align 8, !tbaa !24
  %42 = getelementptr inbounds i8, ptr %0, i64 196
  %43 = load i32, ptr %42, align 4, !tbaa !25
  %.not = icmp slt i32 %40, %43
  br i1 %.not, label %45, label %44

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

45:                                               ; preds = %29
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #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 "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 96}
!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 = !{!10, !10, i64 0}
!20 = !{!6, !12, i64 128}
!21 = !{!6, !9, i64 204}
!22 = !{!6, !9, i64 144}
!23 = !{!6, !9, i64 140}
!24 = !{!6, !9, i64 200}
!25 = !{!6, !9, i64 196}


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