; 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.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }
%struct.GCRef = type { i32 }
%struct.GCtab = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, %struct.MRef, i32, i32 }
%struct.MRef = type { i32 }
%union.TValue = type { i64 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.lua_State = type { %union.anon.2 }
%union.anon.2 = type { %struct.anon.3, [320 x i8] }
%struct.anon.3 = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.global_State = type { ptr, i32, i32, ptr, ptr, %struct.GCState, i32, %struct.SBuf, %struct.GCstr, i8, i8, i8, i8, %struct.GCRef, %union.TValue, %union.TValue, %union.TValue, %struct.Node, %struct.GCupval, i32, i32, ptr, ptr, ptr, i32, i32, %struct.GCRef, %struct.MRef, %struct.MRef, [38 x %struct.GCRef] }
%struct.GCState = type { i32, i32, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, i32, i32, i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.4, %struct.MRef, i32 }
%union.anon.4 = type { %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
declare hidden ptr @lj_tab_getinth(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_tab_get(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = 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
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.anon, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp eq i32 %16, -5
  br i1 %17, label %18, label %35

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.GCRef, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  %26 = call ptr @lj_tab_getstr(ptr noundef %19, ptr noundef %25)
  store ptr %26, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %31

29:                                               ; preds = %18
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %32

31:                                               ; preds = %18
  store i32 0, ptr %9, align 4
  br label %32

32:                                               ; preds = %31, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %33 = load i32, ptr %9, align 4
  switch i32 %33, label %127 [
    i32 0, label %34
    i32 1, label %125
  ]

34:                                               ; preds = %32
  br label %115

35:                                               ; preds = %3
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp ult i32 %38, -65537
  br i1 %39, label %40, label %84

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load double, ptr %41, align 8, !tbaa !9
  store double %42, ptr %10, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %43 = load double, ptr %10, align 8, !tbaa !10
  %44 = fptosi double %43 to i32
  store i32 %44, ptr %11, align 4, !tbaa !12
  %45 = load double, ptr %10, align 8, !tbaa !10
  %46 = load i32, ptr %11, align 4, !tbaa !12
  %47 = sitofp i32 %46 to double
  %48 = fcmp oeq double %45, %47
  br i1 %48, label %49, label %79

49:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %50 = load i32, ptr %11, align 4, !tbaa !12
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.GCtab, ptr %51, i32 0, i32 10
  %53 = load i32, ptr %52, align 4, !tbaa !14
  %54 = icmp ult i32 %50, %53
  br i1 %54, label %55, label %65

55:                                               ; preds = %49
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.GCtab, ptr %56, i32 0, i32 5
  %58 = getelementptr inbounds %struct.MRef, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !18
  %60 = zext i32 %59 to i64
  %61 = inttoptr i64 %60 to ptr
  %62 = load i32, ptr %11, align 4, !tbaa !12
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %union.TValue, ptr %61, i64 %63
  br label %69

65:                                               ; preds = %49
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %11, align 4, !tbaa !12
  %68 = call ptr @lj_tab_getinth(ptr noundef %66, i32 noundef %67)
  br label %69

69:                                               ; preds = %65, %55
  %70 = phi ptr [ %64, %55 ], [ %68, %65 ]
  store ptr %70, ptr %12, align 8, !tbaa !5
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %75

73:                                               ; preds = %69
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %74, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %76

75:                                               ; preds = %69
  store i32 0, ptr %9, align 4
  br label %76

76:                                               ; preds = %75, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %77 = load i32, ptr %9, align 4
  switch i32 %77, label %81 [
    i32 0, label %78
  ]

78:                                               ; preds = %76
  br label %80

79:                                               ; preds = %40
  store i32 2, ptr %9, align 4
  br label %81

80:                                               ; preds = %78
  store i32 0, ptr %9, align 4
  br label %81

81:                                               ; preds = %80, %79, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %82 = load i32, ptr %9, align 4
  switch i32 %82, label %127 [
    i32 0, label %83
    i32 1, label %125
    i32 2, label %90
  ]

83:                                               ; preds = %81
  br label %114

84:                                               ; preds = %35
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.anon, ptr %85, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = icmp eq i32 %87, -1
  br i1 %88, label %113, label %89

89:                                               ; preds = %84
  br label %90

90:                                               ; preds = %89, %81
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = call ptr @hashkey(ptr noundef %91, ptr noundef %92)
  store ptr %93, ptr %13, align 8, !tbaa !5
  br label %94

94:                                               ; preds = %104, %90
  %95 = load ptr, ptr %13, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.Node, ptr %95, i32 0, i32 1
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = call i32 @lj_obj_equal(ptr noundef %96, ptr noundef %97)
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %103

100:                                              ; preds = %94
  %101 = load ptr, ptr %13, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Node, ptr %101, i32 0, i32 0
  store ptr %102, ptr %4, align 8
  br label %125

103:                                              ; preds = %94
  br label %104

104:                                              ; preds = %103
  %105 = load ptr, ptr %13, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.Node, ptr %105, i32 0, i32 2
  %107 = getelementptr inbounds %struct.MRef, ptr %106, i32 0, i32 0
  %108 = load i32, ptr %107, align 8, !tbaa !19
  %109 = zext i32 %108 to i64
  %110 = inttoptr i64 %109 to ptr
  store ptr %110, ptr %13, align 8, !tbaa !5
  %111 = icmp ne ptr %110, null
  br i1 %111, label %94, label %112, !llvm.loop !21

112:                                              ; preds = %104
  br label %113

113:                                              ; preds = %112, %84
  br label %114

114:                                              ; preds = %113, %83
  br label %115

115:                                              ; preds = %114, %34
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.lua_State, ptr %116, i32 0, i32 0
  %118 = getelementptr inbounds %struct.anon.3, ptr %117, i32 0, i32 5
  %119 = getelementptr inbounds %struct.MRef, ptr %118, i32 0, i32 0
  %120 = load i32, ptr %119, align 8, !tbaa !9
  %121 = zext i32 %120 to i64
  %122 = inttoptr i64 %121 to ptr
  %123 = getelementptr inbounds %struct.global_State, ptr %122, i32 0, i32 17
  %124 = getelementptr inbounds %struct.Node, ptr %123, i32 0, i32 0
  store ptr %124, ptr %4, align 8
  br label %125

125:                                              ; preds = %115, %100, %81, %32
  %126 = load ptr, ptr %4, align 8
  ret ptr %126

127:                                              ; preds = %81, %32
  unreachable
}

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

declare hidden i32 @lj_obj_equal(ptr noundef, 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 = !{!"double", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 36}
!15 = !{!"GCtab", !16, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !17, i64 8, !16, i64 12, !16, i64 16, !6, i64 24, !17, i64 32, !13, i64 36, !13, i64 40}
!16 = !{!"GCRef", !13, i64 0}
!17 = !{!"MRef", !13, i64 0}
!18 = !{!15, !13, i64 8}
!19 = !{!20, !13, i64 16}
!20 = !{!"Node", !7, i64 0, !7, i64 8, !17, i64 16, !17, i64 20}
!21 = distinct !{!21, !22}
!22 = !{!"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.TValue = type { i64 }

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

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_tab_get(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, -5
  br i1 %6, label %7, label %12

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 8, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  %11 = tail call ptr @lj_tab_getstr(ptr noundef %1, ptr noundef %10)
  %.not38.not = icmp eq ptr %11, null
  br i1 %.not38.not, label %.thread, label %.thread41

12:                                               ; preds = %3
  %13 = icmp ult i32 %5, -65537
  br i1 %13, label %14, label %34

14:                                               ; preds = %12
  %15 = load double, ptr %2, align 8, !tbaa !5
  %16 = fptosi double %15 to i32
  %17 = sitofp i32 %16 to double
  %18 = fcmp oeq double %15, %17
  br i1 %18, label %19, label %36

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %1, i64 36
  %21 = load i32, ptr %20, align 4, !tbaa !8
  %22 = icmp ugt i32 %21, %16
  br i1 %22, label %23, label %30

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = zext i32 %25 to i64
  %27 = inttoptr i64 %26 to ptr
  %28 = sext i32 %16 to i64
  %29 = getelementptr inbounds %union.TValue, ptr %27, i64 %28
  br label %32

30:                                               ; preds = %19
  %31 = tail call ptr @lj_tab_getinth(ptr noundef nonnull %1, i32 noundef %16)
  br label %32

32:                                               ; preds = %30, %23
  %33 = phi ptr [ %29, %23 ], [ %31, %30 ]
  %.not = icmp eq ptr %33, null
  br i1 %.not, label %.thread, label %.thread41

34:                                               ; preds = %12
  %35 = icmp eq i32 %5, -1
  br i1 %35, label %.thread, label %36

36:                                               ; preds = %14, %34
  %37 = tail call ptr @hashkey(ptr noundef %1, ptr noundef nonnull %2)
  br label %38

38:                                               ; preds = %41, %36
  %.0 = phi ptr [ %37, %36 ], [ %45, %41 ]
  %39 = getelementptr inbounds i8, ptr %.0, i64 8
  %40 = tail call i32 @lj_obj_equal(ptr noundef nonnull %39, ptr noundef %2) #2
  %.not36 = icmp eq i32 %40, 0
  br i1 %.not36, label %41, label %.thread41

41:                                               ; preds = %38
  %42 = getelementptr inbounds i8, ptr %.0, i64 16
  %43 = load i32, ptr %42, align 8, !tbaa !15
  %44 = zext i32 %43 to i64
  %45 = inttoptr i64 %44 to ptr
  %.not37 = icmp eq i32 %43, 0
  br i1 %.not37, label %.thread, label %38, !llvm.loop !17

.thread:                                          ; preds = %41, %32, %7, %34
  %46 = getelementptr inbounds i8, ptr %0, i64 8
  %47 = load i32, ptr %46, align 8, !tbaa !5
  %48 = zext i32 %47 to i64
  %49 = inttoptr i64 %48 to ptr
  %50 = getelementptr inbounds i8, ptr %49, i64 160
  br label %.thread41

.thread41:                                        ; preds = %38, %32, %7, %.thread
  %.3 = phi ptr [ %11, %7 ], [ %50, %.thread ], [ %33, %32 ], [ %.0, %38 ]
  ret ptr %.3
}

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

declare hidden i32 @lj_obj_equal(ptr noundef, 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, !11, i64 36}
!9 = !{!"GCtab", !10, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !12, i64 8, !10, i64 12, !10, i64 16, !13, i64 24, !12, i64 32, !11, i64 36, !11, i64 40}
!10 = !{!"GCRef", !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"MRef", !11, i64 0}
!13 = !{!"any pointer", !6, i64 0}
!14 = !{!9, !11, i64 8}
!15 = !{!16, !11, i64 16}
!16 = !{!"Node", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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