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

21:                                               ; preds = %37, %3
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = icmp ult i32 %25, -65537
  br i1 %26, label %27, label %36

27:                                               ; preds = %21
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 1
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = load double, ptr %8, align 8, !tbaa !11
  %32 = fcmp oeq double %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %27
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 0
  store ptr %35, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %49

36:                                               ; preds = %27, %21
  br label %37

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

45:                                               ; preds = %37
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call ptr @lj_tab_newkey(ptr noundef %46, ptr noundef %47, ptr noundef %8)
  store ptr %48, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %49

49:                                               ; preds = %45, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %50 = load ptr, ptr %4, align 8
  ret ptr %50
}

; 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

; Function Attrs: nounwind uwtable
declare hidden ptr @lj_tab_newkey(ptr noundef, ptr noundef, ptr 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 = { 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"

%union.TValue = type { i64 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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_setinth(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %union.TValue, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = sitofp i32 %2 to double
  store double %5, ptr %4, align 8, !tbaa !5
  %6 = bitcast double %5 to i64
  %7 = trunc i64 %6 to i32
  %sh.diff = lshr i64 %6, 31
  %tr.sh.diff = trunc i64 %sh.diff to i32
  %8 = and i32 %tr.sh.diff, -2
  %9 = tail call i32 @hashrot(i32 noundef %7, i32 noundef %8)
  %10 = tail call ptr @hashmask(ptr noundef %1, i32 noundef %9)
  br label %11

11:                                               ; preds = %19, %3
  %.0 = phi ptr [ %10, %3 ], [ %23, %19 ]
  %12 = getelementptr inbounds i8, ptr %.0, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ult i32 %13, -65537
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %.0, i64 8
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fcmp oeq double %17, %5
  br i1 %18, label %.loopexit, label %19

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

24:                                               ; preds = %19
  %25 = call ptr @lj_tab_newkey(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %4)
  br label %.loopexit

.loopexit:                                        ; preds = %15, %24
  %.08 = phi ptr [ %25, %24 ], [ %.0, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret ptr %.08
}

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

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

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

attributes #0 = { mustprogress 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 = !{!"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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass