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

; 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.K64Array = type { %struct.MRef, i32, [16 x %union.TValue] }

; 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 ptr @lj_ir_k64_find(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.jit_State, ptr %11, i32 0, i32 22
  %13 = getelementptr inbounds %struct.MRef, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = zext i32 %14 to i64
  %16 = inttoptr i64 %15 to ptr
  store ptr %16, ptr %6, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %48, %2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %55

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %21, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !21
  br label %22

22:                                               ; preds = %44, %20
  %23 = load i32, ptr %8, align 4, !tbaa !21
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.K64Array, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !22
  %27 = icmp ult i32 %23, %26
  br i1 %27, label %28, label %47

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.K64Array, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %8, align 4, !tbaa !21
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [16 x %union.TValue], ptr %30, i64 0, i64 %32
  store ptr %33, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %34, align 8, !tbaa !24
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = icmp eq i64 %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %28
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %39, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %41

40:                                               ; preds = %28
  store i32 0, ptr %10, align 4
  br label %41

41:                                               ; preds = %40, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %42 = load i32, ptr %10, align 4
  switch i32 %42, label %60 [
    i32 0, label %43
  ]

43:                                               ; preds = %41
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %8, align 4, !tbaa !21
  %46 = add i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !21
  br label %22, !llvm.loop !25

47:                                               ; preds = %22
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.K64Array, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.MRef, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !27
  %53 = zext i32 %52 to i64
  %54 = inttoptr i64 %53 to ptr
  store ptr %54, ptr %6, align 8, !tbaa !5
  br label %17, !llvm.loop !28

55:                                               ; preds = %17
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = call ptr @ir_k64_add(ptr noundef %56, ptr noundef %57, i64 noundef %58)
  store ptr %59, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %60

60:                                               ; preds = %55, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %61 = load ptr, ptr %3, align 8
  ret ptr %61
}

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


; 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.TValue = type { i64 }

; Function Attrs: nounwind uwtable
define hidden ptr @lj_ir_k64_find(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 212
  %.019.in.in26 = load i32, ptr %3, align 4, !tbaa !5
  %.not29 = icmp eq i32 %.019.in.in26, 0
  br i1 %.not29, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %7, %.preheader
  %.019.in.in = load i32, ptr %.01930, align 4, !tbaa !5
  %.not = icmp eq i32 %.019.in.in, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %2, %.loopexit
  %.01930.in.in = phi i32 [ %.019.in.in, %.loopexit ], [ %.019.in.in26, %2 ]
  %.01930.in = zext i32 %.01930.in.in to i64
  %.01930 = inttoptr i64 %.01930.in to ptr
  %4 = getelementptr inbounds i8, ptr %.01930, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %.not31 = icmp eq i32 %5, 0
  br i1 %.not31, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %.01930, i64 8
  %wide.trip.count = zext i32 %5 to i64
  br label %8

7:                                                ; preds = %8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %8, !llvm.loop !14

8:                                                ; preds = %.lr.ph, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %7 ]
  %9 = getelementptr inbounds [16 x %union.TValue], ptr %6, i64 0, i64 %indvars.iv
  %10 = load i64, ptr %9, align 8, !tbaa !15
  %.not20 = icmp eq i64 %10, %1
  br i1 %.not20, label %.loopexit21.loopexit, label %7

._crit_edge:                                      ; preds = %.loopexit, %2
  %.018.lcssa = phi ptr [ null, %2 ], [ %.01930, %.loopexit ]
  %11 = tail call ptr @ir_k64_add(ptr noundef %0, ptr noundef %.018.lcssa, i64 noundef %1)
  br label %.loopexit21

.loopexit21.loopexit:                             ; preds = %8
  %12 = getelementptr inbounds [16 x %union.TValue], ptr %6, i64 0, i64 %indvars.iv
  br label %.loopexit21

.loopexit21:                                      ; preds = %.loopexit21.loopexit, %._crit_edge
  %.3 = phi ptr [ %11, %._crit_edge ], [ %12, %.loopexit21.loopexit ]
  ret ptr %.3
}

; Function Attrs: nounwind uwtable
declare hidden ptr @ir_k64_add(ptr noundef, ptr noundef, i64 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 4}
!12 = !{!"K64Array", !13, i64 0, !6, i64 4, !7, i64 8}
!13 = !{!"MRef", !6, i64 0}
!14 = distinct !{!14, !10}
!15 = !{!7, !7, i64 0}


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