; LLVM IR from ejoy/ejoy2d :: lua (ltable)

; 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.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }
%struct.Node = type { %struct.lua_TValue, %union.TKey }
%union.TKey = type { %struct.anon }
%struct.anon = type { %union.Value, i32, i32 }

@luaO_nilobject_ = external hidden constant %struct.lua_TValue, align 8

; 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 i32 @numisinteger(double noundef, ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define hidden ptr @luaH_get(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.lua_TValue, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = and i32 %12, 63
  switch i32 %13, label %41 [
    i32 4, label %14
    i32 19, label %20
    i32 0, label %26
    i32 3, label %27
  ]

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.lua_TValue, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = call ptr @luaH_getstr(ptr noundef %15, ptr noundef %18)
  store ptr %19, ptr %3, align 8
  br label %73

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_TValue, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %25 = call ptr @luaH_getint(ptr noundef %21, i64 noundef %24)
  store ptr %25, ptr %3, align 8
  br label %73

26:                                               ; preds = %2
  store ptr @luaO_nilobject_, ptr %3, align 8
  br label %73

27:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.lua_TValue, ptr %28, i32 0, i32 0
  %30 = load double, ptr %29, align 8, !tbaa !12
  %31 = call i32 @numisinteger(double noundef %30, ptr noundef %6)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %27
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !13
  %36 = call ptr @luaH_getint(ptr noundef %34, i64 noundef %35)
  store ptr %36, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %38

37:                                               ; preds = %27
  store i32 0, ptr %7, align 4
  br label %38

38:                                               ; preds = %37, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %39 = load i32, ptr %7, align 4
  switch i32 %39, label %75 [
    i32 0, label %40
    i32 1, label %73
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call ptr @mainposition(ptr noundef %42, ptr noundef %43)
  store ptr %44, ptr %8, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %70, %41
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call i32 @luaV_equalobj(ptr noundef null, ptr noundef %47, ptr noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %45
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 0
  store ptr %53, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

54:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Node, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !12
  store i32 %58, ptr %9, align 4, !tbaa !15
  %59 = load i32, ptr %9, align 4, !tbaa !15
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %54
  store i32 3, ptr %7, align 4
  br label %67

62:                                               ; preds = %54
  %63 = load i32, ptr %9, align 4, !tbaa !15
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = sext i32 %63 to i64
  %66 = getelementptr inbounds %struct.Node, ptr %64, i64 %65
  store ptr %66, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %67

67:                                               ; preds = %62, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %68 = load i32, ptr %7, align 4
  switch i32 %68, label %75 [
    i32 0, label %69
    i32 3, label %71
  ]

69:                                               ; preds = %67
  br label %70

70:                                               ; preds = %69
  br label %45

71:                                               ; preds = %67
  store ptr @luaO_nilobject_, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

72:                                               ; preds = %71, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %73

73:                                               ; preds = %72, %38, %26, %20, %14
  %74 = load ptr, ptr %3, align 8
  ret ptr %74

75:                                               ; preds = %67, %38
  unreachable
}

declare hidden i32 @luaV_equalobj(ptr noundef, 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 = !{!10, !11, i64 8}
!10 = !{!"lua_TValue", !7, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!11, !11, i64 0}


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

%struct.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }
%struct.Node = type { %struct.lua_TValue, %union.TKey }
%union.TKey = type { %struct.anon }
%struct.anon = type { %union.Value, i32, i32 }

@luaO_nilobject_ = external hidden constant %struct.lua_TValue, align 8

; 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
declare hidden i32 @numisinteger(double noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define hidden ptr @luaH_get(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = and i32 %5, 63
  switch i32 %6, label %19 [
    i32 4, label %7
    i32 19, label %10
    i32 0, label %.loopexit
    i32 3, label %13
  ]

7:                                                ; preds = %2
  %8 = load ptr, ptr %1, align 8, !tbaa !10
  %9 = tail call ptr @luaH_getstr(ptr noundef %0, ptr noundef %8)
  br label %.loopexit

10:                                               ; preds = %2
  %11 = load i64, ptr %1, align 8, !tbaa !10
  %12 = tail call ptr @luaH_getint(ptr noundef %0, i64 noundef %11)
  br label %.loopexit

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %14 = load double, ptr %1, align 8, !tbaa !10
  %15 = call i32 @numisinteger(double noundef %14, ptr noundef nonnull %3)
  %.not.not = icmp eq i32 %15, 0
  br i1 %.not.not, label %.thread, label %16

.thread:                                          ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %19

16:                                               ; preds = %13
  %17 = load i64, ptr %3, align 8, !tbaa !11
  %18 = call ptr @luaH_getint(ptr noundef %0, i64 noundef %17)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %.loopexit

19:                                               ; preds = %.thread, %2
  %20 = call ptr @mainposition(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

21:                                               ; preds = %24, %19
  %.018 = phi ptr [ %20, %19 ], [ %29, %24 ]
  %22 = getelementptr inbounds i8, ptr %.018, i64 16
  %23 = call i32 @luaV_equalobj(ptr noundef null, ptr noundef nonnull %22, ptr noundef %1) #3
  %.not23 = icmp eq i32 %23, 0
  br i1 %.not23, label %24, label %.loopexit

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %.018, i64 28
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %27 = icmp eq i32 %26, 0
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds %struct.Node, ptr %.018, i64 %28
  br i1 %27, label %.loopexit, label %21

.loopexit:                                        ; preds = %24, %21, %16, %2, %10, %7
  %.2 = phi ptr [ %18, %16 ], [ %12, %10 ], [ %9, %7 ], [ @luaO_nilobject_, %2 ], [ @luaO_nilobject_, %24 ], [ %.018, %21 ]
  ret ptr %.2
}

declare hidden i32 @luaV_equalobj(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { "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, !9, i64 8}
!6 = !{!"lua_TValue", !7, i64 0, !9, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}


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