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

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

@recff_func = external hidden constant [61 x ptr], align 16

; 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
define hidden void @lj_ffrecord_func(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.RecordFFData, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.jit_State, ptr %5, i32 0, i32 3
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = call i32 @recdef_lookup(ptr noundef %7)
  store i32 %8, ptr %4, align 4, !tbaa !20
  %9 = load i32, ptr %4, align 4, !tbaa !20
  %10 = and i32 %9, 255
  %11 = getelementptr inbounds %struct.RecordFFData, ptr %3, i32 0, i32 2
  store i32 %10, ptr %11, align 8, !tbaa !21
  %12 = getelementptr inbounds %struct.RecordFFData, ptr %3, i32 0, i32 1
  store i64 1, ptr %12, align 8, !tbaa !23
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.jit_State, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !24
  %16 = getelementptr inbounds %struct.lua_State, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.anon.5, ptr %16, i32 0, i32 7
  %18 = load ptr, ptr %17, align 8, !tbaa !25
  %19 = getelementptr inbounds %struct.RecordFFData, ptr %3, i32 0, i32 0
  store ptr %18, ptr %19, align 8, !tbaa !26
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.jit_State, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !27
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.jit_State, ptr %23, i32 0, i32 7
  %25 = load i32, ptr %24, align 4, !tbaa !28
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %22, i64 %26
  store i32 0, ptr %27, align 4, !tbaa !20
  %28 = load i32, ptr %4, align 4, !tbaa !20
  %29 = lshr i32 %28, 8
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [61 x ptr], ptr @recff_func, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void %32(ptr noundef %33, ptr noundef %3)
  %34 = getelementptr inbounds %struct.RecordFFData, ptr %3, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !23
  %36 = icmp sge i64 %35, 0
  br i1 %36, label %37, label %49

37:                                               ; preds = %1
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.jit_State, ptr %38, i32 0, i32 32
  %40 = load i32, ptr %39, align 4, !tbaa !29
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %37
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.jit_State, ptr %43, i32 0, i32 32
  store i32 6, ptr %44, align 4, !tbaa !29
  br label %45

45:                                               ; preds = %42, %37
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.RecordFFData, ptr %3, i32 0, i32 1
  %48 = load i64, ptr %47, align 8, !tbaa !23
  call void @lj_record_ret(ptr noundef %46, i32 noundef 0, i64 noundef %48)
  br label %49

49:                                               ; preds = %45, %1
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #3
  ret void
}

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

declare hidden void @lj_record_ret(ptr noundef, i32 noundef, i64 noundef) #2

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

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


; 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.RecordFFData = type { ptr, i64, i32 }

@recff_func = external hidden local_unnamed_addr constant [61 x ptr], align 16

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

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

; Function Attrs: nounwind uwtable
define hidden void @lj_ffrecord_func(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.RecordFFData, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 112
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call i32 @recdef_lookup(ptr noundef %4)
  %6 = and i32 %5, 255
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 %6, ptr %7, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 1, ptr %8, align 8, !tbaa !21
  %9 = getelementptr inbounds i8, ptr %0, i64 96
  %10 = load ptr, ptr %9, align 8, !tbaa !22
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !23
  store ptr %12, ptr %2, align 8, !tbaa !24
  %13 = getelementptr inbounds i8, ptr %0, i64 128
  %14 = load ptr, ptr %13, align 8, !tbaa !25
  %15 = getelementptr inbounds i8, ptr %0, i64 140
  %16 = load i32, ptr %15, align 4, !tbaa !26
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %14, i64 %17
  store i32 0, ptr %18, align 4, !tbaa !27
  %19 = lshr i32 %5, 8
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds [61 x ptr], ptr @recff_func, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !28
  call void %22(ptr noundef %0, ptr noundef nonnull %2) #3
  %23 = load i64, ptr %8, align 8, !tbaa !21
  %24 = icmp sgt i64 %23, -1
  br i1 %24, label %25, label %31

25:                                               ; preds = %1
  %26 = getelementptr inbounds i8, ptr %0, i64 300
  %27 = load i32, ptr %26, align 4, !tbaa !29
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i32 6, ptr %26, align 4, !tbaa !29
  br label %30

30:                                               ; preds = %29, %25
  call void @lj_record_ret(ptr noundef nonnull %0, i32 noundef 0, i64 noundef %23) #3
  br label %31

31:                                               ; preds = %30, %1
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  ret void
}

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

declare hidden void @lj_record_ret(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 }

!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 112}
!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, !9, i64 16}
!20 = !{!"RecordFFData", !12, i64 0, !18, i64 8, !9, i64 16}
!21 = !{!20, !18, i64 8}
!22 = !{!6, !12, i64 96}
!23 = !{!10, !10, i64 0}
!24 = !{!20, !12, i64 0}
!25 = !{!6, !12, i64 128}
!26 = !{!6, !9, i64 140}
!27 = !{!9, !9, i64 0}
!28 = !{!12, !12, i64 0}
!29 = !{!6, !9, i64 300}


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