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

; 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.SParser = type { ptr, %struct.Mbuffer, ptr }
%struct.Mbuffer = type { ptr, i64, i64 }
%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.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }

; 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

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

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

; Function Attrs: nounwind uwtable
define hidden i32 @luaD_protectedparser(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 %struct.SParser, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 0
  store ptr %9, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 2
  store ptr %11, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 1
  %14 = getelementptr inbounds %struct.Mbuffer, ptr %13, i32 0, i32 0
  store ptr null, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 1
  %16 = getelementptr inbounds %struct.Mbuffer, ptr %15, i32 0, i32 2
  store i64 0, ptr %16, align 8, !tbaa !15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.lua_State, ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.lua_State, ptr %21, i32 0, i32 10
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = ptrtoint ptr %20 to i64
  %25 = ptrtoint ptr %23 to i64
  %26 = sub i64 %24, %25
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lua_State, ptr %27, i32 0, i32 27
  %29 = load i64, ptr %28, align 8, !tbaa !22
  %30 = call i32 @luaD_pcall(ptr noundef %17, ptr noundef @f_parser, ptr noundef %7, i64 noundef %26, i64 noundef %29)
  store i32 %30, ptr %8, align 4, !tbaa !23
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 1
  %33 = getelementptr inbounds %struct.Mbuffer, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 1
  %36 = getelementptr inbounds %struct.Mbuffer, ptr %35, i32 0, i32 2
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = mul i64 %37, 1
  %39 = call ptr @luaM_realloc_(ptr noundef %31, ptr noundef %34, i64 noundef %38, i64 noundef 0)
  %40 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 1
  %41 = getelementptr inbounds %struct.Mbuffer, ptr %40, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !14
  %42 = getelementptr inbounds %struct.SParser, ptr %7, i32 0, i32 1
  %43 = getelementptr inbounds %struct.Mbuffer, ptr %42, i32 0, i32 2
  store i64 0, ptr %43, align 8, !tbaa !15
  %44 = load i32, ptr %8, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #3
  ret i32 %44
}

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

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, !6, i64 0}
!10 = !{!"SParser", !6, i64 0, !11, i64 8, !6, i64 32}
!11 = !{!"Mbuffer", !6, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 32}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !12, i64 24}
!16 = !{!17, !6, i64 16}
!17 = !{!"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, !18, i64 88, !18, i64 92, !19, i64 96, !19, i64 98, !7, i64 100, !7, i64 101, !18, i64 104, !18, i64 108, !6, i64 112, !20, i64 120, !20, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !12, i64 176}
!18 = !{!"int", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!"lua_TValue", !7, i64 0, !18, i64 8}
!21 = !{!17, !6, i64 64}
!22 = !{!17, !12, i64 176}
!23 = !{!18, !18, 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.SParser = type { ptr, %struct.Mbuffer, ptr }
%struct.Mbuffer = type { ptr, i64, i64 }

; 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

declare hidden ptr @luaM_realloc_(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define hidden i32 @luaD_protectedparser(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.SParser, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #3
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 32
  store ptr %2, ptr %5, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr null, ptr %6, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %4, i64 24
  store i64 0, ptr %7, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %12 = ptrtoint ptr %9 to i64
  %13 = ptrtoint ptr %11 to i64
  %14 = sub i64 %12, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 176
  %16 = load i64, ptr %15, align 8, !tbaa !21
  %17 = call i32 @luaD_pcall(ptr noundef %0, ptr noundef nonnull @f_parser, ptr noundef nonnull %4, i64 noundef %14, i64 noundef %16)
  %18 = load ptr, ptr %6, align 8, !tbaa !13
  %19 = load i64, ptr %7, align 8, !tbaa !14
  %20 = call ptr @luaM_realloc_(ptr noundef %0, ptr noundef %18, i64 noundef %19, i64 noundef 0) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #3
  ret i32 %17
}

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

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"SParser", !7, i64 0, !10, i64 8, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Mbuffer", !7, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 32}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !11, i64 24}
!15 = !{!16, !7, i64 16}
!16 = !{!"lua_State", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !17, i64 88, !17, i64 92, !18, i64 96, !18, i64 98, !8, i64 100, !8, i64 101, !17, i64 104, !17, i64 108, !7, i64 112, !19, i64 120, !19, i64 136, !7, i64 152, !7, i64 160, !7, i64 168, !11, i64 176}
!17 = !{!"int", !8, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!"lua_TValue", !8, i64 0, !17, i64 8}
!20 = !{!16, !7, i64 64}
!21 = !{!16, !11, i64 176}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass