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

; Function Attrs: nounwind uwtable
define hidden void @lj_record_stop(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.jit_State, ptr %7, i32 0, i32 16
  store i32 19, ptr %8, align 4, !tbaa !11
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = trunc i32 %9 to i8
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.jit_State, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.GCtrace, ptr %12, i32 0, i32 4
  store i8 %10, ptr %13, align 1, !tbaa !21
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = trunc i32 %14 to i16
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.jit_State, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.GCtrace, ptr %17, i32 0, i32 22
  store i16 %15, ptr %18, align 2, !tbaa !22
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.jit_State, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.GCtrace, ptr %21, i32 0, i32 21
  %23 = load i16, ptr %22, align 8, !tbaa !23
  %24 = zext i16 %23 to i32
  %25 = icmp eq i32 %19, %24
  br i1 %25, label %26, label %57

26:                                               ; preds = %3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.jit_State, ptr %27, i32 0, i32 20
  %29 = load i32, ptr %28, align 4, !tbaa !24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.jit_State, ptr %30, i32 0, i32 21
  %32 = load i32, ptr %31, align 8, !tbaa !25
  %33 = add nsw i32 %29, %32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %57

35:                                               ; preds = %26
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.jit_State, ptr %36, i32 0, i32 6
  %38 = load i32, ptr %37, align 8, !tbaa !26
  %39 = and i32 %38, 4194304
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  br label %59

42:                                               ; preds = %35
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.jit_State, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.GCtrace, ptr %44, i32 0, i32 23
  %46 = load i16, ptr %45, align 4, !tbaa !27
  %47 = icmp ne i16 %46, 0
  br i1 %47, label %48, label %56

48:                                               ; preds = %42
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.jit_State, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.GCtrace, ptr %50, i32 0, i32 23
  %52 = load i16, ptr %51, align 4, !tbaa !27
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.jit_State, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.GCtrace, ptr %54, i32 0, i32 22
  store i16 %52, ptr %55, align 2, !tbaa !22
  br label %56

56:                                               ; preds = %48, %42
  br label %57

57:                                               ; preds = %56, %26, %3
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  call void @canonicalize_slots(ptr noundef %58)
  br label %59

59:                                               ; preds = %57, %41
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lj_snap_add(ptr noundef %60)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.jit_State, ptr %61, i32 0, i32 10
  store i8 0, ptr %62, align 1, !tbaa !28
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.jit_State, ptr %63, i32 0, i32 9
  store i8 1, ptr %64, align 4, !tbaa !29
  ret void
}

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

declare hidden void @lj_snap_add(ptr noundef) #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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 188}
!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 = !{!12, !7, i64 7}
!22 = !{!12, !15, i64 82}
!23 = !{!12, !15, i64 80}
!24 = !{!12, !10, i64 204}
!25 = !{!12, !10, i64 208}
!26 = !{!12, !10, i64 136}
!27 = !{!12, !15, i64 84}
!28 = !{!12, !7, i64 149}
!29 = !{!12, !7, i64 148}


; 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
define hidden void @lj_record_stop(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 188
  store i32 19, ptr %4, align 4, !tbaa !5
  %5 = trunc i32 %1 to i8
  %6 = getelementptr inbounds i8, ptr %0, i64 7
  store i8 %5, ptr %6, align 1, !tbaa !19
  %7 = trunc i32 %2 to i16
  %8 = getelementptr inbounds i8, ptr %0, i64 82
  store i16 %7, ptr %8, align 2, !tbaa !20
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load i16, ptr %9, align 8, !tbaa !21
  %11 = zext i16 %10 to i32
  %12 = icmp eq i32 %11, %2
  br i1 %12, label %13, label %28

13:                                               ; preds = %3
  %14 = getelementptr inbounds i8, ptr %0, i64 204
  %15 = load i32, ptr %14, align 4, !tbaa !22
  %16 = getelementptr inbounds i8, ptr %0, i64 208
  %17 = load i32, ptr %16, align 8, !tbaa !23
  %18 = sub i32 0, %17
  %19 = icmp eq i32 %15, %18
  br i1 %19, label %20, label %28

20:                                               ; preds = %13
  %21 = getelementptr inbounds i8, ptr %0, i64 136
  %22 = load i32, ptr %21, align 8, !tbaa !24
  %23 = and i32 %22, 4194304
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %24, label %29

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %0, i64 84
  %26 = load i16, ptr %25, align 4, !tbaa !25
  %.not16 = icmp eq i16 %26, 0
  br i1 %.not16, label %28, label %27

27:                                               ; preds = %24
  store i16 %26, ptr %8, align 2, !tbaa !20
  br label %28

28:                                               ; preds = %24, %27, %13, %3
  tail call void @canonicalize_slots(ptr noundef nonnull %0)
  br label %29

29:                                               ; preds = %20, %28
  tail call void @lj_snap_add(ptr noundef nonnull %0) #2
  %30 = getelementptr inbounds i8, ptr %0, i64 149
  store i8 0, ptr %30, align 1, !tbaa !26
  %31 = getelementptr inbounds i8, ptr %0, i64 148
  store i8 1, ptr %31, align 4, !tbaa !27
  ret void
}

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

declare hidden void @lj_snap_add(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 = { "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 = { 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, !9, i64 188}
!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 = !{!6, !10, i64 7}
!20 = !{!6, !13, i64 82}
!21 = !{!6, !13, i64 80}
!22 = !{!6, !9, i64 204}
!23 = !{!6, !9, i64 208}
!24 = !{!6, !9, i64 136}
!25 = !{!6, !13, i64 84}
!26 = !{!6, !10, i64 149}
!27 = !{!6, !10, i64 148}


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