; 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.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: alwaysinline nounwind uwtable
declare hidden i32 @ir_nextk(ptr noundef) #1

; Function Attrs: nounwind uwtable
define hidden i32 @lj_ir_k64(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %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 7
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 28
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, i32 14, i32 21
  store i32 %18, ptr %10, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.jit_State, ptr %19, i32 0, i32 38
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i16], ptr %20, i64 0, i64 %22
  %24 = load i16, ptr %23, align 2, !tbaa !21
  %25 = zext i16 %24 to i32
  store i32 %25, ptr %9, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %42, %3
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %50

29:                                               ; preds = %26
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %union.IRIns, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.MRef, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 4, !tbaa !22
  %36 = zext i32 %35 to i64
  %37 = inttoptr i64 %36 to ptr
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = icmp eq ptr %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %29
  br label %89

41:                                               ; preds = %29
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %union.IRIns, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.anon, ptr %46, i32 0, i32 3
  %48 = load i16, ptr %47, align 2, !tbaa !22
  %49 = zext i16 %48 to i32
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %26, !llvm.loop !23

50:                                               ; preds = %26
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call i32 @ir_nextk(ptr noundef %51)
  store i32 %52, ptr %9, align 4, !tbaa !9
  %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 7
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds %union.IRIns, ptr %56, i64 %58
  store ptr %59, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = ptrtoint ptr %60 to i64
  %62 = trunc i64 %61 to i32
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MRef, ptr %63, i32 0, i32 0
  store i32 %62, ptr %64, align 4, !tbaa !22
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = trunc i32 %65 to i8
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.anon.0, ptr %67, i32 0, i32 1
  %69 = getelementptr inbounds %struct.IRType1, ptr %68, i32 0, i32 0
  store i8 %66, ptr %69, align 4, !tbaa !22
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = trunc i32 %70 to i8
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.anon.0, ptr %72, i32 0, i32 2
  store i8 %71, ptr %73, align 1, !tbaa !22
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.jit_State, ptr %74, i32 0, i32 38
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds [100 x i16], ptr %75, i64 0, i64 %77
  %79 = load i16, ptr %78, align 2, !tbaa !21
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.anon, ptr %80, i32 0, i32 3
  store i16 %79, ptr %81, align 2, !tbaa !22
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = trunc i32 %82 to i16
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.jit_State, ptr %84, i32 0, i32 38
  %86 = load i32, ptr %5, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds [100 x i16], ptr %85, i64 0, i64 %87
  store i16 %83, ptr %88, align 2, !tbaa !21
  br label %89

89:                                               ; preds = %50, %40
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = load i32, ptr %10, align 4, !tbaa !9
  %92 = shl i32 %91, 24
  %93 = add i32 %90, %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!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 = !{!15, !15, i64 0}
!22 = !{!7, !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: alwaysinline nounwind uwtable
declare hidden i32 @ir_nextk(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden i32 @lj_ir_k64(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %1, 28
  %7 = select i1 %6, i32 14, i32 21
  %8 = getelementptr inbounds i8, ptr %0, i64 336
  %9 = zext i32 %1 to i64
  %10 = getelementptr inbounds [100 x i16], ptr %8, i64 0, i64 %9
  %.0.in26 = load i16, ptr %10, align 2, !tbaa !19
  %.not27 = icmp eq i16 %.0.in26, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %14, i64 6
  %.0.in = load i16, ptr %12, align 2, !tbaa !19
  %.not = icmp eq i16 %.0.in, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20

.lr.ph:                                           ; preds = %3, %11
  %.0.in28 = phi i16 [ %.0.in, %11 ], [ %.0.in26, %3 ]
  %13 = zext i16 %.0.in28 to i64
  %14 = getelementptr inbounds %union.IRIns, ptr %5, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !19
  %16 = zext i32 %15 to i64
  %17 = inttoptr i64 %16 to ptr
  %18 = icmp eq ptr %17, %2
  br i1 %18, label %.loopexit, label %11

._crit_edge:                                      ; preds = %11, %3
  %19 = tail call i32 @ir_nextk(ptr noundef %0)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = zext i32 %19 to i64
  %22 = getelementptr inbounds %union.IRIns, ptr %20, i64 %21
  %23 = ptrtoint ptr %2 to i64
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %22, align 4, !tbaa !19
  %25 = trunc nuw nsw i32 %7 to i8
  %26 = getelementptr inbounds i8, ptr %22, i64 4
  store i8 %25, ptr %26, align 4, !tbaa !19
  %27 = trunc i32 %1 to i8
  %28 = getelementptr inbounds i8, ptr %22, i64 5
  store i8 %27, ptr %28, align 1, !tbaa !19
  %29 = load i16, ptr %10, align 2, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %22, i64 6
  store i16 %29, ptr %30, align 2, !tbaa !19
  %31 = trunc i32 %19 to i16
  store i16 %31, ptr %10, align 2, !tbaa !22
  br label %32

.loopexit:                                        ; preds = %.lr.ph
  %.0.le = zext i16 %.0.in28 to i32
  br label %32

32:                                               ; preds = %.loopexit, %._crit_edge
  %.1 = phi i32 [ %19, %._crit_edge ], [ %.0.le, %.loopexit ]
  %33 = shl nuw nsw i32 %7, 24
  %34 = add i32 %.1, %33
  ret i32 %34
}

attributes #0 = { alwaysinline 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 = { 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, !12, i64 16}
!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 = !{!10, !10, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!13, !13, i64 0}


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