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

; 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.LexState = type { i32, i32, i32, %struct.Token, %struct.Token, ptr, ptr, ptr, ptr, ptr, i8 }
%struct.Token = type { i32, %union.SemInfo }
%union.SemInfo = type { double }
%struct.FuncState = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i16, i8, [60 x %struct.upvaldesc], [200 x i16] }
%struct.upvaldesc = type { i8, i8 }
%struct.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }
%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 }

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

declare hidden ptr @luaS_newlstr(ptr noundef, ptr noundef, i64 noundef) #1

; 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 @luaX_newstring(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.LexState, ptr %11, i32 0, i32 6
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = call ptr @luaS_newlstr(ptr noundef %14, ptr noundef %15, i64 noundef %16)
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.LexState, ptr %19, i32 0, i32 5
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds %struct.FuncState, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call ptr @luaH_setstr(ptr noundef %18, ptr noundef %23, ptr noundef %24)
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.lua_TValue, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %50

30:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %31, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lua_TValue, ptr %32, i32 0, i32 0
  store i32 1, ptr %33, align 8, !tbaa !21
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.lua_TValue, ptr %34, i32 0, i32 1
  store i32 1, ptr %35, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lua_State, ptr %36, i32 0, i32 6
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  %39 = getelementptr inbounds %struct.global_State, ptr %38, i32 0, i32 14
  %40 = load i64, ptr %39, align 8, !tbaa !24
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.lua_State, ptr %41, i32 0, i32 6
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  %44 = getelementptr inbounds %struct.global_State, ptr %43, i32 0, i32 13
  %45 = load i64, ptr %44, align 8, !tbaa !29
  %46 = icmp uge i64 %40, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %30
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  call void @luaC_step(ptr noundef %48)
  br label %49

49:                                               ; preds = %47, %30
  br label %50

50:                                               ; preds = %49, %3
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %51
}

declare hidden ptr @luaH_setstr(ptr noundef, ptr noundef, ptr noundef) #1

declare hidden void @luaC_step(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 56}
!12 = !{!"LexState", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !14, i64 32, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !7, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"Token", !13, i64 0, !7, i64 8}
!15 = !{!12, !6, i64 48}
!16 = !{!17, !6, i64 8}
!17 = !{!"FuncState", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !18, i64 72, !7, i64 74, !7, i64 75, !7, i64 196}
!18 = !{!"short", !7, i64 0}
!19 = !{!20, !13, i64 8}
!20 = !{!"lua_TValue", !7, i64 0, !13, i64 8}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !6, i64 32}
!23 = !{!"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, !13, i64 88, !13, i64 92, !18, i64 96, !18, i64 98, !7, i64 100, !7, i64 101, !13, i64 104, !13, i64 108, !6, i64 112, !20, i64 120, !20, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176}
!24 = !{!25, !10, i64 120}
!25 = !{!"global_State", !26, i64 0, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !13, i64 36, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !27, i64 88, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !13, i64 144, !13, i64 148, !6, i64 152, !20, i64 160, !6, i64 176, !28, i64 184, !7, i64 224, !7, i64 296}
!26 = !{!"stringtable", !6, i64 0, !13, i64 8, !13, i64 12}
!27 = !{!"Mbuffer", !6, i64 0, !10, i64 8, !10, i64 16}
!28 = !{!"UpVal", !6, i64 0, !7, i64 8, !7, i64 9, !6, i64 16, !7, i64 24}
!29 = !{!25, !10, i64 112}


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

declare hidden ptr @luaS_newlstr(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden noundef ptr @luaX_newstring(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call ptr @luaS_newlstr(ptr noundef %5, ptr noundef %1, i64 noundef %2) #2
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = tail call ptr @luaH_setstr(ptr noundef %5, ptr noundef %10, ptr noundef %6) #2
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %3
  store i32 1, ptr %11, align 8, !tbaa !18
  store i32 1, ptr %12, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %5, i64 32
  %17 = load ptr, ptr %16, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %17, i64 120
  %19 = load i64, ptr %18, align 8, !tbaa !22
  %20 = getelementptr inbounds i8, ptr %17, i64 112
  %21 = load i64, ptr %20, align 8, !tbaa !27
  %.not = icmp ult i64 %19, %21
  br i1 %.not, label %23, label %22

22:                                               ; preds = %15
  tail call void @luaC_step(ptr noundef nonnull %5) #2
  br label %23

23:                                               ; preds = %15, %22, %3
  ret ptr %6
}

declare hidden ptr @luaH_setstr(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare hidden void @luaC_step(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !11, i64 56}
!6 = !{!"LexState", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 32, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !8, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Token", !7, i64 0, !8, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 48}
!13 = !{!14, !11, i64 8}
!14 = !{!"FuncState", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !15, i64 72, !8, i64 74, !8, i64 75, !8, i64 196}
!15 = !{!"short", !8, i64 0}
!16 = !{!17, !7, i64 8}
!17 = !{!"lua_TValue", !8, i64 0, !7, i64 8}
!18 = !{!8, !8, i64 0}
!19 = !{!20, !11, i64 32}
!20 = !{!"lua_State", !11, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !7, i64 88, !7, i64 92, !15, i64 96, !15, i64 98, !8, i64 100, !8, i64 101, !7, i64 104, !7, i64 108, !11, i64 112, !17, i64 120, !17, i64 136, !11, i64 152, !11, i64 160, !11, i64 168, !21, i64 176}
!21 = !{!"long", !8, i64 0}
!22 = !{!23, !21, i64 120}
!23 = !{!"global_State", !24, i64 0, !11, i64 16, !11, i64 24, !8, i64 32, !8, i64 33, !7, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !25, i64 88, !21, i64 112, !21, i64 120, !21, i64 128, !21, i64 136, !7, i64 144, !7, i64 148, !11, i64 152, !17, i64 160, !11, i64 176, !26, i64 184, !8, i64 224, !8, i64 296}
!24 = !{!"stringtable", !11, i64 0, !7, i64 8, !7, i64 12}
!25 = !{!"Mbuffer", !11, i64 0, !21, i64 8, !21, i64 16}
!26 = !{!"UpVal", !11, i64 0, !8, i64 8, !8, i64 9, !11, i64 16, !8, i64 24}
!27 = !{!23, !21, i64 112}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass