; 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: 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: 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) #1

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

17:                                               ; preds = %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call ptr @callrethooks(ptr noundef %18, ptr noundef %19)
  store ptr %20, ptr %4, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %17, %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lua_State, ptr %22, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds %struct.CallInfo, ptr %24, i32 -1
  store ptr %25, ptr %23, align 8, !tbaa !15
  store ptr %24, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.CallInfo, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.CallInfo, ptr %29, i32 0, i32 4
  %31 = load i32, ptr %30, align 8, !tbaa !18
  store i32 %31, ptr %6, align 4, !tbaa !19
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.CallInfo, ptr %32, i64 -1
  %34 = getelementptr inbounds %struct.CallInfo, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lua_State, ptr %36, i32 0, i32 5
  store ptr %35, ptr %37, align 8, !tbaa !21
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.CallInfo, ptr %38, i64 -1
  %40 = getelementptr inbounds %struct.CallInfo, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !22
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.lua_State, ptr %42, i32 0, i32 8
  store ptr %41, ptr %43, align 8, !tbaa !23
  %44 = load i32, ptr %6, align 4, !tbaa !19
  store i32 %44, ptr %7, align 4, !tbaa !19
  br label %45

45:                                               ; preds = %70, %21
  %46 = load i32, ptr %7, align 4, !tbaa !19
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %45
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.lua_State, ptr %50, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !24
  %53 = icmp ult ptr %49, %52
  br label %54

54:                                               ; preds = %48, %45
  %55 = phi i1 [ false, %45 ], [ %53, %48 ]
  br i1 %55, label %56, label %73

56:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.lua_TValue, ptr %57, i32 1
  store ptr %58, ptr %4, align 8, !tbaa !5
  store ptr %57, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.lua_TValue, ptr %59, i32 1
  store ptr %60, ptr %5, align 8, !tbaa !5
  store ptr %59, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.lua_TValue, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.lua_TValue, ptr %63, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %62, ptr align 8 %64, i64 8, i1 false), !tbaa.struct !25
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lua_TValue, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !27
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.lua_TValue, ptr %68, i32 0, i32 1
  store i32 %67, ptr %69, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %70

70:                                               ; preds = %56
  %71 = load i32, ptr %7, align 4, !tbaa !19
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %7, align 4, !tbaa !19
  br label %45, !llvm.loop !28

73:                                               ; preds = %54
  br label %74

74:                                               ; preds = %78, %73
  %75 = load i32, ptr %7, align 4, !tbaa !19
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %7, align 4, !tbaa !19
  %77 = icmp sgt i32 %75, 0
  br i1 %77, label %78, label %82

78:                                               ; preds = %74
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.lua_TValue, ptr %79, i32 1
  store ptr %80, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.lua_TValue, ptr %79, i32 0, i32 1
  store i32 0, ptr %81, align 8, !tbaa !27
  br label %74, !llvm.loop !30

82:                                               ; preds = %74
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.lua_State, ptr %84, i32 0, i32 4
  store ptr %83, ptr %85, align 8, !tbaa !24
  %86 = load i32, ptr %6, align 4, !tbaa !19
  %87 = sub nsw i32 %86, -1
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 %87
}

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

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


; 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
define hidden range(i32 -2147483647, -2147483648) i32 @luaD_poscall(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 100
  %4 = load i8, ptr %3, align 4, !tbaa !5
  %5 = and i8 %4, 2
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %8, label %6

6:                                                ; preds = %2
  %7 = tail call ptr @callrethooks(ptr noundef nonnull %0, ptr noundef %1)
  br label %8

8:                                                ; preds = %6, %2
  %.0 = phi ptr [ %7, %6 ], [ %1, %2 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %10, i64 -40
  store ptr %11, ptr %9, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %10, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %10, i64 32
  %15 = load i32, ptr %14, align 8, !tbaa !17
  %16 = load ptr, ptr %11, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %16, ptr %17, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %10, i64 -16
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %19, ptr %20, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %.not2930 = icmp eq i32 %15, 0
  br i1 %.not2930, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %24
  %indvar = phi i32 [ %indvar.next, %24 ], [ 0, %8 ]
  %.133 = phi ptr [ %25, %24 ], [ %.0, %8 ]
  %.02532 = phi ptr [ %26, %24 ], [ %13, %8 ]
  %.02731 = phi i32 [ %31, %24 ], [ %15, %8 ]
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = icmp ult ptr %.133, %22
  br i1 %23, label %24, label %.critedge

24:                                               ; preds = %.lr.ph
  %25 = getelementptr inbounds i8, ptr %.133, i64 16
  %26 = getelementptr inbounds i8, ptr %.02532, i64 16
  %27 = load i64, ptr %.133, align 8, !tbaa !23
  store i64 %27, ptr %.02532, align 8, !tbaa !23
  %28 = getelementptr inbounds i8, ptr %.133, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !24
  %30 = getelementptr inbounds i8, ptr %.02532, i64 8
  store i32 %29, ptr %30, align 8, !tbaa !24
  %31 = add nsw i32 %.02731, -1
  %.not29 = icmp eq i32 %31, 0
  %indvar.next = add i32 %indvar, 1
  br i1 %.not29, label %._crit_edge, label %.lr.ph, !llvm.loop !25

.critedge:                                        ; preds = %.lr.ph
  %32 = icmp sgt i32 %.02731, 0
  br i1 %32, label %.lr.ph40.preheader, label %._crit_edge

.lr.ph40.preheader:                               ; preds = %.critedge
  %xtraiter = and i32 %.02731, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph40.prol.loopexit, label %.lr.ph40.prol

.lr.ph40.prol:                                    ; preds = %.lr.ph40.preheader, %.lr.ph40.prol
  %.12639.prol = phi ptr [ %34, %.lr.ph40.prol ], [ %.02532, %.lr.ph40.preheader ]
  %.12838.prol = phi i32 [ %33, %.lr.ph40.prol ], [ %.02731, %.lr.ph40.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph40.prol ], [ 0, %.lr.ph40.preheader ]
  %33 = add nsw i32 %.12838.prol, -1
  %34 = getelementptr inbounds i8, ptr %.12639.prol, i64 16
  %35 = getelementptr inbounds i8, ptr %.12639.prol, i64 8
  store i32 0, ptr %35, align 8, !tbaa !24
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph40.prol.loopexit, label %.lr.ph40.prol, !llvm.loop !27

.lr.ph40.prol.loopexit:                           ; preds = %.lr.ph40.prol, %.lr.ph40.preheader
  %.12639.unr = phi ptr [ %.02532, %.lr.ph40.preheader ], [ %34, %.lr.ph40.prol ]
  %.12838.unr = phi i32 [ %.02731, %.lr.ph40.preheader ], [ %33, %.lr.ph40.prol ]
  %.lcssa.unr = phi ptr [ poison, %.lr.ph40.preheader ], [ %34, %.lr.ph40.prol ]
  %36 = sub i32 %indvar, %15
  %37 = icmp ugt i32 %36, -8
  br i1 %37, label %._crit_edge, label %.lr.ph40

.lr.ph40:                                         ; preds = %.lr.ph40.prol.loopexit, %.lr.ph40
  %.12639 = phi ptr [ %46, %.lr.ph40 ], [ %.12639.unr, %.lr.ph40.prol.loopexit ]
  %.12838 = phi i32 [ %45, %.lr.ph40 ], [ %.12838.unr, %.lr.ph40.prol.loopexit ]
  %38 = getelementptr inbounds i8, ptr %.12639, i64 8
  store i32 0, ptr %38, align 8, !tbaa !24
  %39 = getelementptr inbounds i8, ptr %.12639, i64 24
  store i32 0, ptr %39, align 8, !tbaa !24
  %40 = getelementptr inbounds i8, ptr %.12639, i64 40
  store i32 0, ptr %40, align 8, !tbaa !24
  %41 = getelementptr inbounds i8, ptr %.12639, i64 56
  store i32 0, ptr %41, align 8, !tbaa !24
  %42 = getelementptr inbounds i8, ptr %.12639, i64 72
  store i32 0, ptr %42, align 8, !tbaa !24
  %43 = getelementptr inbounds i8, ptr %.12639, i64 88
  store i32 0, ptr %43, align 8, !tbaa !24
  %44 = getelementptr inbounds i8, ptr %.12639, i64 104
  store i32 0, ptr %44, align 8, !tbaa !24
  %45 = add nsw i32 %.12838, -8
  %46 = getelementptr inbounds i8, ptr %.12639, i64 128
  %47 = getelementptr inbounds i8, ptr %.12639, i64 120
  store i32 0, ptr %47, align 8, !tbaa !24
  %48 = add i32 %.12838, -9
  %49 = icmp ult i32 %48, -2
  br i1 %49, label %.lr.ph40, label %._crit_edge, !llvm.loop !29

._crit_edge:                                      ; preds = %24, %.lr.ph40.prol.loopexit, %.lr.ph40, %8, %.critedge
  %.126.lcssa = phi ptr [ %.02532, %.critedge ], [ %13, %8 ], [ %.lcssa.unr, %.lr.ph40.prol.loopexit ], [ %46, %.lr.ph40 ], [ %26, %24 ]
  store ptr %.126.lcssa, ptr %21, align 8, !tbaa !22
  %50 = add nsw i32 %15, 1
  ret i32 %50
}

; Function Attrs: nounwind uwtable
declare hidden ptr @callrethooks(ptr noundef, 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" }

!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, !8, i64 100}
!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 = !{!16, !7, i64 8}
!16 = !{!"CallInfo", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!17 = !{!16, !10, i64 32}
!18 = !{!16, !7, i64 0}
!19 = !{!6, !7, i64 24}
!20 = !{!16, !7, i64 24}
!21 = !{!6, !7, i64 48}
!22 = !{!6, !7, i64 16}
!23 = !{!8, !8, i64 0}
!24 = !{!12, !10, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.unroll.disable"}
!29 = distinct !{!29, !26}


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