; 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"

%union.TValue = type { i64 }
%struct.anon.1 = type { i32, i32 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }
%struct.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }
%struct.GCRef = type { i32 }

; 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_tab_getinth(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %union.TValue, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = sitofp i32 %9 to double
  store double %10, ptr %6, align 8, !tbaa !11
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.anon.1, ptr %6, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.anon.1, ptr %6, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = shl i32 %15, 1
  %17 = call i32 @hashrot(i32 noundef %13, i32 noundef %16)
  %18 = call ptr @hashmask(ptr noundef %11, i32 noundef %17)
  store ptr %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %35, %2
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp ult i32 %23, -65537
  br i1 %24, label %25, label %34

25:                                               ; preds = %19
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 1
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = load double, ptr %6, align 8, !tbaa !11
  %30 = fcmp oeq double %28, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Node, ptr %32, i32 0, i32 0
  store ptr %33, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %44

34:                                               ; preds = %25, %19
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.MRef, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !12
  %40 = zext i32 %39 to i64
  %41 = inttoptr i64 %40 to ptr
  store ptr %41, ptr %7, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %19, label %43, !llvm.loop !15

43:                                               ; preds = %35
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %44

44:                                               ; preds = %43, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %45 = load ptr, ptr %3, align 8
  ret ptr %45
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @hashrot(i32 noundef, i32 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 = { 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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 16}
!13 = !{!"Node", !7, i64 0, !7, i64 8, !14, i64 16, !14, i64 20}
!14 = !{!"MRef", !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nounwind uwtable
define hidden ptr @lj_tab_getinth(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sitofp i32 %1 to double
  %4 = bitcast double %3 to i64
  %.sroa.0.0.extract.trunc = trunc i64 %4 to i32
  %sh.diff = lshr i64 %4, 31
  %tr.sh.diff = trunc i64 %sh.diff to i32
  %5 = and i32 %tr.sh.diff, -2
  %6 = tail call i32 @hashrot(i32 noundef %.sroa.0.0.extract.trunc, i32 noundef %5)
  %7 = tail call ptr @hashmask(ptr noundef %0, i32 noundef %6)
  br label %8

8:                                                ; preds = %16, %2
  %.0 = phi ptr [ %7, %2 ], [ %20, %16 ]
  %9 = getelementptr inbounds i8, ptr %.0, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp ult i32 %10, -65537
  br i1 %11, label %12, label %16

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %.0, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fcmp oeq double %14, %3
  br i1 %15, label %21, label %16

16:                                               ; preds = %8, %12
  %17 = getelementptr inbounds i8, ptr %.0, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !8
  %19 = zext i32 %18 to i64
  %20 = inttoptr i64 %19 to ptr
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %21, label %8, !llvm.loop !12

21:                                               ; preds = %16, %12
  %.06 = phi ptr [ %.0, %12 ], [ null, %16 ]
  ret ptr %.06
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @hashrot(i32 noundef, i32 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 = { 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" }

!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 16}
!9 = !{!"Node", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!10 = !{!"MRef", !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass