; 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_href_nokey(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 i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %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 0
  %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) #2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.jit_State, ptr %14, i32 0, i32 13
  %16 = getelementptr inbounds %struct.FoldState, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds %struct.anon.0, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds %struct.IRType1, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 4, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = and i32 %20, 31
  %22 = icmp eq i32 %21, 14
  br i1 %22, label %23, label %62

23:                                               ; preds = %1
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.jit_State, ptr %24, i32 0, i32 38
  %26 = getelementptr inbounds [100 x i16], ptr %25, i64 0, i64 60
  %27 = load i16, ptr %26, align 8, !tbaa !12
  %28 = zext i16 %27 to i32
  %29 = load i32, ptr %4, align 4, !tbaa !10
  %30 = icmp ugt i32 %28, %29
  br i1 %30, label %31, label %62

31:                                               ; preds = %23
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.jit_State, ptr %32, i32 0, i32 38
  %34 = getelementptr inbounds [100 x i16], ptr %33, i64 0, i64 73
  %35 = load i16, ptr %34, align 2, !tbaa !12
  %36 = zext i16 %35 to i32
  store i32 %36, ptr %5, align 4, !tbaa !10
  br label %37

37:                                               ; preds = %50, %31
  %38 = load i32, ptr %5, align 4, !tbaa !10
  %39 = load i32, ptr %4, align 4, !tbaa !10
  %40 = icmp ugt i32 %38, %39
  br i1 %40, label %41, label %61

41:                                               ; preds = %37
  %42 = load i32, ptr %5, align 4, !tbaa !10
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.jit_State, ptr %43, i32 0, i32 38
  %45 = getelementptr inbounds [100 x i16], ptr %44, i64 0, i64 60
  %46 = load i16, ptr %45, align 8, !tbaa !12
  %47 = zext i16 %46 to i32
  %48 = icmp ult i32 %42, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %41
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %105

50:                                               ; preds = %41
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.jit_State, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.GCtrace, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load i32, ptr %5, align 4, !tbaa !10
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds %union.IRIns, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.anon, ptr %57, i32 0, i32 3
  %59 = load i16, ptr %58, align 2, !tbaa !9
  %60 = zext i16 %59 to i32
  store i32 %60, ptr %5, align 4, !tbaa !10
  br label %37, !llvm.loop !23

61:                                               ; preds = %37
  br label %62

62:                                               ; preds = %61, %23, %1
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.jit_State, ptr %63, i32 0, i32 38
  %65 = getelementptr inbounds [100 x i16], ptr %64, i64 0, i64 74
  %66 = load i16, ptr %65, align 4, !tbaa !12
  %67 = zext i16 %66 to i32
  store i32 %67, ptr %5, align 4, !tbaa !10
  br label %68

68:                                               ; preds = %103, %62
  %69 = load i32, ptr %5, align 4, !tbaa !10
  %70 = load i32, ptr %4, align 4, !tbaa !10
  %71 = icmp ugt i32 %69, %70
  br i1 %71, label %72, label %104

72:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.jit_State, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds %struct.GCtrace, ptr %74, i32 0, i32 7
  %76 = load ptr, ptr %75, align 8, !tbaa !14
  %77 = load i32, ptr %5, align 4, !tbaa !10
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds %union.IRIns, ptr %76, i64 %78
  store ptr %79, ptr %7, align 8, !tbaa !5
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.jit_State, ptr %81, i32 0, i32 13
  %83 = getelementptr inbounds %struct.FoldState, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.jit_State, ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds %struct.GCtrace, ptr %85, i32 0, i32 7
  %87 = load ptr, ptr %86, align 8, !tbaa !14
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.anon, ptr %88, i32 0, i32 0
  %90 = load i16, ptr %89, align 4, !tbaa !9
  %91 = zext i16 %90 to i64
  %92 = getelementptr inbounds %union.IRIns, ptr %87, i64 %91
  %93 = call i32 @aa_ahref(ptr noundef %80, ptr noundef %83, ptr noundef %92)
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %72
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %101

96:                                               ; preds = %72
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.anon, ptr %97, i32 0, i32 3
  %99 = load i16, ptr %98, align 2, !tbaa !9
  %100 = zext i16 %99 to i32
  store i32 %100, ptr %5, align 4, !tbaa !10
  store i32 0, ptr %6, align 4
  br label %101

101:                                              ; preds = %96, %95
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %102 = load i32, ptr %6, align 4
  switch i32 %102, label %105 [
    i32 0, label %103
  ]

103:                                              ; preds = %101
  br label %68, !llvm.loop !25

104:                                              ; preds = %68
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %105

105:                                              ; preds = %104, %101, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %106 = load i32, ptr %2, align 4
  ret i32 %106
}

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

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 = { 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"}
!25 = distinct !{!25, !24}


; 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 noundef i32 @lj_opt_fwd_href_nokey(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 152
  %3 = load i16, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 172
  %5 = load i8, ptr %4, align 4, !tbaa !5
  %6 = and i8 %5, 31
  %7 = icmp eq i8 %6, 14
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 456
  %10 = load i16, ptr %9, align 8, !tbaa !8
  %11 = icmp ugt i16 %10, %3
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 482
  %.023.in29 = load i16, ptr %13, align 2, !tbaa !5
  %14 = icmp ugt i16 %.023.in29, %3
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  br label %16

16:                                               ; preds = %.lr.ph, %18
  %.023.in30 = phi i16 [ %.023.in29, %.lr.ph ], [ %.023.in, %18 ]
  %17 = icmp ult i16 %.023.in30, %10
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %16
  %19 = load ptr, ptr %15, align 8, !tbaa !10
  %20 = zext i16 %.023.in30 to i64
  %21 = getelementptr inbounds %union.IRIns, ptr %19, i64 %20, i32 0, i32 3
  %.023.in = load i16, ptr %21, align 2, !tbaa !5
  %22 = icmp ugt i16 %.023.in, %3
  br i1 %22, label %16, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %18, %12, %8, %1
  %23 = getelementptr inbounds i8, ptr %0, i64 484
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %.124.in31 = load i16, ptr %23, align 2, !tbaa !5
  %25 = icmp ugt i16 %.124.in31, %3
  br i1 %25, label %.lr.ph33, label %.thread

26:                                               ; preds = %.lr.ph33
  %27 = getelementptr inbounds i8, ptr %31, i64 6
  %.124.in = load i16, ptr %27, align 2, !tbaa !5
  %28 = icmp ugt i16 %.124.in, %3
  br i1 %28, label %.lr.ph33, label %.thread, !llvm.loop !23

.lr.ph33:                                         ; preds = %.loopexit, %26
  %.124.in32 = phi i16 [ %.124.in, %26 ], [ %.124.in31, %.loopexit ]
  %29 = load ptr, ptr %24, align 8, !tbaa !10
  %30 = zext i16 %.124.in32 to i64
  %31 = getelementptr inbounds %union.IRIns, ptr %29, i64 %30
  %32 = load i16, ptr %31, align 4, !tbaa !5
  %33 = zext i16 %32 to i64
  %34 = getelementptr inbounds %union.IRIns, ptr %29, i64 %33
  %35 = tail call i32 @aa_ahref(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef %34)
  %.not = icmp eq i32 %35, 0
  br i1 %.not, label %26, label %.thread

.thread:                                          ; preds = %16, %26, %.lr.ph33, %.loopexit
  %.2 = phi i32 [ 1, %.loopexit ], [ 1, %26 ], [ 0, %.lr.ph33 ], [ 0, %16 ]
  ret i32 %.2
}

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

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


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