; LLVM IR from ramsdell/lineqpp :: lua (lvm)

; 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.Table = type { ptr, i8, i8, i8, i8, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.lua_State = type { ptr, i8, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i16, i16, i8, i8, i32, i32, ptr, %struct.lua_TValue, %struct.lua_TValue, ptr, ptr, ptr, i64 }
%struct.global_State = type { %struct.stringtable, ptr, ptr, i8, i8, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.Mbuffer, i64, i64, i64, i64, i32, i32, ptr, %struct.lua_TValue, ptr, %struct.UpVal, [9 x ptr], [17 x ptr] }
%struct.stringtable = type { ptr, i32, i32 }
%struct.Mbuffer = type { ptr, i64, i64 }
%struct.UpVal = type { ptr, i8, i8, ptr, %union.anon }
%union.anon = type { %struct.lua_TValue }

@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1

; 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 void @luaV_gettable(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %110, %4
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 100
  br i1 %18, label %19, label %113

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.lua_TValue, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp eq i32 %22, 5
  br i1 %23, label %24, label %83

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.lua_TValue, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  store ptr %27, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call ptr @luaH_get(ptr noundef %28, ptr noundef %29)
  store ptr %30, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.lua_TValue, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %67

35:                                               ; preds = %24
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Table, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  br label %64

41:                                               ; preds = %35
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Table, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds %struct.Table, ptr %44, i32 0, i32 3
  %46 = load i8, ptr %45, align 2, !tbaa !16
  %47 = zext i8 %46 to i32
  %48 = and i32 %47, 1
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %41
  br label %62

51:                                               ; preds = %41
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Table, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.lua_State, ptr %55, i32 0, i32 6
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %struct.global_State, ptr %57, i32 0, i32 24
  %59 = getelementptr inbounds [17 x ptr], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = call ptr @luaT_gettm(ptr noundef %54, i32 noundef 0, ptr noundef %60)
  br label %62

62:                                               ; preds = %51, %50
  %63 = phi ptr [ null, %50 ], [ %61, %51 ]
  br label %64

64:                                               ; preds = %62, %40
  %65 = phi ptr [ null, %40 ], [ %63, %62 ]
  store ptr %65, ptr %10, align 8, !tbaa !5
  %66 = icmp eq ptr %65, null
  br i1 %66, label %67, label %79

67:                                               ; preds = %64, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %68, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %69, ptr %14, align 8, !tbaa !5
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lua_TValue, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %13, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.lua_TValue, ptr %72, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %71, ptr align 8 %73, i64 8, i1 false), !tbaa.struct !21
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.lua_TValue, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !11
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.lua_TValue, ptr %77, i32 0, i32 1
  store i32 %76, ptr %78, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  store i32 1, ptr %15, align 4
  br label %80

79:                                               ; preds = %64
  store i32 0, ptr %15, align 4
  br label %80

80:                                               ; preds = %79, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %81 = load i32, ptr %15, align 4
  switch i32 %81, label %107 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %94

83:                                               ; preds = %19
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = call ptr @luaT_gettmbyobj(ptr noundef %84, ptr noundef %85, i32 noundef 0)
  store ptr %86, ptr %10, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.lua_TValue, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 8, !tbaa !11
  %89 = icmp eq i32 %88, 0
  br i1 %89, label %90, label %93

90:                                               ; preds = %83
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  call void @luaG_typeerror(ptr noundef %91, ptr noundef %92, ptr noundef @.str.1)
  br label %93

93:                                               ; preds = %90, %83
  br label %94

94:                                               ; preds = %93, %82
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.lua_TValue, ptr %95, i32 0, i32 1
  %97 = load i32, ptr %96, align 8, !tbaa !11
  %98 = icmp eq i32 %97, 6
  br i1 %98, label %99, label %105

99:                                               ; preds = %94
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  call void @callTMres(ptr noundef %100, ptr noundef %101, ptr noundef %102, ptr noundef %103, ptr noundef %104)
  store i32 1, ptr %15, align 4
  br label %107

105:                                              ; preds = %94
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %106, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %15, align 4
  br label %107

107:                                              ; preds = %105, %99, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %108 = load i32, ptr %15, align 4
  switch i32 %108, label %115 [
    i32 0, label %109
  ]

109:                                              ; preds = %107
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %9, align 4, !tbaa !9
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !22

113:                                              ; preds = %16
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, ...) @luaG_runerror(ptr noundef %114, ptr noundef @.str.2)
  store i32 0, ptr %15, align 4
  br label %115

115:                                              ; preds = %113, %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %116 = load i32, ptr %15, align 4
  switch i32 %116, label %118 [
    i32 0, label %117
    i32 1, label %117
  ]

117:                                              ; preds = %115, %115
  ret void

118:                                              ; preds = %115
  unreachable
}

declare hidden ptr @luaH_get(ptr noundef, ptr noundef) #2

declare hidden ptr @luaT_gettm(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare hidden ptr @luaT_gettmbyobj(ptr noundef, ptr noundef, i32 noundef) #2

declare hidden void @luaG_typeerror(ptr noundef, ptr noundef, ptr noundef) #2

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

declare hidden void @luaG_runerror(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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!12, !10, i64 8}
!12 = !{!"lua_TValue", !7, i64 0, !10, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"Table", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!16 = !{!15, !7, i64 10}
!17 = !{!18, !6, i64 32}
!18 = !{!"lua_State", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !19, i64 96, !19, i64 98, !7, i64 100, !7, i64 101, !10, i64 104, !10, i64 108, !6, i64 112, !12, i64 120, !12, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !20, i64 176}
!19 = !{!"short", !7, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{i64 0, i64 8, !13}
!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"

@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define hidden void @luaV_gettable(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 8
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %8

6:                                                ; preds = %.thread39
  %7 = add nuw nsw i32 %.03351, 1
  %exitcond.not = icmp eq i32 %7, 100
  br i1 %exitcond.not, label %45, label %8, !llvm.loop !10

8:                                                ; preds = %4, %6
  %9 = phi i32 [ %.pre, %4 ], [ %42, %6 ]
  %.03152 = phi ptr [ %1, %4 ], [ %.3, %6 ]
  %.03351 = phi i32 [ 0, %4 ], [ %7, %6 ]
  %10 = icmp eq i32 %9, 5
  br i1 %10, label %11, label %35

11:                                               ; preds = %8
  %12 = load ptr, ptr %.03152, align 8, !tbaa !12
  %13 = tail call ptr @luaH_get(ptr noundef %12, ptr noundef %2) #2
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %.thread

17:                                               ; preds = %11
  %18 = getelementptr inbounds i8, ptr %12, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %19, i64 10
  %23 = load i8, ptr %22, align 2, !tbaa !16
  %24 = and i8 %23, 1
  %.not = icmp eq i8 %24, 0
  br i1 %.not, label %25, label %.thread

25:                                               ; preds = %21
  %26 = load ptr, ptr %5, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %26, i64 296
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = tail call ptr @luaT_gettm(ptr noundef nonnull %19, i32 noundef 0, ptr noundef %28) #2
  %30 = icmp eq ptr %29, null
  br i1 %30, label %.thread, label %.thread39

.thread:                                          ; preds = %21, %17, %11, %25
  %31 = getelementptr inbounds i8, ptr %13, i64 8
  %32 = load i64, ptr %13, align 8, !tbaa !12
  store i64 %32, ptr %3, align 8, !tbaa !12
  %33 = load i32, ptr %31, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %33, ptr %34, align 8, !tbaa !5
  br label %.thread43

35:                                               ; preds = %8
  %36 = tail call ptr @luaT_gettmbyobj(ptr noundef %0, ptr noundef nonnull %.03152, i32 noundef 0) #2
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = load i32, ptr %37, align 8, !tbaa !5
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %.thread39

40:                                               ; preds = %35
  tail call void @luaG_typeerror(ptr noundef %0, ptr noundef nonnull %.03152, ptr noundef nonnull @.str.1) #2
  br label %.thread39

.thread39:                                        ; preds = %25, %35, %40
  %.3 = phi ptr [ %36, %40 ], [ %36, %35 ], [ %29, %25 ]
  %41 = getelementptr inbounds i8, ptr %.3, i64 8
  %42 = load i32, ptr %41, align 8, !tbaa !5
  %43 = icmp eq i32 %42, 6
  br i1 %43, label %44, label %6

44:                                               ; preds = %.thread39
  tail call void @callTMres(ptr noundef %0, ptr noundef %3, ptr noundef nonnull %.3, ptr noundef nonnull %.03152, ptr noundef %2)
  br label %.thread43

45:                                               ; preds = %6
  tail call void (ptr, ptr, ...) @luaG_runerror(ptr noundef %0, ptr noundef nonnull @.str.2) #2
  br label %.thread43

.thread43:                                        ; preds = %.thread, %44, %45
  ret void
}

declare hidden ptr @luaH_get(ptr noundef, ptr noundef) local_unnamed_addr #1

declare hidden ptr @luaT_gettm(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare hidden ptr @luaT_gettmbyobj(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare hidden void @luaG_typeerror(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare hidden void @luaG_runerror(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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 16}
!14 = !{!"Table", !15, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !9, i64 56}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!14, !7, i64 10}
!17 = !{!18, !15, i64 32}
!18 = !{!"lua_State", !15, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !9, i64 88, !9, i64 92, !19, i64 96, !19, i64 98, !7, i64 100, !7, i64 101, !9, i64 104, !9, i64 108, !15, i64 112, !6, i64 120, !6, i64 136, !15, i64 152, !15, i64 160, !15, i64 168, !20, i64 176}
!19 = !{!"short", !7, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!15, !15, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass