; 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_Debug = type { i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, [60 x i8], 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.lua_TValue = type { %union.Value, i32 }
%union.Value = type { ptr }
%struct.CallInfo = type { ptr, ptr, ptr, ptr, i32, i32 }

; 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 void @luaD_growstack(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define hidden void @luaD_callhook(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.lua_Debug, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lua_State, ptr %11, i32 0, i32 21
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %109

16:                                               ; preds = %3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.lua_State, ptr %17, i32 0, i32 18
  %19 = load i8, ptr %18, align 1, !tbaa !16
  %20 = zext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %109

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lua_State, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.lua_State, ptr %26, i32 0, i32 10
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = ptrtoint ptr %25 to i64
  %30 = ptrtoint ptr %28 to i64
  %31 = sub i64 %29, %30
  store i64 %31, ptr %8, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lua_State, ptr %32, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = getelementptr inbounds %struct.CallInfo, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.lua_State, ptr %37, i32 0, i32 10
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = ptrtoint ptr %36 to i64
  %41 = ptrtoint ptr %39 to i64
  %42 = sub i64 %40, %41
  store i64 %42, ptr %9, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 120, ptr %10) #2
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = getelementptr inbounds %struct.lua_Debug, ptr %10, i32 0, i32 0
  store i32 %43, ptr %44, align 8, !tbaa !23
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = getelementptr inbounds %struct.lua_Debug, ptr %10, i32 0, i32 5
  store i32 %45, ptr %46, align 8, !tbaa !25
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 4
  br i1 %48, label %49, label %51

49:                                               ; preds = %22
  %50 = getelementptr inbounds %struct.lua_Debug, ptr %10, i32 0, i32 10
  store i32 0, ptr %50, align 4, !tbaa !26
  br label %64

51:                                               ; preds = %22
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.lua_State, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !20
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.lua_State, ptr %55, i32 0, i32 12
  %57 = load ptr, ptr %56, align 8, !tbaa !27
  %58 = ptrtoint ptr %54 to i64
  %59 = ptrtoint ptr %57 to i64
  %60 = sub i64 %58, %59
  %61 = sdiv exact i64 %60, 40
  %62 = trunc i64 %61 to i32
  %63 = getelementptr inbounds %struct.lua_Debug, ptr %10, i32 0, i32 10
  store i32 %62, ptr %63, align 4, !tbaa !26
  br label %64

64:                                               ; preds = %51, %49
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lua_State, ptr %65, i32 0, i32 9
  %67 = load ptr, ptr %66, align 8, !tbaa !28
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.lua_State, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = ptrtoint ptr %67 to i64
  %72 = ptrtoint ptr %70 to i64
  %73 = sub i64 %71, %72
  %74 = icmp sle i64 %73, 320
  br i1 %74, label %75, label %77

75:                                               ; preds = %64
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  call void @luaD_growstack(ptr noundef %76, i32 noundef 20)
  br label %78

77:                                               ; preds = %64
  br label %78

78:                                               ; preds = %77, %75
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.lua_State, ptr %79, i32 0, i32 4
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = getelementptr inbounds %struct.lua_TValue, ptr %81, i64 20
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.lua_State, ptr %83, i32 0, i32 7
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = getelementptr inbounds %struct.CallInfo, ptr %85, i32 0, i32 2
  store ptr %82, ptr %86, align 8, !tbaa !21
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.lua_State, ptr %87, i32 0, i32 18
  store i8 0, ptr %88, align 1, !tbaa !16
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  call void %89(ptr noundef %90, ptr noundef %10)
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.lua_State, ptr %91, i32 0, i32 18
  store i8 1, ptr %92, align 1, !tbaa !16
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.lua_State, ptr %93, i32 0, i32 10
  %95 = load ptr, ptr %94, align 8, !tbaa !18
  %96 = load i64, ptr %9, align 8, !tbaa !19
  %97 = getelementptr inbounds i8, ptr %95, i64 %96
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.lua_State, ptr %98, i32 0, i32 7
  %100 = load ptr, ptr %99, align 8, !tbaa !20
  %101 = getelementptr inbounds %struct.CallInfo, ptr %100, i32 0, i32 2
  store ptr %97, ptr %101, align 8, !tbaa !21
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.lua_State, ptr %102, i32 0, i32 10
  %104 = load ptr, ptr %103, align 8, !tbaa !18
  %105 = load i64, ptr %8, align 8, !tbaa !19
  %106 = getelementptr inbounds i8, ptr %104, i64 %105
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.lua_State, ptr %107, i32 0, i32 4
  store ptr %106, ptr %108, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 120, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %109

109:                                              ; preds = %78, %16, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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 = { 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, !6, i64 112}
!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, !10, i64 88, !10, i64 92, !13, i64 96, !13, i64 98, !7, i64 100, !7, i64 101, !10, i64 104, !10, i64 108, !6, i64 112, !14, i64 120, !14, i64 136, !6, i64 152, !6, i64 160, !6, i64 168, !15, i64 176}
!13 = !{!"short", !7, i64 0}
!14 = !{!"lua_TValue", !7, i64 0, !10, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !7, i64 101}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !6, i64 64}
!19 = !{!15, !15, i64 0}
!20 = !{!12, !6, i64 40}
!21 = !{!22, !6, i64 16}
!22 = !{!"CallInfo", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!23 = !{!24, !10, i64 0}
!24 = !{!"lua_Debug", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !7, i64 56, !10, i64 116}
!25 = !{!24, !10, i64 40}
!26 = !{!24, !10, i64 116}
!27 = !{!12, !6, i64 80}
!28 = !{!12, !6, i64 56}


; 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_Debug = type { i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, [60 x i8], i32 }

; 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

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

; Function Attrs: nounwind uwtable
define hidden void @luaD_callhook(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.lua_Debug, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %52, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 101
  %9 = load i8, ptr %8, align 1, !tbaa !14
  %.not26 = icmp eq i8 %9, 0
  br i1 %.not26, label %52, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = ptrtoint ptr %12 to i64
  %16 = ptrtoint ptr %14 to i64
  %17 = sub i64 %15, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = ptrtoint ptr %21 to i64
  %23 = sub i64 %22, %16
  call void @llvm.lifetime.start.p0(i64 120, ptr nonnull %4) #2
  store i32 %1, ptr %4, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %4, i64 40
  store i32 %2, ptr %24, align 8, !tbaa !22
  %25 = icmp eq i32 %1, 4
  br i1 %25, label %34, label %26

26:                                               ; preds = %10
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  %28 = load ptr, ptr %27, align 8, !tbaa !23
  %29 = ptrtoint ptr %19 to i64
  %30 = ptrtoint ptr %28 to i64
  %31 = sub i64 %29, %30
  %32 = sdiv exact i64 %31, 40
  %33 = trunc i64 %32 to i32
  br label %34

34:                                               ; preds = %10, %26
  %.sink = phi i32 [ %33, %26 ], [ 0, %10 ]
  %35 = getelementptr inbounds i8, ptr %4, i64 116
  store i32 %.sink, ptr %35, align 4
  %36 = getelementptr inbounds i8, ptr %0, i64 56
  %37 = load ptr, ptr %36, align 8, !tbaa !24
  %38 = ptrtoint ptr %37 to i64
  %39 = sub i64 %38, %15
  %40 = icmp slt i64 %39, 321
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  tail call void @luaD_growstack(ptr noundef nonnull %0, i32 noundef 20)
  %.pre = load ptr, ptr %11, align 8, !tbaa !15
  %.pre27 = load ptr, ptr %18, align 8, !tbaa !17
  br label %42

42:                                               ; preds = %34, %41
  %43 = phi ptr [ %19, %34 ], [ %.pre27, %41 ]
  %44 = phi ptr [ %12, %34 ], [ %.pre, %41 ]
  %45 = getelementptr inbounds i8, ptr %44, i64 320
  %46 = getelementptr inbounds i8, ptr %43, i64 16
  store ptr %45, ptr %46, align 8, !tbaa !18
  store i8 0, ptr %8, align 1, !tbaa !14
  call void %6(ptr noundef nonnull %0, ptr noundef nonnull %4) #2
  store i8 1, ptr %8, align 1, !tbaa !14
  %47 = load ptr, ptr %13, align 8, !tbaa !16
  %48 = getelementptr inbounds i8, ptr %47, i64 %23
  %49 = load ptr, ptr %18, align 8, !tbaa !17
  %50 = getelementptr inbounds i8, ptr %49, i64 16
  store ptr %48, ptr %50, align 8, !tbaa !18
  %51 = getelementptr inbounds i8, ptr %47, i64 %17
  store ptr %51, ptr %11, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %4) #2
  br label %52

52:                                               ; preds = %42, %7, %3
  ret void
}

attributes #0 = { mustprogress 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 = { 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 112}
!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, !8, i64 101}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !7, i64 64}
!17 = !{!6, !7, i64 40}
!18 = !{!19, !7, i64 16}
!19 = !{!"CallInfo", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!20 = !{!21, !10, i64 0}
!21 = !{!"lua_Debug", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !8, i64 56, !10, i64 116}
!22 = !{!21, !10, i64 40}
!23 = !{!6, !7, i64 80}
!24 = !{!6, !7, i64 56}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass