; 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.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 }
%struct.CallInfo = type { ptr, ptr, ptr, ptr, i32, i32 }

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

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

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

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

; Function Attrs: nounwind uwtable
define hidden i32 @luaD_pcall(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i16, align 2
  %13 = alloca i64, align 8
  %14 = alloca i8, align 1
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.lua_State, ptr %17, i32 0, i32 15
  %19 = load i16, ptr %18, align 8, !tbaa !11
  store i16 %19, ptr %12, align 2, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.lua_State, ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lua_State, ptr %23, i32 0, i32 12
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = ptrtoint ptr %22 to i64
  %27 = ptrtoint ptr %25 to i64
  %28 = sub i64 %26, %27
  store i64 %28, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.lua_State, ptr %29, i32 0, i32 18
  %31 = load i8, ptr %30, align 1, !tbaa !19
  store i8 %31, ptr %14, align 1, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lua_State, ptr %32, i32 0, i32 27
  %34 = load i64, ptr %33, align 8, !tbaa !21
  store i64 %34, ptr %15, align 8, !tbaa !9
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lua_State, ptr %36, i32 0, i32 27
  store i64 %35, ptr %37, align 8, !tbaa !21
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call i32 @luaD_rawrunprotected(ptr noundef %38, ptr noundef %39, ptr noundef %40)
  store i32 %41, ptr %11, align 4, !tbaa !22
  %42 = load i32, ptr %11, align 4, !tbaa !22
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %83

44:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.lua_State, ptr %45, i32 0, i32 10
  %47 = load ptr, ptr %46, align 8, !tbaa !23
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  store ptr %49, ptr %16, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %16, align 8, !tbaa !5
  call void @luaF_close(ptr noundef %50, ptr noundef %51)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !22
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  call void @luaD_seterrorobj(ptr noundef %52, i32 noundef %53, ptr noundef %54)
  %55 = load i16, ptr %12, align 2, !tbaa !16
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lua_State, ptr %56, i32 0, i32 15
  store i16 %55, ptr %57, align 8, !tbaa !11
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.lua_State, ptr %58, i32 0, i32 12
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = load i64, ptr %13, align 8, !tbaa !9
  %62 = getelementptr inbounds i8, ptr %60, i64 %61
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.lua_State, ptr %63, i32 0, i32 7
  store ptr %62, ptr %64, align 8, !tbaa !17
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lua_State, ptr %65, i32 0, i32 7
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = getelementptr inbounds %struct.CallInfo, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !24
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lua_State, ptr %70, i32 0, i32 5
  store ptr %69, ptr %71, align 8, !tbaa !26
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.lua_State, ptr %72, i32 0, i32 7
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = getelementptr inbounds %struct.CallInfo, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !27
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.lua_State, ptr %77, i32 0, i32 8
  store ptr %76, ptr %78, align 8, !tbaa !28
  %79 = load i8, ptr %14, align 1, !tbaa !20
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.lua_State, ptr %80, i32 0, i32 18
  store i8 %79, ptr %81, align 1, !tbaa !19
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  call void @restore_stack_limit(ptr noundef %82)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %83

83:                                               ; preds = %44, %5
  %84 = load i64, ptr %15, align 8, !tbaa !9
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.lua_State, ptr %85, i32 0, i32 27
  store i64 %84, ptr %86, align 8, !tbaa !21
  %87 = load i32, ptr %11, align 4, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i32 %87
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !14, i64 96}
!12 = !{!"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, !14, i64 96, !14, i64 98, !7, i64 100, !7, i64 101, !13, i64 104, !13, i64 108, !6, i64 112, !15, i64 120, !15, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"lua_TValue", !7, i64 0, !13, i64 8}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !6, i64 80}
!19 = !{!12, !7, i64 101}
!20 = !{!7, !7, i64 0}
!21 = !{!12, !10, i64 176}
!22 = !{!13, !13, i64 0}
!23 = !{!12, !6, i64 64}
!24 = !{!25, !6, i64 0}
!25 = !{!"CallInfo", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36}
!26 = !{!12, !6, i64 24}
!27 = !{!25, !6, i64 24}
!28 = !{!12, !6, i64 48}


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

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

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

; Function Attrs: nounwind uwtable
define hidden i32 @luaD_pcall(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = load i16, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %0, i64 101
  %13 = load i8, ptr %12, align 1, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %0, i64 176
  %15 = load i64, ptr %14, align 8, !tbaa !17
  store i64 %4, ptr %14, align 8, !tbaa !17
  %16 = tail call i32 @luaD_rawrunprotected(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %31, label %17

17:                                               ; preds = %5
  %18 = ptrtoint ptr %9 to i64
  %19 = ptrtoint ptr %11 to i64
  %20 = sub i64 %18, %19
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %22, i64 %3
  tail call void @luaF_close(ptr noundef nonnull %0, ptr noundef %23) #2
  tail call void @luaD_seterrorobj(ptr noundef nonnull %0, i32 noundef %16, ptr noundef %23)
  store i16 %7, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %24, i64 %20
  store ptr %25, ptr %8, align 8, !tbaa !14
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %26, ptr %27, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %25, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %29, ptr %30, align 8, !tbaa !23
  store i8 %13, ptr %12, align 1, !tbaa !16
  tail call void @restore_stack_limit(ptr noundef nonnull %0)
  br label %31

31:                                               ; preds = %17, %5
  store i64 %15, ptr %14, align 8, !tbaa !17
  ret i32 %16
}

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

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

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


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