; LLVM IR from ramsdell/lineqpp :: 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, ptr }

@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 ptr @luaH_getnum(ptr noundef, i32 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 i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  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
  switch i32 %12, label %40 [
    i32 0, label %13
    i32 4, label %14
    i32 3, label %20
  ]

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

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 %64

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.lua_TValue, ptr %21, i32 0, i32 0
  %23 = load double, ptr %22, align 8, !tbaa !12
  store double %23, ptr %7, align 8, !tbaa !13
  %24 = load double, ptr %7, align 8, !tbaa !13
  %25 = fptosi double %24 to i32
  store i32 %25, ptr %6, align 4, !tbaa !15
  %26 = load i32, ptr %6, align 4, !tbaa !15
  %27 = sitofp i32 %26 to double
  %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 = fcmp oeq double %27, %30
  br i1 %31, label %32, label %36

32:                                               ; preds = %20
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !15
  %35 = call ptr @luaH_getnum(ptr noundef %33, i32 noundef %34)
  store ptr %35, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %37

36:                                               ; preds = %20
  store i32 0, ptr %8, align 4
  br label %37

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

39:                                               ; preds = %37
  br label %40

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

44:                                               ; preds = %59, %40
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Node, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call i32 @luaO_rawequalObj(ptr noundef %46, ptr noundef %47)
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %44
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 0
  store ptr %52, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

53:                                               ; preds = %44
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds %struct.anon, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !12
  store ptr %57, ptr %9, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %53
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %44, label %62, !llvm.loop !16

62:                                               ; preds = %59
  store ptr @luaO_nilobject_, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

63:                                               ; preds = %62, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %64

64:                                               ; preds = %63, %37, %14, %13
  %65 = load ptr, ptr %3, align 8
  ret ptr %65

66:                                               ; preds = %37
  unreachable
}

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

declare hidden i32 @luaO_rawequalObj(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 = !{!"double", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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

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

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

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

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

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

8:                                                ; preds = %2
  %9 = load double, ptr %1, align 8, !tbaa !10
  %10 = fptosi double %9 to i32
  %11 = sitofp i32 %10 to double
  %12 = fcmp oeq double %9, %11
  br i1 %12, label %13, label %.thread

13:                                               ; preds = %8
  %14 = tail call ptr @luaH_getnum(ptr noundef %0, i32 noundef %10)
  br label %.loopexit

.thread:                                          ; preds = %8, %2
  %15 = tail call ptr @mainposition(ptr noundef %0, ptr noundef nonnull %1)
  br label %16

16:                                               ; preds = %19, %.thread
  %.0 = phi ptr [ %15, %.thread ], [ %21, %19 ]
  %17 = getelementptr inbounds i8, ptr %.0, i64 16
  %18 = tail call i32 @luaO_rawequalObj(ptr noundef nonnull %17, ptr noundef %1) #2
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %.loopexit

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %.0, i64 32
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %.not20 = icmp eq ptr %21, null
  br i1 %.not20, label %.loopexit, label %16, !llvm.loop !11

.loopexit:                                        ; preds = %16, %19, %13, %2, %5
  %.2 = phi ptr [ %14, %13 ], [ %7, %5 ], [ @luaO_nilobject_, %2 ], [ @luaO_nilobject_, %19 ], [ %.0, %16 ]
  ret ptr %.2
}

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

declare hidden i32 @luaO_rawequalObj(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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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