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

; 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.GCtab = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, %struct.MRef, i32, i32 }
%struct.GCRef = type { i32 }
%struct.MRef = type { i32 }
%union.TValue = type { i64 }
%struct.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }

; 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 void @copyTV(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define hidden i32 @lj_tab_next(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = call i32 @keyindex(ptr noundef %11, ptr noundef %12, ptr noundef %13)
  store i32 %14, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = add i32 %15, 1
  store i32 %16, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %52, %3
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.GCtab, ptr %19, i32 0, i32 10
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = icmp ult i32 %18, %21
  br i1 %22, label %23, label %55

23:                                               ; preds = %17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.GCtab, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds %struct.MRef, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds %union.TValue, ptr %29, i64 %31
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %51, label %36

36:                                               ; preds = %23
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !9
  call void @setintV(ptr noundef %37, i32 noundef %38)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %union.TValue, ptr %40, i64 1
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.GCtab, ptr %42, i32 0, i32 5
  %44 = getelementptr inbounds %struct.MRef, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = zext i32 %45 to i64
  %47 = inttoptr i64 %46 to ptr
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds %union.TValue, ptr %47, i64 %49
  call void @copyTV(ptr noundef %39, ptr noundef %41, ptr noundef %50)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %100

51:                                               ; preds = %23
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !17

55:                                               ; preds = %17
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.GCtab, ptr %56, i32 0, i32 10
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = sub i32 %59, %58
  store i32 %60, ptr %8, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %96, %55
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.GCtab, ptr %63, i32 0, i32 11
  %65 = load i32, ptr %64, align 8, !tbaa !19
  %66 = icmp ule i32 %62, %65
  br i1 %66, label %67, label %99

67:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.GCtab, ptr %68, i32 0, i32 9
  %70 = getelementptr inbounds %struct.MRef, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !20
  %72 = zext i32 %71 to i64
  %73 = inttoptr i64 %72 to ptr
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds %struct.Node, ptr %73, i64 %75
  store ptr %76, ptr %10, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Node, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !16
  %81 = icmp eq i32 %80, -1
  br i1 %81, label %92, label %82

82:                                               ; preds = %67
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.Node, ptr %85, i32 0, i32 1
  call void @copyTV(ptr noundef %83, ptr noundef %84, ptr noundef %86)
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %union.TValue, ptr %88, i64 1
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.Node, ptr %90, i32 0, i32 0
  call void @copyTV(ptr noundef %87, ptr noundef %89, ptr noundef %91)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

92:                                               ; preds = %67
  store i32 0, ptr %9, align 4
  br label %93

93:                                               ; preds = %92, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %94 = load i32, ptr %9, align 4
  switch i32 %94, label %100 [
    i32 0, label %95
  ]

95:                                               ; preds = %93
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %8, align 4, !tbaa !9
  %98 = add i32 %97, 1
  store i32 %98, ptr %8, align 4, !tbaa !9
  br label %61, !llvm.loop !21

99:                                               ; preds = %61
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %100

100:                                              ; preds = %99, %93, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %101 = load i32, ptr %4, align 4
  ret i32 %101
}

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

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

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, !10, i64 36}
!12 = !{!"GCtab", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !14, i64 8, !13, i64 12, !13, i64 16, !6, i64 24, !14, i64 32, !10, i64 36, !10, i64 40}
!13 = !{!"GCRef", !10, i64 0}
!14 = !{!"MRef", !10, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !10, i64 40}
!20 = !{!12, !10, i64 32}
!21 = distinct !{!21, !18}


; 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 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }

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

; Function Attrs: nounwind uwtable
define hidden noundef i32 @lj_tab_next(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @keyindex(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %5 = getelementptr inbounds i8, ptr %1, i64 36
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = add i32 %4, 1
  br label %9

9:                                                ; preds = %11, %3
  %.031.in = phi i32 [ %4, %3 ], [ %.031, %11 ]
  %.031 = add i32 %.031.in, 1
  %10 = icmp ult i32 %.031, %6
  br i1 %10, label %11, label %26

11:                                               ; preds = %9
  %12 = load i32, ptr %7, align 8, !tbaa !13
  %13 = zext i32 %12 to i64
  %14 = inttoptr i64 %13 to ptr
  %15 = zext i32 %.031 to i64
  %16 = getelementptr inbounds %union.TValue, ptr %14, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %9, label %20, !llvm.loop !15

20:                                               ; preds = %11
  tail call void @setintV(ptr noundef %2, i32 noundef %.031)
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  %22 = load i32, ptr %7, align 8, !tbaa !13
  %23 = zext i32 %22 to i64
  %24 = inttoptr i64 %23 to ptr
  %25 = getelementptr inbounds %union.TValue, ptr %24, i64 %15
  tail call void @copyTV(ptr noundef %0, ptr noundef nonnull %21, ptr noundef %25)
  br label %.loopexit

26:                                               ; preds = %9
  %27 = tail call i32 @llvm.usub.sat.i32(i32 %8, i32 %6)
  %28 = getelementptr inbounds i8, ptr %1, i64 40
  %29 = load i32, ptr %28, align 8, !tbaa !17
  %.not39 = icmp ugt i32 %27, %29
  br i1 %.not39, label %.loopexit, label %.critedge.lr.ph

.critedge.lr.ph:                                  ; preds = %26
  %30 = getelementptr inbounds i8, ptr %1, i64 32
  %31 = load i32, ptr %30, align 8, !tbaa !18
  %32 = zext i32 %31 to i64
  %33 = inttoptr i64 %32 to ptr
  br label %.critedge

34:                                               ; preds = %.critedge
  %35 = add i32 %.13240, 1
  %.not = icmp ugt i32 %35, %29
  br i1 %.not, label %.loopexit, label %.critedge, !llvm.loop !19

.critedge:                                        ; preds = %.critedge.lr.ph, %34
  %.13240 = phi i32 [ %27, %.critedge.lr.ph ], [ %35, %34 ]
  %36 = zext i32 %.13240 to i64
  %37 = getelementptr inbounds %struct.Node, ptr %33, i64 %36
  %38 = getelementptr inbounds i8, ptr %37, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = icmp eq i32 %39, -1
  br i1 %40, label %34, label %41

41:                                               ; preds = %.critedge
  %42 = getelementptr inbounds i8, ptr %37, i64 8
  tail call void @copyTV(ptr noundef %0, ptr noundef %2, ptr noundef nonnull %42)
  %43 = getelementptr inbounds i8, ptr %2, i64 8
  tail call void @copyTV(ptr noundef %0, ptr noundef nonnull %43, ptr noundef nonnull %37)
  br label %.loopexit

.loopexit:                                        ; preds = %34, %26, %41, %20
  %.2 = phi i32 [ 1, %20 ], [ 1, %41 ], [ 0, %26 ], [ 0, %34 ]
  ret i32 %.2
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.usub.sat.i32(i32, i32) #2

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !8, i64 36}
!6 = !{!"GCtab", !7, i64 0, !9, i64 4, !9, i64 5, !9, i64 6, !9, i64 7, !11, i64 8, !7, i64 12, !7, i64 16, !12, i64 24, !11, i64 32, !8, i64 36, !8, i64 40}
!7 = !{!"GCRef", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"MRef", !8, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!6, !8, i64 8}
!14 = !{!9, !9, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !8, i64 40}
!18 = !{!6, !8, i64 32}
!19 = distinct !{!19, !16}


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