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

; 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.anon = type { i16, i16, i16, i16 }

; 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 i32 @lj_opt_fwd_hrefk(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.jit_State, ptr %8, i32 0, i32 13
  %10 = getelementptr inbounds %struct.FoldState, ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds %struct.anon, ptr %10, i32 0, i32 0
  %12 = load i16, ptr %11, align 8, !tbaa !9
  %13 = zext i16 %12 to i32
  store i32 %13, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.jit_State, ptr %14, i32 0, i32 38
  %16 = getelementptr inbounds [100 x i16], ptr %15, i64 0, i64 60
  %17 = load i16, ptr %16, align 8, !tbaa !12
  %18 = zext i16 %17 to i32
  store i32 %18, ptr %5, align 4, !tbaa !10
  br label %19

19:                                               ; preds = %70, %1
  %20 = load i32, ptr %5, align 4, !tbaa !10
  %21 = load i32, ptr %4, align 4, !tbaa !10
  %22 = icmp ugt i32 %20, %21
  br i1 %22, label %23, label %71

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.jit_State, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.GCtrace, ptr %25, i32 0, i32 7
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i32, ptr %5, align 4, !tbaa !10
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %union.IRIns, ptr %27, i64 %29
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !10
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 0
  %34 = load i16, ptr %33, align 4, !tbaa !9
  %35 = zext i16 %34 to i32
  %36 = icmp eq i32 %31, %35
  br i1 %36, label %37, label %52

37:                                               ; preds = %23
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.jit_State, ptr %38, i32 0, i32 13
  %40 = getelementptr inbounds %struct.FoldState, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 0
  %42 = load i16, ptr %41, align 8, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 1
  %46 = load i16, ptr %45, align 2, !tbaa !9
  %47 = zext i16 %46 to i32
  %48 = icmp eq i32 %43, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %37
  %50 = load i32, ptr %5, align 4, !tbaa !10
  store i32 %50, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %68

51:                                               ; preds = %37
  store i32 4, ptr %7, align 4
  br label %68

52:                                               ; preds = %23
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !10
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.anon, ptr %55, i32 0, i32 0
  %57 = load i16, ptr %56, align 4, !tbaa !9
  %58 = zext i16 %57 to i32
  %59 = call i32 @aa_table(ptr noundef %53, i32 noundef %54, i32 noundef %58)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %52
  store i32 4, ptr %7, align 4
  br label %68

62:                                               ; preds = %52
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 3
  %66 = load i16, ptr %65, align 2, !tbaa !9
  %67 = zext i16 %66 to i32
  store i32 %67, ptr %5, align 4, !tbaa !10
  store i32 0, ptr %7, align 4
  br label %68

68:                                               ; preds = %63, %61, %51, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %69 = load i32, ptr %7, align 4
  switch i32 %69, label %97 [
    i32 0, label %70
    i32 4, label %94
  ]

70:                                               ; preds = %68
  br label %19, !llvm.loop !23

71:                                               ; preds = %19
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.jit_State, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.GCtrace, ptr %73, i32 0, i32 7
  %75 = load ptr, ptr %74, align 8, !tbaa !14
  %76 = load i32, ptr %4, align 4, !tbaa !10
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds %union.IRIns, ptr %75, i64 %77
  %79 = getelementptr inbounds %struct.anon.0, ptr %78, i32 0, i32 2
  %80 = load i8, ptr %79, align 1, !tbaa !9
  %81 = zext i8 %80 to i32
  %82 = icmp eq i32 %81, 81
  br i1 %82, label %83, label %93

83:                                               ; preds = %71
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.jit_State, ptr %84, i32 0, i32 13
  %86 = getelementptr inbounds %struct.FoldState, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds %struct.anon.0, ptr %86, i32 0, i32 1
  %88 = getelementptr inbounds %struct.IRType1, ptr %87, i32 0, i32 0
  %89 = load i8, ptr %88, align 4, !tbaa !9
  %90 = zext i8 %89 to i32
  %91 = and i32 %90, -129
  %92 = trunc i32 %91 to i8
  store i8 %92, ptr %88, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %83, %71
  br label %94

94:                                               ; preds = %93, %68
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = call i32 @lj_opt_cse(ptr noundef %95)
  store i32 %96, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %97

97:                                               ; preds = %94, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %98 = load i32, ptr %2, align 4
  ret i32 %98
}

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

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

%union.IRIns = type { %struct.anon.0 }
%struct.anon.0 = type { i32, %struct.IRType1, i8, i8, i8 }
%struct.IRType1 = type { i8 }

; Function Attrs: nounwind uwtable
define hidden i32 @lj_opt_fwd_hrefk(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 160
  %3 = load i16, ptr %2, align 8, !tbaa !5
  %4 = zext i16 %3 to i32
  %5 = getelementptr inbounds i8, ptr %0, i64 456
  %.021.in36 = load i16, ptr %5, align 2, !tbaa !5
  %6 = icmp ugt i16 %.021.in36, %3
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  br label %8

8:                                                ; preds = %.lr.ph, %23
  %.021.in37 = phi i16 [ %.021.in36, %.lr.ph ], [ %.021.in, %23 ]
  %9 = load ptr, ptr %7, align 8, !tbaa !8
  %10 = zext i16 %.021.in37 to i64
  %11 = getelementptr inbounds %union.IRIns, ptr %9, i64 %10
  %12 = load i16, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i16 %3, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %8
  %.021.le = zext i16 %.021.in37 to i32
  %15 = getelementptr inbounds i8, ptr %0, i64 168
  %16 = load i16, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %11, i64 2
  %18 = load i16, ptr %17, align 2, !tbaa !5
  %19 = icmp eq i16 %16, %18
  br i1 %19, label %.thread29, label %.thread

20:                                               ; preds = %8
  %21 = zext i16 %12 to i32
  %22 = tail call i32 @aa_table(ptr noundef nonnull %0, i32 noundef %4, i32 noundef %21)
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %23, label %.thread

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %11, i64 6
  %.021.in = load i16, ptr %24, align 2, !tbaa !5
  %25 = icmp ugt i16 %.021.in, %3
  br i1 %25, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %23, %1
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !8
  %28 = zext i16 %3 to i64
  %29 = getelementptr inbounds %union.IRIns, ptr %27, i64 %28, i32 0, i32 2
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = icmp eq i8 %30, 81
  br i1 %31, label %32, label %.thread

32:                                               ; preds = %._crit_edge
  %33 = getelementptr inbounds i8, ptr %0, i64 156
  %34 = load i8, ptr %33, align 4, !tbaa !5
  %35 = and i8 %34, 127
  store i8 %35, ptr %33, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %20, %14, %._crit_edge, %32
  %36 = tail call i32 @lj_opt_cse(ptr noundef nonnull %0) #2
  br label %.thread29

.thread29:                                        ; preds = %14, %.thread
  %.2 = phi i32 [ %36, %.thread ], [ %.021.le, %14 ]
  ret i32 %.2
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass