; 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 }
%struct.anon = type { %union.anon, i32 }
%union.anon = type { %struct.GCRef }
%union.TValue = type { i64 }
%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: noreturn
declare hidden void @lj_err_msg(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define hidden ptr @lj_tab_set(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %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
  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 8, ptr %8) #4
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.GCtab, ptr %12, i32 0, i32 3
  store i8 0, ptr %13, align 2, !tbaa !9
  %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 !14
  %17 = icmp eq i32 %16, -5
  br i1 %17, label %18, label %28

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.GCRef, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = zext i32 %24 to i64
  %26 = inttoptr i64 %25 to ptr
  %27 = call ptr @lj_tab_setstr(ptr noundef %19, ptr noundef %20, ptr noundef %26)
  store ptr %27, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %113

28:                                               ; preds = %3
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = icmp ult i32 %31, -65537
  br i1 %32, label %33, label %77

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load double, ptr %34, align 8, !tbaa !14
  store double %35, ptr %10, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %36 = load double, ptr %10, align 8, !tbaa !15
  %37 = fptosi double %36 to i32
  store i32 %37, ptr %11, align 4, !tbaa !17
  %38 = load double, ptr %10, align 8, !tbaa !15
  %39 = load i32, ptr %11, align 4, !tbaa !17
  %40 = sitofp i32 %39 to double
  %41 = fcmp oeq double %38, %40
  br i1 %41, label %42, label %65

42:                                               ; preds = %33
  %43 = load i32, ptr %11, align 4, !tbaa !17
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.GCtab, ptr %44, i32 0, i32 10
  %46 = load i32, ptr %45, align 4, !tbaa !18
  %47 = icmp ult i32 %43, %46
  br i1 %47, label %48, label %58

48:                                               ; preds = %42
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.GCtab, ptr %49, i32 0, i32 5
  %51 = getelementptr inbounds %struct.MRef, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !19
  %53 = zext i32 %52 to i64
  %54 = inttoptr i64 %53 to ptr
  %55 = load i32, ptr %11, align 4, !tbaa !17
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %union.TValue, ptr %54, i64 %56
  br label %63

58:                                               ; preds = %42
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !17
  %62 = call ptr @lj_tab_setinth(ptr noundef %59, ptr noundef %60, i32 noundef %61)
  br label %63

63:                                               ; preds = %58, %48
  %64 = phi ptr [ %57, %48 ], [ %62, %58 ]
  store ptr %64, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %74

65:                                               ; preds = %33
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load double, ptr %66, align 8, !tbaa !14
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load double, ptr %68, align 8, !tbaa !14
  %70 = fcmp une double %67, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %65
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lj_err_msg(ptr noundef %72, i32 noundef 154) #5
  unreachable

73:                                               ; preds = %65
  store i32 0, ptr %9, align 4
  br label %74

74:                                               ; preds = %73, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %75 = load i32, ptr %9, align 4
  switch i32 %75, label %113 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  br label %85

77:                                               ; preds = %28
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !14
  %81 = icmp eq i32 %80, -1
  br i1 %81, label %82, label %84

82:                                               ; preds = %77
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lj_err_msg(ptr noundef %83, i32 noundef 173) #5
  unreachable

84:                                               ; preds = %77
  br label %85

85:                                               ; preds = %84, %76
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = call ptr @hashkey(ptr noundef %87, ptr noundef %88)
  store ptr %89, ptr %8, align 8, !tbaa !5
  br label %90

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

96:                                               ; preds = %90
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.Node, ptr %97, i32 0, i32 0
  store ptr %98, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %113

99:                                               ; preds = %90
  br label %100

100:                                              ; preds = %99
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Node, ptr %101, i32 0, i32 2
  %103 = getelementptr inbounds %struct.MRef, ptr %102, i32 0, i32 0
  %104 = load i32, ptr %103, align 8, !tbaa !20
  %105 = zext i32 %104 to i64
  %106 = inttoptr i64 %105 to ptr
  store ptr %106, ptr %8, align 8, !tbaa !5
  %107 = icmp ne ptr %106, null
  br i1 %107, label %90, label %108, !llvm.loop !22

108:                                              ; preds = %100
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = call ptr @lj_tab_newkey(ptr noundef %109, ptr noundef %110, ptr noundef %111)
  store ptr %112, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %113

113:                                              ; preds = %108, %96, %74, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %114 = load ptr, ptr %4, align 8
  ret ptr %114
}

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

declare hidden i32 @lj_obj_equal(ptr noundef, ptr noundef) #3

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 = { "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 #4 = { nounwind }
attributes #5 = { noreturn }

!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, !7, i64 6}
!10 = !{!"GCtab", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !13, i64 32, !12, i64 36, !12, i64 40}
!11 = !{!"GCRef", !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"MRef", !12, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !12, i64 36}
!19 = !{!10, !12, i64 8}
!20 = !{!21, !12, i64 16}
!21 = !{!"Node", !7, i64 0, !7, i64 8, !13, i64 16, !13, i64 20}
!22 = distinct !{!22, !23}
!23 = !{!"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: noreturn
declare hidden void @lj_err_msg(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

8:                                                ; preds = %3
  %9 = load i32, ptr %2, align 8, !tbaa !13
  %10 = zext i32 %9 to i64
  %11 = inttoptr i64 %10 to ptr
  %12 = tail call ptr @lj_tab_setstr(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %11)
  br label %.thread

13:                                               ; preds = %3
  %14 = icmp ult i32 %6, -65537
  br i1 %14, label %15, label %36

15:                                               ; preds = %13
  %16 = load double, ptr %2, align 8, !tbaa !13
  %17 = fptosi double %16 to i32
  %18 = sitofp i32 %17 to double
  %19 = fcmp une double %16, %18
  br i1 %19, label %33, label %20

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %1, i64 36
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = icmp ugt i32 %22, %17
  br i1 %23, label %24, label %31

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %1, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = zext i32 %26 to i64
  %28 = inttoptr i64 %27 to ptr
  %29 = sext i32 %17 to i64
  %30 = getelementptr inbounds %union.TValue, ptr %28, i64 %29
  br label %.thread

31:                                               ; preds = %20
  %32 = tail call ptr @lj_tab_setinth(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %17)
  br label %.thread

33:                                               ; preds = %15
  %34 = fcmp uno double %16, 0.000000e+00
  br i1 %34, label %35, label %39

35:                                               ; preds = %33
  tail call void @lj_err_msg(ptr noundef %0, i32 noundef 154) #3
  unreachable

36:                                               ; preds = %13
  %37 = icmp eq i32 %6, -1
  br i1 %37, label %38, label %39

38:                                               ; preds = %36
  tail call void @lj_err_msg(ptr noundef %0, i32 noundef 173) #3
  unreachable

39:                                               ; preds = %33, %36
  %40 = tail call ptr @hashkey(ptr noundef nonnull %1, ptr noundef nonnull %2)
  br label %41

41:                                               ; preds = %44, %39
  %.032 = phi ptr [ %40, %39 ], [ %48, %44 ]
  %42 = getelementptr inbounds i8, ptr %.032, i64 8
  %43 = tail call i32 @lj_obj_equal(ptr noundef nonnull %42, ptr noundef %2) #4
  %.not = icmp eq i32 %43, 0
  br i1 %.not, label %44, label %.thread

44:                                               ; preds = %41
  %45 = getelementptr inbounds i8, ptr %.032, i64 16
  %46 = load i32, ptr %45, align 8, !tbaa !16
  %47 = zext i32 %46 to i64
  %48 = inttoptr i64 %47 to ptr
  %.not39 = icmp eq i32 %46, 0
  br i1 %.not39, label %49, label %41, !llvm.loop !18

49:                                               ; preds = %44
  %50 = tail call ptr @lj_tab_newkey(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  br label %.thread

.thread:                                          ; preds = %41, %31, %24, %49, %8
  %.1 = phi ptr [ %12, %8 ], [ %50, %49 ], [ %32, %31 ], [ %30, %24 ], [ %.032, %41 ]
  ret ptr %.1
}

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

declare hidden i32 @lj_obj_equal(ptr noundef, ptr 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

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

attributes #0 = { noreturn "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 = { "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 = { noreturn nounwind }
attributes #4 = { 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, !9, i64 6}
!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 = !{!9, !9, i64 0}
!14 = !{!6, !8, i64 36}
!15 = !{!6, !8, i64 8}
!16 = !{!17, !8, i64 16}
!17 = !{!"Node", !9, i64 0, !9, i64 8, !11, i64 16, !11, i64 20}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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